Hi everyone!
I am trying to build some tests making use of one http connection and one phoenix channel. I have used previously both of them separately making use of Phoenix.ConnTest
and Phoenix.ChannelTest
respectively, but now I need to use both of them someway.
I decided to create a new support test file at *./test/support/channel_and_conn_case.ex * with this code:
defmodule Project.ChannelAndConnCase do
use ExUnit.CaseTemplate
using do
quote do
defmodule Conn do
require Phoenix.ConnTest
@endpoint Project.Endpoint
defdelegate get(conn, route, params), to: Phoenix.ConnTest
...
end
defmodule Channel do
require Phoenix.ChannelTest
@endpoint Project.Endpoint
defdelegate connect(socket_module, params), to: Phoenix.ChannelTest
defdelegate subscribe_and_join(socket, channel_module, topic), to: Phoenix.ChannelTest
...
end
...
end
end
Using this I am able to call functions from both files (Phoenix.ConnTestand
Phoenix.ChannelTest`), but I feel like this is not the way to go. I would like to know if there is a more appropriate approach to get this done.
Thank you in advance!