diff --git a/lib/shift73k_web/live/admin_dashboard_live.ex b/lib/shift73k_web/live/admin_dashboard_live.ex deleted file mode 100644 index 6ba8da39..00000000 --- a/lib/shift73k_web/live/admin_dashboard_live.ex +++ /dev/null @@ -1,18 +0,0 @@ -defmodule Shift73kWeb.AdminDashboardLive do - use Shift73kWeb, :live_view - - @impl true - def mount(_params, session, socket) do - socket = assign_defaults(socket, session) - {:ok, socket} - end - - @impl true - def render(assigns) do - ~L""" -
-

Welcome to the admin dashboard!

-
- """ - end -end diff --git a/lib/shift73k_web/live/user_dashboard_live.ex b/lib/shift73k_web/live/user_dashboard_live.ex deleted file mode 100644 index 70a91ae3..00000000 --- a/lib/shift73k_web/live/user_dashboard_live.ex +++ /dev/null @@ -1,18 +0,0 @@ -defmodule Shift73kWeb.UserDashboardLive do - use Shift73kWeb, :live_view - - @impl true - def mount(_params, session, socket) do - socket = assign_defaults(socket, session) - {:ok, socket} - end - - @impl true - def render(assigns) do - ~L""" -
-

Welcome to the user dashboard!

-
- """ - end -end diff --git a/lib/shift73k_web/router.ex b/lib/shift73k_web/router.ex index d18f94cd..2545ec96 100644 --- a/lib/shift73k_web/router.ex +++ b/lib/shift73k_web/router.ex @@ -88,17 +88,13 @@ defmodule Shift73kWeb.Router do get("/users/confirm/:token", UserConfirmationController, :confirm) end - scope "/", Shift73kWeb do - pipe_through([:browser, :require_authenticated_user, :user]) + # scope "/", Shift73kWeb do + # pipe_through([:browser, :require_authenticated_user, :user]) + # end - live("/user_dashboard", UserDashboardLive, :index) - end - - scope "/", Shift73kWeb do - pipe_through([:browser, :require_authenticated_user, :admin]) - - live("/admin_dashboard", AdminDashboardLive, :index) - end + # scope "/", Shift73kWeb do + # pipe_through([:browser, :require_authenticated_user, :admin]) + # end # Users Management scope "/users", Shift73kWeb do diff --git a/test/shift73k_web/live/admin_dashboard_live_test.exs b/test/shift73k_web/live/admin_dashboard_live_test.exs deleted file mode 100644 index 405c5045..00000000 --- a/test/shift73k_web/live/admin_dashboard_live_test.exs +++ /dev/null @@ -1,80 +0,0 @@ -defmodule Shift73kWeb.AdminDashboardLiveTest do - use Shift73kWeb.ConnCase - - import Phoenix.LiveViewTest - import Shift73k.AccountsFixtures - - test "disconnected and connected render without authentication should redirect to login page", - %{conn: conn} do - # If we don't previously log in we will be redirected to the login page - assert {:error, {:redirect, %{to: "/users/log_in"}}} = live(conn, "/admin_dashboard") - end - - test "disconnected and connected render authenticated with user role should redirect to index page", - %{ - conn: conn - } do - conn = conn |> log_in_user(user_fixture()) - assert {:error, {:redirect, %{to: "/"}}} = live(conn, "/admin_dashboard") - end - - test "disconnected and connected render authenticated with admin role should redirect to index page", - %{ - conn: conn - } do - conn = conn |> log_in_user(admin_fixture()) - {:ok, admin_dashboard, disconnected_html} = live(conn, "/admin_dashboard") - assert disconnected_html =~ "Welcome to the admin dashboard!" - assert render(admin_dashboard) =~ "Welcome to the admin dashboard!" - end - - test "logs out when force logout on logged user", %{ - conn: conn - } do - admin = admin_fixture() - conn = conn |> log_in_user(admin) - - {:ok, admin_dashboard, disconnected_html} = live(conn, "/admin_dashboard") - assert disconnected_html =~ "Welcome to the admin dashboard!" - assert render(admin_dashboard) =~ "Welcome to the admin dashboard!" - - Shift73k.Accounts.logout_user(admin) - - # Assert our liveview process is down - ref = Process.monitor(admin_dashboard.pid) - assert_receive {:DOWN, ^ref, _, _, _} - refute Process.alive?(admin_dashboard.pid) - - # Assert our liveview was redirected, following first to /users/force_logout, then to "/", and then to "/users/log_in" - assert_redirect(admin_dashboard, "/users/force_logout") - - conn = get(conn, "/users/force_logout") - assert "/" = redir_path = redirected_to(conn, 302) - conn = get(recycle(conn), redir_path) - - assert html_response(conn, 200) =~ - "You were logged out. Please login again to continue using our application." - end - - test "doesn't log out when force logout on another user", %{ - conn: conn - } do - admin1 = admin_fixture() - admin2 = admin_fixture() - conn = conn |> log_in_user(admin1) - - {:ok, admin_dashboard, disconnected_html} = live(conn, "/admin_dashboard") - assert disconnected_html =~ "Welcome to the admin dashboard!" - assert render(admin_dashboard) =~ "Welcome to the admin dashboard!" - - Shift73k.Accounts.logout_user(admin2) - - # Assert our liveview is alive - ref = Process.monitor(admin_dashboard.pid) - refute_receive {:DOWN, ^ref, _, _, _} - assert Process.alive?(admin_dashboard.pid) - - # If we are able to rerender the page it means nothing happened - assert render(admin_dashboard) =~ "Welcome to the admin dashboard!" - end -end diff --git a/test/shift73k_web/live/user_dashboard_live_test.exs b/test/shift73k_web/live/user_dashboard_live_test.exs deleted file mode 100644 index d94a889e..00000000 --- a/test/shift73k_web/live/user_dashboard_live_test.exs +++ /dev/null @@ -1,82 +0,0 @@ -defmodule Shift73kWeb.UserDashboardLiveTest do - use Shift73kWeb.ConnCase - - import Phoenix.LiveViewTest - import Shift73k.AccountsFixtures - - test "disconnected and connected render without authentication should redirect to login page", - %{conn: conn} do - # If we don't previously log in we will be redirected to the login page - assert {:error, {:redirect, %{to: "/users/log_in"}}} = live(conn, "/user_dashboard") - end - - test "disconnected and connected render authenticated with user role should redirect to index page", - %{ - conn: conn - } do - conn = conn |> log_in_user(user_fixture()) - {:ok, user_dashboard, disconnected_html} = live(conn, "/user_dashboard") - assert disconnected_html =~ "Welcome to the user dashboard!" - assert render(user_dashboard) =~ "Welcome to the user dashboard!" - end - - test "disconnected and connected render authenticated with admin role should redirect to index page", - %{ - conn: conn - } do - conn = conn |> log_in_user(admin_fixture()) - {:ok, user_dashboard, disconnected_html} = live(conn, "/user_dashboard") - assert disconnected_html =~ "Welcome to the user dashboard!" - assert render(user_dashboard) =~ "Welcome to the user dashboard!" - end - - test "logs out when force logout on logged user", %{ - conn: conn - } do - user = user_fixture() - conn = conn |> log_in_user(user) - - {:ok, user_dashboard, disconnected_html} = live(conn, "/user_dashboard") - assert disconnected_html =~ "Welcome to the user dashboard!" - assert render(user_dashboard) =~ "Welcome to the user dashboard!" - - Shift73k.Accounts.logout_user(user) - - # Assert our liveview process is down - ref = Process.monitor(user_dashboard.pid) - assert_receive {:DOWN, ^ref, _, _, _} - refute Process.alive?(user_dashboard.pid) - - # Assert our liveview was redirected, following first to /users/force_logout, then to "/", and then to "/users/log_in" - assert_redirect(user_dashboard, "/users/force_logout") - - conn = get(conn, "/users/force_logout") - assert "/" = redir_path = redirected_to(conn, 302) - conn = get(recycle(conn), redir_path) - - assert html_response(conn, 200) =~ - "You were logged out. Please login again to continue using our application." - end - - test "doesn't log out when force logout on another user", %{ - conn: conn - } do - user1 = user_fixture() - user2 = user_fixture() - conn = conn |> log_in_user(user1) - - {:ok, user_dashboard, disconnected_html} = live(conn, "/user_dashboard") - assert disconnected_html =~ "Welcome to the user dashboard!" - assert render(user_dashboard) =~ "Welcome to the user dashboard!" - - Shift73k.Accounts.logout_user(user2) - - # Assert our liveview is alive - ref = Process.monitor(user_dashboard.pid) - refute_receive {:DOWN, ^ref, _, _, _} - assert Process.alive?(user_dashboard.pid) - - # If we are able to rerender the page it means nothing happened - assert render(user_dashboard) =~ "Welcome to the user dashboard!" - end -end