mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-02-23 21:54:33 +01:00
Adds new tests.
This commit is contained in:
parent
c4f483e5ee
commit
eaf54d4126
3 changed files with 74 additions and 0 deletions
|
@ -0,0 +1,31 @@
|
||||||
|
defmodule PhilomenaWeb.DeactivationControllerTest do
|
||||||
|
use PhilomenaWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
alias Swoosh.Adapters.Local.Storage.Memory
|
||||||
|
alias Philomena.Users
|
||||||
|
alias Philomena.Repo
|
||||||
|
import Philomena.UsersFixtures
|
||||||
|
|
||||||
|
setup :register_and_log_in_user
|
||||||
|
|
||||||
|
describe "GET /deactivations" do
|
||||||
|
test "renders the deactive account page", %{conn: conn, user: user} do
|
||||||
|
conn = get(conn, ~p"/deactivations")
|
||||||
|
response = html_response(conn, 200)
|
||||||
|
assert response =~ "<h1>Deactivate Account</h1>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "DELETE /deactivations" do
|
||||||
|
test "causes the user to be deactivated", %{conn: conn, user: user} do
|
||||||
|
conn = delete(conn, ~p"/deactivations")
|
||||||
|
assert redirected_to(conn) == ~p"/"
|
||||||
|
conn = get(conn, ~p"/registrations/edit")
|
||||||
|
assert redirected_to(conn) == ~p"/sessions/new"
|
||||||
|
assert Memory.all() |> Enum.count() == 1
|
||||||
|
|
||||||
|
user = Users.get_user!(user.id)
|
||||||
|
assert user.deleted_by_user_id == user.id
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,37 @@
|
||||||
|
defmodule PhilomenaWeb.ReactivationControllerTest do
|
||||||
|
use PhilomenaWeb.ConnCase, async: true
|
||||||
|
|
||||||
|
alias Swoosh.Adapters.Local.Storage.Memory
|
||||||
|
alias Philomena.Users
|
||||||
|
alias Philomena.Repo
|
||||||
|
alias Phoenix.Flash
|
||||||
|
import Philomena.UsersFixtures
|
||||||
|
|
||||||
|
setup :register_and_log_in_user
|
||||||
|
|
||||||
|
describe "GET /reactivations/:id" do
|
||||||
|
test "renders the reactivate account page", %{conn: conn, user: user} do
|
||||||
|
conn = delete(conn, ~p"/deactivations")
|
||||||
|
conn = get(conn, ~p"/reactivations/pinkie-pie-is-best-pony")
|
||||||
|
response = html_response(conn, 200)
|
||||||
|
assert response =~ "<h1>Reactivate Your Account</h1>"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "POST /reactivations/:id" do
|
||||||
|
test "reactivate account page works", %{conn: conn, user: user} do
|
||||||
|
conn = delete(conn, ~p"/deactivations")
|
||||||
|
reactivation_link = Memory.all() |> hd |> extract_reactivation_link_from_email
|
||||||
|
conn = post(conn, reactivation_link)
|
||||||
|
assert redirected_to(conn) == ~p"/"
|
||||||
|
|
||||||
|
user = Users.get_user!(user.id)
|
||||||
|
assert user.deleted_by_user_id == nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp extract_reactivation_link_from_email(email = %Swoosh.Email{}) do
|
||||||
|
Regex.scan(~r/http:\/\/localhost:4002\/reactivations\/.*/, email.text_body) |> hd |> hd
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -55,6 +55,12 @@ defmodule PhilomenaWeb.RegistrationControllerTest do
|
||||||
assert response =~ "Settings"
|
assert response =~ "Settings"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "renders the deactivation section of the settings page", %{conn: conn, user: user} do
|
||||||
|
conn = get(conn, ~p"/registrations/edit")
|
||||||
|
response = html_response(conn, 200)
|
||||||
|
assert response =~ "<h3>Deactivate Account</h3>"
|
||||||
|
end
|
||||||
|
|
||||||
test "redirects if user is not logged in" do
|
test "redirects if user is not logged in" do
|
||||||
conn = build_conn()
|
conn = build_conn()
|
||||||
conn = get(conn, ~p"/registrations/edit")
|
conn = get(conn, ~p"/registrations/edit")
|
||||||
|
|
Loading…
Reference in a new issue