Hey guys I’m having a hard time understanding why I’m facing this issue:
I’m assigning a logged in user like this
conn =
conn
|> Map.replace!(:secret_key_base, SerotanaExWeb.Endpoint.config(:secret_key_base))
|> init_test_session(%{current_user_id: user.id})
|> assign(:current_user, user)
|> bypass_through(SerotanaExWeb.Router, :browser)
The test then tries to check all the live routes to see make sure that a logged in user can access them:
test "Access client pages", %{conn: conn, user: user, post: post} do
IEx.pry()
assert html_response(get(conn, "/c/posts"), 200)
assert html_response(get(test_conn, "/c/posts/new"), 200)
assert html_response(get(test_conn, "/c/proposals"), 200)
assert html_response(get(test_conn, "/c/clients/#{user.client.id}"), 200)
assert html_response(get(test_conn, "/c/clients/#{user.client.id}/show/edit"), 200)
assert html_response(get(test_conn, "/c/posts/#{post.id}/edit"), 200)
assert html_response(get(test_conn, "/c/posts/#{post.id}"), 200)
assert html_response(get(test_conn, "/c/posts/#{post.id}/show/edit"), 200)
When I run a pry in my tests the conn has the current_user
I have a made plug that checks to see if client has access:
def check_page_permissions(conn, _opts) do
IEx.pry()
%{request_path: path} = conn
cond do
String.contains?(path, "/c/") -> check_client_access(conn)
String.contains?(path, "/t/") -> check_therapist_access(conn)
String.contains?(path, "/a/") -> check_admin_access(conn)
true -> conn
end
end
Now when I run the pry there, the current_user is nil
I’m not understanding why or how.
Anyways, do you think you guys can help me out?
I think I’m misinterpreting a concept for testing, conn, and plugs but I have no idea.