Right now my application tree starts a supervisor, as well as the rest of the phoenix application. The supervisor’s job is to initialize Cachex and run a Task, which will fetch an Auth token from an external service. We want to start the phoenix components of the application after the cache has been warmed up.
However, since running tests will start up the application’s supervision tree, so when we run our unit tests we are relying on an external service to startup every time. Is there a way to mock out the functionality in the task to not fetch token from external service?
The easiest solution is to add a config to control whether to fetch the token, then set that config to true/false depending on mix env. You can make the config value be {module name, function name} and call the function, this will achieve your goal of mocking out the functionality.