diff --git a/lib/real_estate_web/router.ex b/lib/real_estate_web/router.ex index a42338fb..1f0b4f41 100644 --- a/lib/real_estate_web/router.ex +++ b/lib/real_estate_web/router.ex @@ -17,12 +17,6 @@ defmodule RealEstateWeb.Router do plug :accepts, ["json"] end - scope "/", RealEstateWeb do - pipe_through :browser - - live "/", PageLive, :index - end - # Other scopes may use custom stacks. # scope "/api", RealEstateWeb do # pipe_through :api @@ -66,6 +60,9 @@ defmodule RealEstateWeb.Router do put "/users/settings/update_password", UserSettingsController, :update_password put "/users/settings/update_email", UserSettingsController, :update_email get "/users/settings/confirm_email/:token", UserSettingsController, :confirm_email + + # This line was moved + live "/", PageLive, :index end scope "/", RealEstateWeb do diff --git a/test/real_estate_web/live/page_live_test.exs b/test/real_estate_web/live/page_live_test.exs index 5d205d58..03a5d543 100644 --- a/test/real_estate_web/live/page_live_test.exs +++ b/test/real_estate_web/live/page_live_test.exs @@ -2,8 +2,19 @@ defmodule RealEstateWeb.PageLiveTest 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, "/") + end + + test "disconnected and connected render with authentication should redirect to index page", %{ + conn: conn + } do + conn = conn |> log_in_user(user_fixture()) - test "disconnected and connected render", %{conn: conn} do {:ok, page_live, disconnected_html} = live(conn, "/") assert disconnected_html =~ "Welcome to Phoenix!" assert render(page_live) =~ "Welcome to Phoenix!"