wearblc
Testing with Bypass that makes a call to a dynamic 3rd party url that can't be easily stubbed
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 api/v2/{arg1}/{uuid}
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.
Most Liked
Hermanverschooten
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









