bones73k/test/real_estate_web/live/user_dashboard_live_test.exs
João Gilberto Balsini Moura 8590df5032 Add authorised routes with tests
2020-09-14 13:10:54 -03:00

32 lines
1.2 KiB
Elixir

defmodule RealEstateWeb.UserDashboardLiveTest do
use RealEstateWeb.ConnCase
import Phoenix.LiveViewTest
import RealEstate.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
end