-
Notifications
You must be signed in to change notification settings - Fork 357
Description
Hello, fellow developers.
I was wondering if you can help me with a specific use-case of Tesla.Mock.
(Not sure if this is the best place to post this question, if not, I can repost in the proper place, but here is:)
Context:
I want to create a record in an external API, for the same url, with the same query params, for this, I create a mock like this:
%{
method: :get,
url: "some_url",
query: [
{"Foo", "Bar"},
]
} ->
%Tesla.Env{
status: 200,
body:
"some_response_1.json"
|> File.read!()
|> Jason.decode!()
}This "some_response_1.json", returns something like: Oh, you can create your record because there is nothing in here.
Then I do another request to create something, but now IN THE FUTURE, I want to do the exact same request as presented above, but this time reading another json response, A.K.A. "some_response_2.json":
%{
method: :get,
url: "some_url",
query: [
{"Foo", "Bar"},
]
} ->
%Tesla.Env{
status: 200,
body:
"some_response_2.json" # <-------- OTHER RESPONSE
|> File.read!()
|> Jason.decode!()
}How can I do this? if theoretically, I am pattern matching on the same Tesla props? But in different moments?
Thank you for your attention.
Best regards