I have a couple Elixir modules that rely in part on 3rd party APIs. I’m wondering how I can best test them? Since the 3rd party service may be down or we may experience time-outs or we may have mis-configured the connection entirely, it is important that our module can recover and log any problems.
One gotcha is that Elixir reads ENV variables at compile-time. If I wanted to test that the proper URL had been entered, I would have to restructure my module and functions to allow for me to inject an override. Is this recommended?
Another not-so-hypothetical case is that our account with the 3rd party may have lapsed – let’s say our contract expired without anyone noticing. In that case, our API token would stop working and their API would start returning an error page. Again, I could refactor our modules so that I could inject a fake response, but it seems like that approach is not idiomatic to Elixir.
Any suggestions? Thanks!