I am working on testing a complex function that makes multiple third party API calls. We use
[Bypass](https://hexdocs.pm/bypass/Bypass.html) to mock our API calls and has served us well for testing functions where it’s easy to mock the url being called.
However, the function I’m testing has a few API calls that are nested. I am easily able to anticipate the url being called except for one where we pass a newly created UUID that is used in the API call.
def complex_function(args) do # logic and api calls ThirdPartyApi.create(arg1, UUID.uuid4(), arg3) # additional logic and api calls end
Makes a call similar to
Testing the function
ThirdPartyApi.create/3 is easy to do on its own but in the above function it is not since the
uuid is not known.
I’ve read about accessing the env in the function and creating a stub function for
ThirdPartyApi.create/3 if the env is
test. It’s something I know about and have seen but haven’t read too much into just yet.
I wanted to see if there’s a way to handle the above scenario with
Bypass with how I’m using it now or if I’ll need to do something like passing the
env to test.