I need to test an Authentication Plug that needs to consume a function of a context module, Accounts.get_user/1
.
The best way to mock this would be something like:
defmodule Auth do
use ExUnit.Case, async: true
use Plug.Test
test "auth works" do
defmodule DummyAccounts do
def get_user(_id), do: %User{}
end
conn = conn(:get, "/hello")
conn = MyRouter.call(conn, DummyAccounts)
# asserts here
end
end