Hi @LostKobrakai,
Thank you for recommending above way to handle this issue.
I was able to inject the subdomain by using this in my test Phoenix.ConnTest.build_conn(:get, "http://subdomain.domain.com", nil)
. But further than that I could not manage to pass the subdomain through tags.
I am having following code in my controller test -
defmodule CompanyArchiveWeb.ManagementControllerTest do
use CompanyArchiveWeb.ConnCase, async: true, subdomain: "app"
test "GET management_path(conn, :index)", %{conn: conn} do
conn = get(conn, management_path(conn, :index))
assert html_response(conn, 200) =~ "Management"
end
end
In my test/support/conn_case.ex I am having this in my setup block -
setup tags do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(CompanyArchive.Repo)
unless tags[:async] do
Ecto.Adapters.SQL.Sandbox.mode(CompanyArchive.Repo, {:shared, self()})
end
IO.inspect tags # Debug to see tags
conn = case tags[:subdomain] do
nil -> Phoenix.ConnTest.build_conn(:get, "http://test-company-archive.local/", nil)
somedomain -> Phoenix.ConnTest.build_conn(:get, "http://#{somedomain}.test-company-archive.local/", nil)
end
{:ok, conn: conn}
end
When I inspect tags inside the above setup block I am getting this -
%{
async: true,
case: CompanyArchiveWeb.ManagementControllerTest,
describe: nil,
describe_line: nil,
file: ...,
line: 4,
module: CompanyArchiveWeb.ManagementControllerTest,
registered: %{},
test: :"test GET management_path(conn, :index)",
type: :test
}
I am curious what is the right way of passing parameters to the setup block above?