mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-21 21:03:11 +01:00
Updates test to use extract_user_token.
This commit is contained in:
parent
f77043be03
commit
5d6604b57b
1 changed files with 5 additions and 19 deletions
|
@ -10,9 +10,6 @@ defmodule PhilomenaWeb.ReactivationControllerTest do
|
|||
%{user: deactivated_user_fixture()}
|
||||
end
|
||||
|
||||
@host PhilomenaWeb.Endpoint.config(:url)[:host]
|
||||
@port PhilomenaWeb.Endpoint.config(:http)[:port]
|
||||
|
||||
describe "GET /reactivations/:id" do
|
||||
test "renders the reactivate account page", %{conn: conn} do
|
||||
conn = get(conn, ~p"/reactivations/pinkie-pie-is-best-pony")
|
||||
|
@ -23,17 +20,16 @@ defmodule PhilomenaWeb.ReactivationControllerTest do
|
|||
|
||||
describe "POST /reactivations/" do
|
||||
test "reactivate account page works", %{conn: conn, user: user} do
|
||||
{:ok, email} =
|
||||
Users.deliver_user_reactivation_instructions(user, &url(~p"/reactivations/#{&1}"))
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Users.deliver_user_reactivation_instructions(user, url)
|
||||
end)
|
||||
|
||||
assert UserToken.user_and_contexts_query(user, ["reactivate"]) |> Repo.exists?()
|
||||
|
||||
{token, url} = extract_reactivation_link_from_email(email)
|
||||
|
||||
assert token != nil
|
||||
assert url != nil
|
||||
|
||||
conn = post(conn, url, %{"token" => token})
|
||||
conn = post(conn, ~p"/reactivations", %{"token" => token})
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
|
||||
user = Users.get_user!(user.id)
|
||||
|
@ -42,14 +38,4 @@ defmodule PhilomenaWeb.ReactivationControllerTest do
|
|||
assert not (UserToken.user_and_contexts_query(user, ["reactivate"]) |> Repo.exists?())
|
||||
end
|
||||
end
|
||||
|
||||
defp extract_reactivation_link_from_email(email = %Swoosh.Email{}) do
|
||||
%{"token" => token, "url" => url} =
|
||||
Regex.named_captures(
|
||||
~r/(?<url>http:\/\/#{@host}:#{@port}\/reactivations)\/(?<token>.*)/,
|
||||
email.text_body
|
||||
)
|
||||
|
||||
{token, url}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue