-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update stripe-mock to v0.30.0 #414
Update stripe-mock to v0.30.0 #414
Conversation
Sends request params in the query string, to account for stripe/stripe-mock@09826da introducing parameter validation (and removed request body validation) for `GET` requests, since the body of a GET request has no semantic meaning. This broke endpoints like `/invoices/upcoming?customer=cus_1234`, because we were sending the `customer` param in the request body.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcrumm You did a really nice job on this PR. Lmk about a few questions below and then we can work to get this merged asap!
@@ -17,11 +17,10 @@ defmodule Stripe.CustomerTest do | |||
assert_stripe_requested(:post, "/v1/customers/cus_123") | |||
end | |||
|
|||
test "is deleteable" do | |||
test "is deleteble" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r/deleteble/deletable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! I dropped the wrong letter 😄
@@ -42,6 +44,7 @@ defmodule Stripe.SubscriptionTest do | |||
assert_stripe_requested(:delete, "/v1/subscriptions/#{subscription.id}") | |||
end | |||
|
|||
@tag :skip |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the delete/2
&& delete/3
can be simplified to delete/2
that simply takes the Stripe.id
and optional Stripe.options
. Basically at_period_end
is not a potential parameter to pass anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's absolutely true as of 2018-08-23
. I was trying not to muddy the concept of the stripe-mock update with the Stripe API version update.
I'd be happy to make that change here, or I can leave it for the API update PR. Let me know what makes the most sense to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcrumm Oh I see what you did. So follow up PR is probably a good idea 👍
@@ -10,7 +10,7 @@ otp_release: | |||
sudo: false | |||
env: | |||
global: | |||
- STRIPE_MOCK_VERSION=0.16.1 | |||
- STRIPE_MOCK_VERSION=0.30.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 🎉
@@ -317,7 +317,6 @@ defmodule Stripe.Account do | |||
{:ok, t} | {:error, Stripe.Error.t()} | |||
def reject(id, reason, opts \\ []) do | |||
params = %{ | |||
account: id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@doc """ | ||
""" | ||
@spec request_file_upload(body, method, String.t(), headers, list) :: | ||
{:ok, map} | {:error, Stripe.Error.t()} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we leave this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a duplication on the second function signature. The first signature for request_file_upload
already defines the @spec
, and I think I just got tired of looking past the dialyzer warning 😄
|> Stripe.URI.encode_query() | ||
|> prepend_url("#{base_url}#{endpoint}") | ||
|
||
perform_request(req_url, :get, "", headers, opts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the main difference between the two requests is :get
will pass ""
for the body and the other won't? I'm wondering if both of these request/5
methods could be simplified into one...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise, this change looks great!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct, and any additional parameters for a :get
request go into the query string. For instance, /v1/invoices/upcoming?customer=cus_1234
previously sent customer=cus_1234
in the GET
body, which stopped validating on the latest stripe-mock
.
My methodology here was basically "make the least number of changes required", but I agree that it seems harder to follow than it should be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gotcha. So we basically have expand
request parameters and other parameters. We can send them in the url or body. Currently we send the expand
able items in the url and the rest in the body. With a GET
request, we send both in the url.
I'm thinking we should brainstorm something to reduce the duplication and have 1 request/5
method but that can be a future refactor as you stated.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that was my thought as well. Refactoring the URL building functions should make it simple enough to reduce request/5
to a single function body.
@@ -30,9 +30,8 @@ defmodule Stripe.SubscriptionItemTest do | |||
describe "delete/2" do | |||
test "deletes a subscription" do | |||
{:ok, subscription_item} = Stripe.SubscriptionItem.retrieve("sub_123") | |||
assert {:ok, %{deleted: deleted, id: _id}} = Stripe.SubscriptionItem.delete("sub_123") | |||
assert {:ok, %Stripe.SubscriptionItem{}} = Stripe.SubscriptionItem.delete("sub_123") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should clarify that this changed because stripe-mock now returns the "object" in the response (not sure of exact version), thus we convert to a struct with id
populated and rest of keys nil, whereas before, we couldn't determine the struct, so we just processed the bare map.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meaning stripe-mock is returning %{deleted: deleted, id: _id, object: object}
but we convert it to a proper struct.
@@ -135,6 +135,20 @@ defmodule Stripe.API do | |||
""" | |||
@spec request(body, method, String.t(), headers, list) :: | |||
{:ok, map} | {:error, Stripe.Error.t()} | |||
def request(body, :get, endpoint, headers, opts) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lastly, do you think this is properly tested? e.g. a GET request with a body and expand params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do. On its own, the :get
request change fixed the upcoming invoice test (you can verify the failure by testing the current master
against a v0.30.x
version of stripe-mock), and I've tested this branch against the live (well, test) Stripe API as well.
Our Stripe logs verify parameters coming in now as Request query parameters
instead of Request POST body
for GET requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcrumm Really really great work! Super easy to follow this PR.
Looks like we have 2 follow ups before we cut a proper release (2.3):
- One
delete/2
method - One
request/5
method.
Otherwise, lmk if you are done working on this and we can hit the merge button!
Thanks for the feedback! Yep, I think this is good to merge, and then we can tackle the actual API update. |
Relates to #413
Changes:
stripe-mock v0.30.0
in tests (2f8396d)Stripe.Account.create/2
sendingaccount
in the POST body (it's in the path) (c50b31b).delete/2
calls (411c124)at_period_end
on subscription delete), or erroneously failing parameter validation (external_accounts with?object=
) (545ece2)