Skip to content

Commit

Permalink
Added test for new plug.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Apr 25, 2024
1 parent 8686973 commit 8c5a03d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/screenplay_web/ensure_pa_message_admin_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ScreenplayWeb.EnsurePaMessageAdminTest do
use ScreenplayWeb.ConnCase

describe "init/1" do
test "passes options through unchanged" do
assert ScreenplayWeb.EnsurePaMessageAdmin.init([]) == []
end
end

describe "call/2" do
@tag :authenticated_pa_message_admin
test "does nothing when user is a PA message admin", %{conn: conn} do
assert conn == ScreenplayWeb.EnsurePaMessageAdmin.call(conn, [])
end

@tag :authenticated
test "redirects to Dashboard when user is not a PA message admin", %{conn: conn} do
conn = ScreenplayWeb.EnsurePaMessageAdmin.call(conn, [])

assert redirected_to(conn) =~ "/dashboard"
end
end
end
14 changes: 14 additions & 0 deletions test/support/conn_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ defmodule ScreenplayWeb.ConnCase do

{conn, user}

tags[:authenticated_pa_message_admin] ->
user = "test_user"

conn =
Phoenix.ConnTest.build_conn()
|> Plug.Test.init_test_session(%{})
|> Guardian.Plug.sign_in(ScreenplayWeb.AuthManager, user, %{
"roles" => ["pa-message-admin"]
})
|> Plug.Conn.put_session(:username, user)
|> assign(:roles, [:pa_message_admin])

{conn, user}

true ->
{Phoenix.ConnTest.build_conn(), nil}
end
Expand Down

0 comments on commit 8c5a03d

Please sign in to comment.