Filter responses from Response.all_4xx and Response.all_5xx lists
Closed this issue · 2 comments
bernardolins commented
Sometimes you want to ensure that your client can handle all kinds of 4xx or 5xx responses, but you will handle some of these responses in a special way.
For example, suppose you are requesting an external service for a user by email. You want to return a specific message when the user is not found (when the server replies 404) but for any other 4xx status code, you just want return a default error message. This filter will help to test such cases:
test_with_server "return {:error, :user_not_found} when the external service replies 404" do
route("/users", Response.not_found)
assert {:error, :not_found} == User.find_by_email("john@example.com")
end
test_with_server "return {:error, :invalid_response} when the external service replies any other 4xx" do
responses = Response.all_4xx(except: [404])
route("/users", responses)
for _ <- responses do
assert {:error, :invalid_response} == User.find_by_email("john@example.com")
end
end
fcapovilla commented
I'll try to work on this issue.
bernardolins commented
#45 closes this issue.