-
Notifications
You must be signed in to change notification settings - Fork 353
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
Implement assert_stripe_requested/3
#487
Implement assert_stripe_requested/3
#487
Conversation
25d72eb
to
45d85d3
Compare
45d85d3
to
07abeac
Compare
In the tests, a message is send with the request to the process. We can assert on this message and test whether the expected request was made.
07abeac
to
178f555
Compare
assert expected_url == url | ||
|
||
assert_stripe_request_body(expected_body, body) | ||
assert_stripe_request_headers(expected_headers, headers) |
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.
🎉
expected_body = Keyword.get(extra, :body) | ||
expected_headers = Keyword.get(extra, :headers) | ||
|
||
assert_received({method, url, headers, 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.
Did you mean for these to be prefixed with expected_
?
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.
No, they will pattern match to the received message. So url
will contain the url the http client used. Right?
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.
oh i figured these had to be variables in this function's scope. Not seeing 'method' in this scope for example.
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.
They could've been pinned like assert_received({^expected_method, ^expected_url, headers, body, _})
as well.
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.
Ah it is a macro that is expecting to pattern match the received message into those variables, correct? Now I understand.
The
assert_stripe_requested/3
function was not yet implemented.To better test #480 (comment)
I implemented this function to test whether the request was actually called. This is done by sending a message to the current process and asserting whether it was received and has the right shape.
The a1147ee commit was the only one where I found a bug in the current code. All other fixes only concern the tests where the wrong thing was asserted because of a typo or another mistake.
In the case where two requests are made in a test, it is necessary to assert both requests. Otherwise the
assert_stripe_requested/3
function might check the wrong request.In a few cases the body, query_params or the request headers were also passed allong to
assert_stripe_requested/3
, these params are also asserted for being correct.