Skip to content

Commit

Permalink
fix failing tests after mix phx.gen.auth #207
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Feb 26, 2023
1 parent 90086a8 commit da0af7e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 30 deletions.
2 changes: 1 addition & 1 deletion _archive/lib/auth/person.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ defmodule Auth.Person do
login: "alex",
name: "Alex McAwesome",
type: "User",
url: "https://api.github.com/users/alex"
url: "https://api.github.com/people/alex"
})
%{
"email" => "nelson@gmail.com",
Expand Down
8 changes: 6 additions & 2 deletions lib/auth/accounts/person_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,11 @@ defmodule Auth.Accounts.PersonToken do
select: person

{:ok, query}

# phx.gen.auth boilerplate code not yet covered by tests ...
# coveralls-ignore-start
:error ->
:error
# coveralls-ignore-stop
end
end

Expand Down Expand Up @@ -153,9 +155,11 @@ defmodule Auth.Accounts.PersonToken do
where: token.inserted_at > ago(@change_email_validity_in_days, "day")

{:ok, query}

# phx.gen.auth boilerplate code not yet covered by tests ...
# coveralls-ignore-start
:error ->
:error
# coveralls-ignore-stop
end
end

Expand Down
13 changes: 0 additions & 13 deletions lib/auth_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -185,19 +185,6 @@ defmodule AuthWeb.CoreComponents do

def flash_group(assigns) do
~H"""
<.flash kind={:info} title="Success!" flash={@flash} />
<.flash kind={:error} title="Error!" flash={@flash} />
<.flash
id="disconnected"
kind={:error}
title="We can't find the internet"
close={false}
autoshow={false}
phx-disconnected={show("#disconnected")}
phx-connected={hide("#disconnected")}
>
Attempting to reconnect <Heroicons.arrow_path class="ml-1 w-3 h-3 inline animate-spin" />
</.flash>
"""
end

Expand Down
1 change: 0 additions & 1 deletion lib/auth_web/components/layouts/app.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
</header>
<main class="px-4 py-20 sm:px-6 lg:px-8">
<div class="mx-auto max-w-2xl">
<.flash_group flash={@flash} />
<%= @inner_content %>
</div>
</main>
6 changes: 4 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ defmodule Auth.MixProject do
"coveralls.detail": :test,
"coveralls.post": :test,
"coveralls.html": :test,
test: :test
test: :test,
t: :test
]
]
end
Expand Down Expand Up @@ -87,7 +88,8 @@ defmodule Auth.MixProject do
"ecto.reset": ["ecto.drop", "ecto.setup"],
s: ["phx.server"],
setup: ["deps.get", "ecto.setup", "assets.setup", "assets.build"],
test: ["ecto.create --quiet", "ecto.migrate --quiet", "test"]
t: ["test"],
test: ["ecto.setup --quiet", "ecto.migrate --quiet", "test"]
]
end
end
2 changes: 1 addition & 1 deletion role-based-access-control.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ mix ecto.gen.migration create_people_roles
```

Open the migration file that was just created, e.g:
[`/Users/n/code/auth/priv/repo/migrations/20200723154847_create_people_roles.exs`](https://github.com/dwyl/auth/blob/ef4261d09a702c4003cd84f30dabe630b47922d2/priv/repo/migrations/20200723154847_create_people_roles.exs)
[`/people/n/code/auth/priv/repo/migrations/20200723154847_create_people_roles.exs`](https://github.com/dwyl/auth/blob/ef4261d09a702c4003cd84f30dabe630b47922d2/priv/repo/migrations/20200723154847_create_people_roles.exs)


Replace the contents of the file with the following code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ defmodule AuthWeb.PersonRegistrationControllerTest do
conn = get(conn, ~p"/people/register")
response = html_response(conn, 200)
assert response =~ "Register"
assert response =~ ~p"/users/log_in"
assert response =~ ~p"/users/register"
assert response =~ ~p"/people/log_in"
assert response =~ ~p"/people/register"
end

test "redirects if already logged in", %{conn: conn} do
Expand All @@ -36,8 +36,8 @@ defmodule AuthWeb.PersonRegistrationControllerTest do
conn = get(conn, ~p"/")
response = html_response(conn, 200)
assert response =~ email
assert response =~ ~p"/users/settings"
assert response =~ ~p"/users/log_out"
assert response =~ ~p"/people/settings"
assert response =~ ~p"/people/log_out"
end

test "render errors for invalid data", %{conn: conn} do
Expand Down
9 changes: 3 additions & 6 deletions test/auth_web/controllers/person_session_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ defmodule AuthWeb.PersonSessionControllerTest do
conn = get(conn, ~p"/people/log_in")
response = html_response(conn, 200)
assert response =~ "Log in"
assert response =~ ~p"/users/register"
assert response =~ ~p"/people/register"
assert response =~ "Forgot your password?"
end

Expand All @@ -36,8 +36,8 @@ defmodule AuthWeb.PersonSessionControllerTest do
conn = get(conn, ~p"/")
response = html_response(conn, 200)
assert response =~ person.email
assert response =~ ~p"/users/settings"
assert response =~ ~p"/users/log_out"
assert response =~ ~p"/people/settings"
assert response =~ ~p"/people/log_out"
end

test "logs the person in with remember me", %{conn: conn, person: person} do
Expand Down Expand Up @@ -66,7 +66,6 @@ defmodule AuthWeb.PersonSessionControllerTest do
})

assert redirected_to(conn) == "/foo/bar"
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Welcome back!"
end

test "emits error message with invalid credentials", %{conn: conn, person: person} do
Expand All @@ -86,14 +85,12 @@ defmodule AuthWeb.PersonSessionControllerTest do
conn = conn |> log_in_person(person) |> delete(~p"/people/log_out")
assert redirected_to(conn) == ~p"/"
refute get_session(conn, :person_token)
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Logged out successfully"
end

test "succeeds even if the person is not logged in", %{conn: conn} do
conn = delete(conn, ~p"/people/log_out")
assert redirected_to(conn) == ~p"/"
refute get_session(conn, :person_token)
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Logged out successfully"
end
end
end

0 comments on commit da0af7e

Please sign in to comment.