I have reqs to test that relys on previous reponses of other http requests, what would be a good way to develop a test for each request and use the response to test another request without nesting all requests in the same test? I want to test it individually to avoid not seeing errors. Example: I have this function that returns a body
def make_qrcode() do
headers = [
{"User-Agent", "elixir_test"},
{"accept", "application/json"},
{"access_token", "$aact_YTU5YTE0M2M2N2I4MTliNzk0YTI5N2U5MzdjNWZmNDQ6OjAwMDAwMDAwMDAwMDAwNzE5NTE6OiRhYWNoXzdiZDBkZjZmLWQxZWUtNDI0NC1hYjdlLTFiNzU2NDUxZGQ4Zg=="},
{"content-type", "application/json"}
]
body = %{
"value" => 50,
"addressKey" => "c3c1b77a-ce3f-4115-92e5-6de064242818",
"format" => "PAYLOAD"
}
response =
Req.post!("https://sandbox.asaas.com/api/v3/pix/qrCodes/static",
headers: headers,
json: body
)
case response.status do
200 ->
{:ok, response.body}
_ -> {:error, response}
end
end
and the test
test "request payload" do
assert {:ok, response} = make_qrcode();
IO.inspect(response["payload"])
end
So what I want to do is besides test “request payload”, save the response to pass to this function
def check_payload(payload) do
token = "$aact_YTU5YTE0M2M2N2I4MTliNzk0YTI5N2U5MzdjNWZmNDQ6OjAwMDAwMDAwMDAwMDAwNzE5NTE6OiRhYWNoXzdiZDBkZjZmLWQxZWUtNDI0NC1hYjdlLTFiNzU2NDUxZGQ4Zg=="
req = Req.Request.new(
method: :post,
url: "https://sandbox.asaas.com/api/v3/pix/qrCodes/decode",
headers: [{"accept", "application/json"},{"content-type", "application/json"}, {"access_token", token}],
body: Jason.encode!(%{payload: payload})
)
{_req, resp} = Req.Request.run_request(req)
decoded_response = Jason.decode!(resp.body)
decoded_response
end
but in a different test What I thought was just saving it to a json file into the test directoy and get the data from there, but I want to know if there is some better way to do this since I have no exp in elixir or testing on it