I’m writing a lib and I decided to use mox to mock some API calls… So I configured a prod.exs and a test.exs with this:
# prod.exs
use Mix.Config
config :junex, auth_client: Junex.Auth.HTTP
# test.exs
use Mix.Config
config :junex, auth_client: Junex.AuthMock
and to configure Tesla, on my config.exs I have:
use Mix.Config
config :junex, :adapter, Tesla.Adapter.Hackney
One of my modules is defined as:
defmodule Junex.Auth do
@moduledoc """
This Module defines the client's function behaviour
and exposes the get_access_token function
"""
def get_access_token(client_id, client_secret, is_sandbox) do
client().get_access_token(client_id, client_secret, is_sandbox)
end
defp client do
Application.get_env(:junex, :auth_client)
end
end
However, even if I try to run MIX_ENV=prod iex -S mix
or with MIX_ENV=test
the client
function return nil
, causing this test error:
1) test get_access_token/3 returns 401 when credentials are invalid (Junex.AuthTest)
test/auth_test.exs:11
** (UndefinedFunctionError) function nil.get_access_token/3 is undefined
code: Auth.get_access_token(client_id, client_secret, is_sandbox)
stacktrace:
nil.get_access_token("teste1", "teste2", true)
test/auth_test.exs:23: (test)
So I tried to run Application.get_all_env :junex
and then I realised that only the config.exs
config is being loaded… What I’m doing wrong?
This is my lib repo: https://github.com/boostingtech/junex/tree/test/auth
I also did a minimal new repo to reproduce: https://github.com/Mdsp9070/test_config
Oh, I already tried to run mix clean
, mix compile --force
and rebuild the project from 0.