this is a really good first commit
This commit is contained in:
@ -152,9 +152,9 @@ defmodule SomethingErlang.AccountsTest do
|
||||
|
||||
test "validates email uniqueness", %{user: user} do
|
||||
%{email: email} = user_fixture()
|
||||
password = valid_user_password()
|
||||
|
||||
{:error, changeset} =
|
||||
Accounts.apply_user_email(user, valid_user_password(), %{email: email})
|
||||
{:error, changeset} = Accounts.apply_user_email(user, password, %{email: email})
|
||||
|
||||
assert "has already been taken" in errors_on(changeset).email
|
||||
end
|
||||
@ -174,7 +174,7 @@ defmodule SomethingErlang.AccountsTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "deliver_update_email_instructions/3" do
|
||||
describe "deliver_user_update_email_instructions/3" do
|
||||
setup do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
@ -182,7 +182,7 @@ defmodule SomethingErlang.AccountsTest do
|
||||
test "sends token through notification", %{user: user} do
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_update_email_instructions(user, "current@example.com", url)
|
||||
Accounts.deliver_user_update_email_instructions(user, "current@example.com", url)
|
||||
end)
|
||||
|
||||
{:ok, token} = Base.url_decode64(token, padding: false)
|
||||
@ -200,7 +200,7 @@ defmodule SomethingErlang.AccountsTest do
|
||||
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_update_email_instructions(%{user | email: email}, user.email, url)
|
||||
Accounts.deliver_user_update_email_instructions(%{user | email: email}, user.email, url)
|
||||
end)
|
||||
|
||||
%{user: user, token: token, email: email}
|
||||
@ -353,11 +353,11 @@ defmodule SomethingErlang.AccountsTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete_session_token/1" do
|
||||
describe "delete_user_session_token/1" do
|
||||
test "deletes the token" do
|
||||
user = user_fixture()
|
||||
token = Accounts.generate_user_session_token(user)
|
||||
assert Accounts.delete_session_token(token) == :ok
|
||||
assert Accounts.delete_user_session_token(token) == :ok
|
||||
refute Accounts.get_user_by_session_token(token)
|
||||
end
|
||||
end
|
||||
@ -500,7 +500,7 @@ defmodule SomethingErlang.AccountsTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "inspect/2" do
|
||||
describe "inspect/2 for the User module" do
|
||||
test "does not include password" do
|
||||
refute inspect(%User{password: "123456"}) =~ "password: \"123456\""
|
||||
end
|
||||
|
@ -1,61 +0,0 @@
|
||||
defmodule SomethingErlang.ForumsTest do
|
||||
use SomethingErlang.DataCase
|
||||
|
||||
alias SomethingErlang.Forums
|
||||
|
||||
describe "threads" do
|
||||
alias SomethingErlang.Forums.Thread
|
||||
|
||||
import SomethingErlang.ForumsFixtures
|
||||
|
||||
@invalid_attrs %{thread_id: nil, title: nil}
|
||||
|
||||
test "list_threads/0 returns all threads" do
|
||||
thread = thread_fixture()
|
||||
assert Forums.list_threads() == [thread]
|
||||
end
|
||||
|
||||
test "get_thread!/1 returns the thread with given id" do
|
||||
thread = thread_fixture()
|
||||
assert Forums.get_thread!(thread.id) == thread
|
||||
end
|
||||
|
||||
test "create_thread/1 with valid data creates a thread" do
|
||||
valid_attrs = %{thread_id: 42, title: "some title"}
|
||||
|
||||
assert {:ok, %Thread{} = thread} = Forums.create_thread(valid_attrs)
|
||||
assert thread.thread_id == 42
|
||||
assert thread.title == "some title"
|
||||
end
|
||||
|
||||
test "create_thread/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Forums.create_thread(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_thread/2 with valid data updates the thread" do
|
||||
thread = thread_fixture()
|
||||
update_attrs = %{thread_id: 43, title: "some updated title"}
|
||||
|
||||
assert {:ok, %Thread{} = thread} = Forums.update_thread(thread, update_attrs)
|
||||
assert thread.thread_id == 43
|
||||
assert thread.title == "some updated title"
|
||||
end
|
||||
|
||||
test "update_thread/2 with invalid data returns error changeset" do
|
||||
thread = thread_fixture()
|
||||
assert {:error, %Ecto.Changeset{}} = Forums.update_thread(thread, @invalid_attrs)
|
||||
assert thread == Forums.get_thread!(thread.id)
|
||||
end
|
||||
|
||||
test "delete_thread/1 deletes the thread" do
|
||||
thread = thread_fixture()
|
||||
assert {:ok, %Thread{}} = Forums.delete_thread(thread)
|
||||
assert_raise Ecto.NoResultsError, fn -> Forums.get_thread!(thread.id) end
|
||||
end
|
||||
|
||||
test "change_thread/1 returns a thread changeset" do
|
||||
thread = thread_fixture()
|
||||
assert %Ecto.Changeset{} = Forums.change_thread(thread)
|
||||
end
|
||||
end
|
||||
end
|
14
test/something_erlang_web/controllers/error_html_test.exs
Normal file
14
test/something_erlang_web/controllers/error_html_test.exs
Normal file
@ -0,0 +1,14 @@
|
||||
defmodule SomethingErlangWeb.ErrorHTMLTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
# Bring render_to_string/4 for testing custom views
|
||||
import Phoenix.Template
|
||||
|
||||
test "renders 404.html" do
|
||||
assert render_to_string(SomethingErlangWeb.ErrorHTML, "404", "html", []) == "Not Found"
|
||||
end
|
||||
|
||||
test "renders 500.html" do
|
||||
assert render_to_string(SomethingErlangWeb.ErrorHTML, "500", "html", []) == "Internal Server Error"
|
||||
end
|
||||
end
|
12
test/something_erlang_web/controllers/error_json_test.exs
Normal file
12
test/something_erlang_web/controllers/error_json_test.exs
Normal file
@ -0,0 +1,12 @@
|
||||
defmodule SomethingErlangWeb.ErrorJSONTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
test "renders 404" do
|
||||
assert SomethingErlangWeb.ErrorJSON.render("404.json", %{}) == %{errors: %{detail: "Not Found"}}
|
||||
end
|
||||
|
||||
test "renders 500" do
|
||||
assert SomethingErlangWeb.ErrorJSON.render("500.json", %{}) ==
|
||||
%{errors: %{detail: "Internal Server Error"}}
|
||||
end
|
||||
end
|
@ -2,7 +2,7 @@ defmodule SomethingErlangWeb.PageControllerTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
test "GET /", %{conn: conn} do
|
||||
conn = get(conn, "/")
|
||||
assert html_response(conn, 200) =~ "Welcome to Phoenix!"
|
||||
conn = get(conn, ~p"/")
|
||||
assert html_response(conn, 200) =~ "Peace of mind from prototype to production"
|
||||
end
|
||||
end
|
||||
|
@ -1,105 +0,0 @@
|
||||
defmodule SomethingErlangWeb.UserConfirmationControllerTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
alias SomethingErlang.Accounts
|
||||
alias SomethingErlang.Repo
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
setup do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
|
||||
describe "GET /users/confirm" do
|
||||
test "renders the resend confirmation page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_confirmation_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Resend confirmation instructions</h1>"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/confirm" do
|
||||
@tag :capture_log
|
||||
test "sends a new confirmation token", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||
"user" => %{"email" => user.email}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :info) =~ "If your email is in our system"
|
||||
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "confirm"
|
||||
end
|
||||
|
||||
test "does not send confirmation token if User is confirmed", %{conn: conn, user: user} do
|
||||
Repo.update!(Accounts.User.confirm_changeset(user))
|
||||
|
||||
conn =
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||
"user" => %{"email" => user.email}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :info) =~ "If your email is in our system"
|
||||
refute Repo.get_by(Accounts.UserToken, user_id: user.id)
|
||||
end
|
||||
|
||||
test "does not send confirmation token if email is invalid", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, Routes.user_confirmation_path(conn, :create), %{
|
||||
"user" => %{"email" => "unknown@example.com"}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :info) =~ "If your email is in our system"
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /users/confirm/:token" do
|
||||
test "renders the confirmation page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_confirmation_path(conn, :edit, "some-token"))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Confirm account</h1>"
|
||||
|
||||
form_action = Routes.user_confirmation_path(conn, :update, "some-token")
|
||||
assert response =~ "action=\"#{form_action}\""
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/confirm/:token" do
|
||||
test "confirms the given token once", %{conn: conn, user: user} do
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_user_confirmation_instructions(user, url)
|
||||
end)
|
||||
|
||||
conn = post(conn, Routes.user_confirmation_path(conn, :update, token))
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :info) =~ "User confirmed successfully"
|
||||
assert Accounts.get_user!(user.id).confirmed_at
|
||||
refute get_session(conn, :user_token)
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
|
||||
# When not logged in
|
||||
conn = post(conn, Routes.user_confirmation_path(conn, :update, token))
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
|
||||
|
||||
# When logged in
|
||||
conn =
|
||||
build_conn()
|
||||
|> log_in_user(user)
|
||||
|> post(Routes.user_confirmation_path(conn, :update, token))
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
refute get_flash(conn, :error)
|
||||
end
|
||||
|
||||
test "does not confirm email with invalid token", %{conn: conn, user: user} do
|
||||
conn = post(conn, Routes.user_confirmation_path(conn, :update, "oops"))
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :error) =~ "User confirmation link is invalid or it has expired"
|
||||
refute Accounts.get_user!(user.id).confirmed_at
|
||||
end
|
||||
end
|
||||
end
|
@ -1,54 +0,0 @@
|
||||
defmodule SomethingErlangWeb.UserRegistrationControllerTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
describe "GET /users/register" do
|
||||
test "renders registration page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_registration_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Register</h1>"
|
||||
assert response =~ "Log in</a>"
|
||||
assert response =~ "Register</a>"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn} do
|
||||
conn = conn |> log_in_user(user_fixture()) |> get(Routes.user_registration_path(conn, :new))
|
||||
assert redirected_to(conn) == "/"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/register" do
|
||||
@tag :capture_log
|
||||
test "creates account and logs the user in", %{conn: conn} do
|
||||
email = unique_user_email()
|
||||
|
||||
conn =
|
||||
post(conn, Routes.user_registration_path(conn, :create), %{
|
||||
"user" => valid_user_attributes(email: email)
|
||||
})
|
||||
|
||||
assert get_session(conn, :user_token)
|
||||
assert redirected_to(conn) == "/"
|
||||
|
||||
# Now do a logged in request and assert on the menu
|
||||
conn = get(conn, "/")
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ email
|
||||
assert response =~ "Settings</a>"
|
||||
assert response =~ "Log out</a>"
|
||||
end
|
||||
|
||||
test "render errors for invalid data", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, Routes.user_registration_path(conn, :create), %{
|
||||
"user" => %{"email" => "with spaces", "password" => "too short"}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Register</h1>"
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "should be at least 12 character"
|
||||
end
|
||||
end
|
||||
end
|
@ -1,113 +0,0 @@
|
||||
defmodule SomethingErlangWeb.UserResetPasswordControllerTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
alias SomethingErlang.Accounts
|
||||
alias SomethingErlang.Repo
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
setup do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
|
||||
describe "GET /users/reset_password" do
|
||||
test "renders the reset password page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_reset_password_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Forgot your password?</h1>"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/reset_password" do
|
||||
@tag :capture_log
|
||||
test "sends a new reset password token", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, Routes.user_reset_password_path(conn, :create), %{
|
||||
"user" => %{"email" => user.email}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :info) =~ "If your email is in our system"
|
||||
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "reset_password"
|
||||
end
|
||||
|
||||
test "does not send reset password token if email is invalid", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, Routes.user_reset_password_path(conn, :create), %{
|
||||
"user" => %{"email" => "unknown@example.com"}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :info) =~ "If your email is in our system"
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /users/reset_password/:token" do
|
||||
setup %{user: user} do
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_user_reset_password_instructions(user, url)
|
||||
end)
|
||||
|
||||
%{token: token}
|
||||
end
|
||||
|
||||
test "renders reset password", %{conn: conn, token: token} do
|
||||
conn = get(conn, Routes.user_reset_password_path(conn, :edit, token))
|
||||
assert html_response(conn, 200) =~ "<h1>Reset password</h1>"
|
||||
end
|
||||
|
||||
test "does not render reset password with invalid token", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_reset_password_path(conn, :edit, "oops"))
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /users/reset_password/:token" do
|
||||
setup %{user: user} do
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_user_reset_password_instructions(user, url)
|
||||
end)
|
||||
|
||||
%{token: token}
|
||||
end
|
||||
|
||||
test "resets password once", %{conn: conn, user: user, token: token} do
|
||||
conn =
|
||||
put(conn, Routes.user_reset_password_path(conn, :update, token), %{
|
||||
"user" => %{
|
||||
"password" => "new valid password",
|
||||
"password_confirmation" => "new valid password"
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ "Password reset successfully"
|
||||
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||
end
|
||||
|
||||
test "does not reset password on invalid data", %{conn: conn, token: token} do
|
||||
conn =
|
||||
put(conn, Routes.user_reset_password_path(conn, :update, token), %{
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Reset password</h1>"
|
||||
assert response =~ "should be at least 12 character(s)"
|
||||
assert response =~ "does not match password"
|
||||
end
|
||||
|
||||
test "does not reset password with invalid token", %{conn: conn} do
|
||||
conn = put(conn, Routes.user_reset_password_path(conn, :update, "oops"))
|
||||
assert redirected_to(conn) == "/"
|
||||
assert get_flash(conn, :error) =~ "Reset password link is invalid or it has expired"
|
||||
end
|
||||
end
|
||||
end
|
@ -7,33 +7,18 @@ defmodule SomethingErlangWeb.UserSessionControllerTest do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
|
||||
describe "GET /users/log_in" do
|
||||
test "renders log in page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_session_path(conn, :new))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Log in</h1>"
|
||||
assert response =~ "Register</a>"
|
||||
assert response =~ "Forgot your password?</a>"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn, user: user} do
|
||||
conn = conn |> log_in_user(user) |> get(Routes.user_session_path(conn, :new))
|
||||
assert redirected_to(conn) == "/"
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /users/log_in" do
|
||||
test "logs the user in", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
post(conn, ~p"/users/log_in", %{
|
||||
"user" => %{"email" => user.email, "password" => valid_user_password()}
|
||||
})
|
||||
|
||||
assert get_session(conn, :user_token)
|
||||
assert redirected_to(conn) == "/"
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
|
||||
# Now do a logged in request and assert on the menu
|
||||
conn = get(conn, "/")
|
||||
conn = get(conn, ~p"/")
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ user.email
|
||||
assert response =~ "Settings</a>"
|
||||
@ -42,7 +27,7 @@ defmodule SomethingErlangWeb.UserSessionControllerTest do
|
||||
|
||||
test "logs the user in with remember me", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
post(conn, ~p"/users/log_in", %{
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => valid_user_password(),
|
||||
@ -51,14 +36,14 @@ defmodule SomethingErlangWeb.UserSessionControllerTest do
|
||||
})
|
||||
|
||||
assert conn.resp_cookies["_something_erlang_web_user_remember_me"]
|
||||
assert redirected_to(conn) == "/"
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
end
|
||||
|
||||
test "logs the user in with return to", %{conn: conn, user: user} do
|
||||
conn =
|
||||
conn
|
||||
|> init_test_session(user_return_to: "/foo/bar")
|
||||
|> post(Routes.user_session_path(conn, :create), %{
|
||||
|> post(~p"/users/log_in", %{
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => valid_user_password()
|
||||
@ -66,33 +51,63 @@ defmodule SomethingErlangWeb.UserSessionControllerTest 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, user: user} do
|
||||
test "login following registration", %{conn: conn, user: user} do
|
||||
conn =
|
||||
post(conn, Routes.user_session_path(conn, :create), %{
|
||||
"user" => %{"email" => user.email, "password" => "invalid_password"}
|
||||
conn
|
||||
|> post(~p"/users/log_in", %{
|
||||
"_action" => "registered",
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => valid_user_password()
|
||||
}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Log in</h1>"
|
||||
assert response =~ "Invalid email or password"
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Account created successfully"
|
||||
end
|
||||
|
||||
test "login following password update", %{conn: conn, user: user} do
|
||||
conn =
|
||||
conn
|
||||
|> post(~p"/users/log_in", %{
|
||||
"_action" => "password_updated",
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => valid_user_password()
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == ~p"/users/settings"
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Password updated successfully"
|
||||
end
|
||||
|
||||
test "redirects to login page with invalid credentials", %{conn: conn} do
|
||||
conn =
|
||||
post(conn, ~p"/users/log_in", %{
|
||||
"user" => %{"email" => "invalid@email.com", "password" => "invalid_password"}
|
||||
})
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :error) == "Invalid email or password"
|
||||
assert redirected_to(conn) == ~p"/users/log_in"
|
||||
end
|
||||
end
|
||||
|
||||
describe "DELETE /users/log_out" do
|
||||
test "logs the user out", %{conn: conn, user: user} do
|
||||
conn = conn |> log_in_user(user) |> delete(Routes.user_session_path(conn, :delete))
|
||||
assert redirected_to(conn) == "/"
|
||||
conn = conn |> log_in_user(user) |> delete(~p"/users/log_out")
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ "Logged out successfully"
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Logged out successfully"
|
||||
end
|
||||
|
||||
test "succeeds even if the user is not logged in", %{conn: conn} do
|
||||
conn = delete(conn, Routes.user_session_path(conn, :delete))
|
||||
assert redirected_to(conn) == "/"
|
||||
conn = delete(conn, ~p"/users/log_out")
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
refute get_session(conn, :user_token)
|
||||
assert get_flash(conn, :info) =~ "Logged out successfully"
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Logged out successfully"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -1,129 +0,0 @@
|
||||
defmodule SomethingErlangWeb.UserSettingsControllerTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
alias SomethingErlang.Accounts
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
setup :register_and_log_in_user
|
||||
|
||||
describe "GET /users/settings" do
|
||||
test "renders settings page", %{conn: conn} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :edit))
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
end
|
||||
|
||||
test "redirects if user is not logged in" do
|
||||
conn = build_conn()
|
||||
conn = get(conn, Routes.user_settings_path(conn, :edit))
|
||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /users/settings (change password form)" do
|
||||
test "updates the user password and resets tokens", %{conn: conn, user: user} do
|
||||
new_password_conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_password",
|
||||
"current_password" => valid_user_password(),
|
||||
"user" => %{
|
||||
"password" => "new valid password",
|
||||
"password_confirmation" => "new valid password"
|
||||
}
|
||||
})
|
||||
|
||||
assert redirected_to(new_password_conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token)
|
||||
assert get_flash(new_password_conn, :info) =~ "Password updated successfully"
|
||||
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||
end
|
||||
|
||||
test "does not update password on invalid data", %{conn: conn} do
|
||||
old_password_conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_password",
|
||||
"current_password" => "invalid",
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
}
|
||||
})
|
||||
|
||||
response = html_response(old_password_conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
assert response =~ "should be at least 12 character(s)"
|
||||
assert response =~ "does not match password"
|
||||
assert response =~ "is not valid"
|
||||
|
||||
assert get_session(old_password_conn, :user_token) == get_session(conn, :user_token)
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /users/settings (change email form)" do
|
||||
@tag :capture_log
|
||||
test "updates the user email", %{conn: conn, user: user} do
|
||||
conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_email",
|
||||
"current_password" => valid_user_password(),
|
||||
"user" => %{"email" => unique_user_email()}
|
||||
})
|
||||
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :info) =~ "A link to confirm your email"
|
||||
assert Accounts.get_user_by_email(user.email)
|
||||
end
|
||||
|
||||
test "does not update email on invalid data", %{conn: conn} do
|
||||
conn =
|
||||
put(conn, Routes.user_settings_path(conn, :update), %{
|
||||
"action" => "update_email",
|
||||
"current_password" => "invalid",
|
||||
"user" => %{"email" => "with spaces"}
|
||||
})
|
||||
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ "<h1>Settings</h1>"
|
||||
assert response =~ "must have the @ sign and no spaces"
|
||||
assert response =~ "is not valid"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /users/settings/confirm_email/:token" do
|
||||
setup %{user: user} do
|
||||
email = unique_user_email()
|
||||
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_update_email_instructions(%{user | email: email}, user.email, url)
|
||||
end)
|
||||
|
||||
%{token: token, email: email}
|
||||
end
|
||||
|
||||
test "updates the user email once", %{conn: conn, user: user, token: token, email: email} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :info) =~ "Email changed successfully"
|
||||
refute Accounts.get_user_by_email(user.email)
|
||||
assert Accounts.get_user_by_email(email)
|
||||
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired"
|
||||
end
|
||||
|
||||
test "does not update email with invalid token", %{conn: conn, user: user} do
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, "oops"))
|
||||
assert redirected_to(conn) == Routes.user_settings_path(conn, :edit)
|
||||
assert get_flash(conn, :error) =~ "Email change link is invalid or it has expired"
|
||||
assert Accounts.get_user_by_email(user.email)
|
||||
end
|
||||
|
||||
test "redirects if user is not logged in", %{token: token} do
|
||||
conn = build_conn()
|
||||
conn = get(conn, Routes.user_settings_path(conn, :confirm_email, token))
|
||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||
end
|
||||
end
|
||||
end
|
@ -1,110 +0,0 @@
|
||||
defmodule SomethingErlangWeb.ThreadLiveTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SomethingErlang.ForumsFixtures
|
||||
|
||||
@create_attrs %{thread_id: 42, title: "some title"}
|
||||
@update_attrs %{thread_id: 43, title: "some updated title"}
|
||||
@invalid_attrs %{thread_id: nil, title: nil}
|
||||
|
||||
defp create_thread(_) do
|
||||
thread = thread_fixture()
|
||||
%{thread: thread}
|
||||
end
|
||||
|
||||
describe "Index" do
|
||||
setup [:create_thread]
|
||||
|
||||
test "lists all threads", %{conn: conn, thread: thread} do
|
||||
{:ok, _index_live, html} = live(conn, Routes.thread_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Listing Threads"
|
||||
assert html =~ thread.title
|
||||
end
|
||||
|
||||
test "saves new thread", %{conn: conn} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.thread_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("a", "New Thread") |> render_click() =~
|
||||
"New Thread"
|
||||
|
||||
assert_patch(index_live, Routes.thread_index_path(conn, :new))
|
||||
|
||||
assert index_live
|
||||
|> form("#thread-form", thread: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#thread-form", thread: @create_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.thread_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Thread created successfully"
|
||||
assert html =~ "some title"
|
||||
end
|
||||
|
||||
test "updates thread in listing", %{conn: conn, thread: thread} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.thread_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#thread-#{thread.id} a", "Edit") |> render_click() =~
|
||||
"Edit Thread"
|
||||
|
||||
assert_patch(index_live, Routes.thread_index_path(conn, :edit, thread))
|
||||
|
||||
assert index_live
|
||||
|> form("#thread-form", thread: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
index_live
|
||||
|> form("#thread-form", thread: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.thread_index_path(conn, :index))
|
||||
|
||||
assert html =~ "Thread updated successfully"
|
||||
assert html =~ "some updated title"
|
||||
end
|
||||
|
||||
test "deletes thread in listing", %{conn: conn, thread: thread} do
|
||||
{:ok, index_live, _html} = live(conn, Routes.thread_index_path(conn, :index))
|
||||
|
||||
assert index_live |> element("#thread-#{thread.id} a", "Delete") |> render_click()
|
||||
refute has_element?(index_live, "#thread-#{thread.id}")
|
||||
end
|
||||
end
|
||||
|
||||
describe "Show" do
|
||||
setup [:create_thread]
|
||||
|
||||
test "displays thread", %{conn: conn, thread: thread} do
|
||||
{:ok, _show_live, html} = live(conn, Routes.thread_show_path(conn, :show, thread))
|
||||
|
||||
assert html =~ "Show Thread"
|
||||
assert html =~ thread.title
|
||||
end
|
||||
|
||||
test "updates thread within modal", %{conn: conn, thread: thread} do
|
||||
{:ok, show_live, _html} = live(conn, Routes.thread_show_path(conn, :show, thread))
|
||||
|
||||
assert show_live |> element("a", "Edit") |> render_click() =~
|
||||
"Edit Thread"
|
||||
|
||||
assert_patch(show_live, Routes.thread_show_path(conn, :edit, thread))
|
||||
|
||||
assert show_live
|
||||
|> form("#thread-form", thread: @invalid_attrs)
|
||||
|> render_change() =~ "can't be blank"
|
||||
|
||||
{:ok, _, html} =
|
||||
show_live
|
||||
|> form("#thread-form", thread: @update_attrs)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, Routes.thread_show_path(conn, :show, thread))
|
||||
|
||||
assert html =~ "Thread updated successfully"
|
||||
assert html =~ "some updated title"
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,67 @@
|
||||
defmodule SomethingErlangWeb.UserConfirmationInstructionsLiveTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
alias SomethingErlang.Accounts
|
||||
alias SomethingErlang.Repo
|
||||
|
||||
setup do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
|
||||
describe "Resend confirmation" do
|
||||
test "renders the resend confirmation page", %{conn: conn} do
|
||||
{:ok, _lv, html} = live(conn, ~p"/users/confirm")
|
||||
assert html =~ "Resend confirmation instructions"
|
||||
end
|
||||
|
||||
test "sends a new confirmation token", %{conn: conn, user: user} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/confirm")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> form("#resend_confirmation_form", user: %{email: user.email})
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, ~p"/")
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~
|
||||
"If your email is in our system"
|
||||
|
||||
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context == "confirm"
|
||||
end
|
||||
|
||||
test "does not send confirmation token if user is confirmed", %{conn: conn, user: user} do
|
||||
Repo.update!(Accounts.User.confirm_changeset(user))
|
||||
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/confirm")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> form("#resend_confirmation_form", user: %{email: user.email})
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, ~p"/")
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~
|
||||
"If your email is in our system"
|
||||
|
||||
refute Repo.get_by(Accounts.UserToken, user_id: user.id)
|
||||
end
|
||||
|
||||
test "does not send confirmation token if email is invalid", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/confirm")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> form("#resend_confirmation_form", user: %{email: "unknown@example.com"})
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, ~p"/")
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~
|
||||
"If your email is in our system"
|
||||
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,88 @@
|
||||
defmodule SomethingErlangWeb.UserConfirmationLiveTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
alias SomethingErlang.Accounts
|
||||
alias SomethingErlang.Repo
|
||||
|
||||
setup do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
|
||||
describe "Confirm user" do
|
||||
test "renders confirmation page", %{conn: conn} do
|
||||
{:ok, _lv, html} = live(conn, ~p"/users/confirm/some-token")
|
||||
assert html =~ "Confirm Account"
|
||||
end
|
||||
|
||||
test "confirms the given token once", %{conn: conn, user: user} do
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_user_confirmation_instructions(user, url)
|
||||
end)
|
||||
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/confirm/#{token}")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> form("#confirmation_form")
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, "/")
|
||||
|
||||
assert {:ok, conn} = result
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~
|
||||
"User confirmed successfully"
|
||||
|
||||
assert Accounts.get_user!(user.id).confirmed_at
|
||||
refute get_session(conn, :user_token)
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
|
||||
# when not logged in
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/confirm/#{token}")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> form("#confirmation_form")
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, "/")
|
||||
|
||||
assert {:ok, conn} = result
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
|
||||
"User confirmation link is invalid or it has expired"
|
||||
|
||||
# when logged in
|
||||
{:ok, lv, _html} =
|
||||
build_conn()
|
||||
|> log_in_user(user)
|
||||
|> live(~p"/users/confirm/#{token}")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> form("#confirmation_form")
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, "/")
|
||||
|
||||
assert {:ok, conn} = result
|
||||
refute Phoenix.Flash.get(conn.assigns.flash, :error)
|
||||
end
|
||||
|
||||
test "does not confirm email with invalid token", %{conn: conn, user: user} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/confirm/invalid-token")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> form("#confirmation_form")
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, ~p"/")
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :error) =~
|
||||
"User confirmation link is invalid or it has expired"
|
||||
|
||||
refute Accounts.get_user!(user.id).confirmed_at
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,63 @@
|
||||
defmodule SomethingErlangWeb.UserForgotPasswordLiveTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
alias SomethingErlang.Accounts
|
||||
alias SomethingErlang.Repo
|
||||
|
||||
describe "Forgot password page" do
|
||||
test "renders email page", %{conn: conn} do
|
||||
{:ok, _lv, html} = live(conn, ~p"/users/reset_password")
|
||||
|
||||
assert html =~ "Forgot your password?"
|
||||
assert html =~ "Register</a>"
|
||||
assert html =~ "Log in</a>"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn} do
|
||||
result =
|
||||
conn
|
||||
|> log_in_user(user_fixture())
|
||||
|> live(~p"/users/reset_password")
|
||||
|> follow_redirect(conn, ~p"/")
|
||||
|
||||
assert {:ok, _conn} = result
|
||||
end
|
||||
end
|
||||
|
||||
describe "Reset link" do
|
||||
setup do
|
||||
%{user: user_fixture()}
|
||||
end
|
||||
|
||||
test "sends a new reset password token", %{conn: conn, user: user} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/reset_password")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> form("#reset_password_form", user: %{"email" => user.email})
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, "/")
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system"
|
||||
|
||||
assert Repo.get_by!(Accounts.UserToken, user_id: user.id).context ==
|
||||
"reset_password"
|
||||
end
|
||||
|
||||
test "does not send reset password token if email is invalid", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/reset_password")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> form("#reset_password_form", user: %{"email" => "unknown@example.com"})
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, "/")
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "If your email is in our system"
|
||||
assert Repo.all(Accounts.UserToken) == []
|
||||
end
|
||||
end
|
||||
end
|
87
test/something_erlang_web/live/user_login_live_test.exs
Normal file
87
test/something_erlang_web/live/user_login_live_test.exs
Normal file
@ -0,0 +1,87 @@
|
||||
defmodule SomethingErlangWeb.UserLoginLiveTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
describe "Log in page" do
|
||||
test "renders log in page", %{conn: conn} do
|
||||
{:ok, _lv, html} = live(conn, ~p"/users/log_in")
|
||||
|
||||
assert html =~ "Log in"
|
||||
assert html =~ "Register"
|
||||
assert html =~ "Forgot your password?"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn} do
|
||||
result =
|
||||
conn
|
||||
|> log_in_user(user_fixture())
|
||||
|> live(~p"/users/log_in")
|
||||
|> follow_redirect(conn, "/")
|
||||
|
||||
assert {:ok, _conn} = result
|
||||
end
|
||||
end
|
||||
|
||||
describe "user login" do
|
||||
test "redirects if user login with valid credentials", %{conn: conn} do
|
||||
password = "123456789abcd"
|
||||
user = user_fixture(%{password: password})
|
||||
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
|
||||
|
||||
form =
|
||||
form(lv, "#login_form", user: %{email: user.email, password: password, remember_me: true})
|
||||
|
||||
conn = submit_form(form, conn)
|
||||
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
end
|
||||
|
||||
test "redirects to login page with a flash error if there are no valid credentials", %{
|
||||
conn: conn
|
||||
} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
|
||||
|
||||
form =
|
||||
form(lv, "#login_form",
|
||||
user: %{email: "test@email.com", password: "123456", remember_me: true}
|
||||
)
|
||||
|
||||
conn = submit_form(form, conn)
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :error) == "Invalid email or password"
|
||||
|
||||
assert redirected_to(conn) == "/users/log_in"
|
||||
end
|
||||
end
|
||||
|
||||
describe "login navigation" do
|
||||
test "redirects to registration page when the Register button is clicked", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
|
||||
|
||||
{:ok, _login_live, login_html} =
|
||||
lv
|
||||
|> element(~s|a:fl-contains("Sign up")|)
|
||||
|> render_click()
|
||||
|> follow_redirect(conn, ~p"/users/register")
|
||||
|
||||
assert login_html =~ "Register"
|
||||
end
|
||||
|
||||
test "redirects to forgot password page when the Forgot Password button is clicked", %{
|
||||
conn: conn
|
||||
} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/log_in")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> element(~s{a:fl-contains('Forgot your password?')})
|
||||
|> render_click()
|
||||
|> follow_redirect(conn, ~p"/users/reset_password")
|
||||
|
||||
assert conn.resp_body =~ "Forgot your password?"
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,87 @@
|
||||
defmodule SomethingErlangWeb.UserRegistrationLiveTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
describe "Registration page" do
|
||||
test "renders registration page", %{conn: conn} do
|
||||
{:ok, _lv, html} = live(conn, ~p"/users/register")
|
||||
|
||||
assert html =~ "Register"
|
||||
assert html =~ "Log in"
|
||||
end
|
||||
|
||||
test "redirects if already logged in", %{conn: conn} do
|
||||
result =
|
||||
conn
|
||||
|> log_in_user(user_fixture())
|
||||
|> live(~p"/users/register")
|
||||
|> follow_redirect(conn, "/")
|
||||
|
||||
assert {:ok, _conn} = result
|
||||
end
|
||||
|
||||
test "renders errors for invalid data", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/register")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> element("#registration_form")
|
||||
|> render_change(user: %{"email" => "with spaces", "password" => "too short"})
|
||||
|
||||
assert result =~ "Register"
|
||||
assert result =~ "must have the @ sign and no spaces"
|
||||
assert result =~ "should be at least 12 character"
|
||||
end
|
||||
end
|
||||
|
||||
describe "register user" do
|
||||
test "creates account and logs the user in", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/register")
|
||||
|
||||
email = unique_user_email()
|
||||
form = form(lv, "#registration_form", user: valid_user_attributes(email: email))
|
||||
render_submit(form)
|
||||
conn = follow_trigger_action(form, conn)
|
||||
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
|
||||
# Now do a logged in request and assert on the menu
|
||||
conn = get(conn, "/")
|
||||
response = html_response(conn, 200)
|
||||
assert response =~ email
|
||||
assert response =~ "Settings"
|
||||
assert response =~ "Log out"
|
||||
end
|
||||
|
||||
test "renders errors for duplicated email", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/register")
|
||||
|
||||
user = user_fixture(%{email: "test@email.com"})
|
||||
|
||||
result =
|
||||
lv
|
||||
|> form("#registration_form",
|
||||
user: %{"email" => user.email, "password" => "valid_password"}
|
||||
)
|
||||
|> render_submit()
|
||||
|
||||
assert result =~ "has already been taken"
|
||||
end
|
||||
end
|
||||
|
||||
describe "registration navigation" do
|
||||
test "redirects to login page when the Log in button is clicked", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/register")
|
||||
|
||||
{:ok, _login_live, login_html} =
|
||||
lv
|
||||
|> element(~s|main a:fl-contains("Sign in")|)
|
||||
|> render_click()
|
||||
|> follow_redirect(conn, ~p"/users/log_in")
|
||||
|
||||
assert login_html =~ "Log in"
|
||||
end
|
||||
end
|
||||
end
|
118
test/something_erlang_web/live/user_reset_password_live_test.exs
Normal file
118
test/something_erlang_web/live/user_reset_password_live_test.exs
Normal file
@ -0,0 +1,118 @@
|
||||
defmodule SomethingErlangWeb.UserResetPasswordLiveTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
alias SomethingErlang.Accounts
|
||||
|
||||
setup do
|
||||
user = user_fixture()
|
||||
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_user_reset_password_instructions(user, url)
|
||||
end)
|
||||
|
||||
%{token: token, user: user}
|
||||
end
|
||||
|
||||
describe "Reset password page" do
|
||||
test "renders reset password with valid token", %{conn: conn, token: token} do
|
||||
{:ok, _lv, html} = live(conn, ~p"/users/reset_password/#{token}")
|
||||
|
||||
assert html =~ "Reset Password"
|
||||
end
|
||||
|
||||
test "does not render reset password with invalid token", %{conn: conn} do
|
||||
{:error, {:redirect, to}} = live(conn, ~p"/users/reset_password/invalid")
|
||||
|
||||
assert to == %{
|
||||
flash: %{"error" => "Reset password link is invalid or it has expired."},
|
||||
to: ~p"/"
|
||||
}
|
||||
end
|
||||
|
||||
test "renders errors for invalid data", %{conn: conn, token: token} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/reset_password/#{token}")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> element("#reset_password_form")
|
||||
|> render_change(
|
||||
user: %{"password" => "secret12", "confirmation_password" => "secret123456"}
|
||||
)
|
||||
|
||||
assert result =~ "should be at least 12 character"
|
||||
assert result =~ "does not match password"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Reset Password" do
|
||||
test "resets password once", %{conn: conn, token: token, user: user} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/reset_password/#{token}")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> form("#reset_password_form",
|
||||
user: %{
|
||||
"password" => "new valid password",
|
||||
"password_confirmation" => "new valid password"
|
||||
}
|
||||
)
|
||||
|> render_submit()
|
||||
|> follow_redirect(conn, ~p"/users/log_in")
|
||||
|
||||
refute get_session(conn, :user_token)
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :info) =~ "Password reset successfully"
|
||||
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||
end
|
||||
|
||||
test "does not reset password on invalid data", %{conn: conn, token: token} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/reset_password/#{token}")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> form("#reset_password_form",
|
||||
user: %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
}
|
||||
)
|
||||
|> render_submit()
|
||||
|
||||
assert result =~ "Reset Password"
|
||||
assert result =~ "should be at least 12 character(s)"
|
||||
assert result =~ "does not match password"
|
||||
end
|
||||
end
|
||||
|
||||
describe "Reset password navigation" do
|
||||
test "redirects to login page when the Log in button is clicked", %{conn: conn, token: token} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/reset_password/#{token}")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> element(~s|main a:fl-contains("Log in")|)
|
||||
|> render_click()
|
||||
|> follow_redirect(conn, ~p"/users/log_in")
|
||||
|
||||
assert conn.resp_body =~ "Log in"
|
||||
end
|
||||
|
||||
test "redirects to password reset page when the Register button is clicked", %{
|
||||
conn: conn,
|
||||
token: token
|
||||
} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/reset_password/#{token}")
|
||||
|
||||
{:ok, conn} =
|
||||
lv
|
||||
|> element(~s|main a:fl-contains("Register")|)
|
||||
|> render_click()
|
||||
|> follow_redirect(conn, ~p"/users/register")
|
||||
|
||||
assert conn.resp_body =~ "Register"
|
||||
end
|
||||
end
|
||||
end
|
210
test/something_erlang_web/live/user_settings_live_test.exs
Normal file
210
test/something_erlang_web/live/user_settings_live_test.exs
Normal file
@ -0,0 +1,210 @@
|
||||
defmodule SomethingErlangWeb.UserSettingsLiveTest do
|
||||
use SomethingErlangWeb.ConnCase
|
||||
|
||||
alias SomethingErlang.Accounts
|
||||
import Phoenix.LiveViewTest
|
||||
import SomethingErlang.AccountsFixtures
|
||||
|
||||
describe "Settings page" do
|
||||
test "renders settings page", %{conn: conn} do
|
||||
{:ok, _lv, html} =
|
||||
conn
|
||||
|> log_in_user(user_fixture())
|
||||
|> live(~p"/users/settings")
|
||||
|
||||
assert html =~ "Change Email"
|
||||
assert html =~ "Change Password"
|
||||
end
|
||||
|
||||
test "redirects if user is not logged in", %{conn: conn} do
|
||||
assert {:error, redirect} = live(conn, ~p"/users/settings")
|
||||
|
||||
assert {:redirect, %{to: path, flash: flash}} = redirect
|
||||
assert path == ~p"/users/log_in"
|
||||
assert %{"error" => "You must log in to access this page."} = flash
|
||||
end
|
||||
end
|
||||
|
||||
describe "update email form" do
|
||||
setup %{conn: conn} do
|
||||
password = valid_user_password()
|
||||
user = user_fixture(%{password: password})
|
||||
%{conn: log_in_user(conn, user), user: user, password: password}
|
||||
end
|
||||
|
||||
test "updates the user email", %{conn: conn, password: password, user: user} do
|
||||
new_email = unique_user_email()
|
||||
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/settings")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> form("#email_form", %{
|
||||
"current_password" => password,
|
||||
"user" => %{"email" => new_email}
|
||||
})
|
||||
|> render_submit()
|
||||
|
||||
assert result =~ "A link to confirm your email"
|
||||
assert Accounts.get_user_by_email(user.email)
|
||||
end
|
||||
|
||||
test "renders errors with invalid data (phx-change)", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/settings")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> element("#email_form")
|
||||
|> render_change(%{
|
||||
"action" => "update_email",
|
||||
"current_password" => "invalid",
|
||||
"user" => %{"email" => "with spaces"}
|
||||
})
|
||||
|
||||
assert result =~ "Change Email"
|
||||
assert result =~ "must have the @ sign and no spaces"
|
||||
end
|
||||
|
||||
test "renders errors with invalid data (phx-submit)", %{conn: conn, user: user} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/settings")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> form("#email_form", %{
|
||||
"current_password" => "invalid",
|
||||
"user" => %{"email" => user.email}
|
||||
})
|
||||
|> render_submit()
|
||||
|
||||
assert result =~ "Change Email"
|
||||
assert result =~ "did not change"
|
||||
assert result =~ "is not valid"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update password form" do
|
||||
setup %{conn: conn} do
|
||||
password = valid_user_password()
|
||||
user = user_fixture(%{password: password})
|
||||
%{conn: log_in_user(conn, user), user: user, password: password}
|
||||
end
|
||||
|
||||
test "updates the user password", %{conn: conn, user: user, password: password} do
|
||||
new_password = valid_user_password()
|
||||
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/settings")
|
||||
|
||||
form =
|
||||
form(lv, "#password_form", %{
|
||||
"current_password" => password,
|
||||
"user" => %{
|
||||
"email" => user.email,
|
||||
"password" => new_password,
|
||||
"password_confirmation" => new_password
|
||||
}
|
||||
})
|
||||
|
||||
render_submit(form)
|
||||
|
||||
new_password_conn = follow_trigger_action(form, conn)
|
||||
|
||||
assert redirected_to(new_password_conn) == ~p"/users/settings"
|
||||
|
||||
assert get_session(new_password_conn, :user_token) != get_session(conn, :user_token)
|
||||
|
||||
assert Phoenix.Flash.get(new_password_conn.assigns.flash, :info) =~
|
||||
"Password updated successfully"
|
||||
|
||||
assert Accounts.get_user_by_email_and_password(user.email, new_password)
|
||||
end
|
||||
|
||||
test "renders errors with invalid data (phx-change)", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/settings")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> element("#password_form")
|
||||
|> render_change(%{
|
||||
"current_password" => "invalid",
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
}
|
||||
})
|
||||
|
||||
assert result =~ "Change Password"
|
||||
assert result =~ "should be at least 12 character(s)"
|
||||
assert result =~ "does not match password"
|
||||
end
|
||||
|
||||
test "renders errors with invalid data (phx-submit)", %{conn: conn} do
|
||||
{:ok, lv, _html} = live(conn, ~p"/users/settings")
|
||||
|
||||
result =
|
||||
lv
|
||||
|> form("#password_form", %{
|
||||
"current_password" => "invalid",
|
||||
"user" => %{
|
||||
"password" => "too short",
|
||||
"password_confirmation" => "does not match"
|
||||
}
|
||||
})
|
||||
|> render_submit()
|
||||
|
||||
assert result =~ "Change Password"
|
||||
assert result =~ "should be at least 12 character(s)"
|
||||
assert result =~ "does not match password"
|
||||
assert result =~ "is not valid"
|
||||
end
|
||||
end
|
||||
|
||||
describe "confirm email" do
|
||||
setup %{conn: conn} do
|
||||
user = user_fixture()
|
||||
email = unique_user_email()
|
||||
|
||||
token =
|
||||
extract_user_token(fn url ->
|
||||
Accounts.deliver_user_update_email_instructions(%{user | email: email}, user.email, url)
|
||||
end)
|
||||
|
||||
%{conn: log_in_user(conn, user), token: token, email: email, user: user}
|
||||
end
|
||||
|
||||
test "updates the user email once", %{conn: conn, user: user, token: token, email: email} do
|
||||
{:error, redirect} = live(conn, ~p"/users/settings/confirm_email/#{token}")
|
||||
|
||||
assert {:live_redirect, %{to: path, flash: flash}} = redirect
|
||||
assert path == ~p"/users/settings"
|
||||
assert %{"info" => message} = flash
|
||||
assert message == "Email changed successfully."
|
||||
refute Accounts.get_user_by_email(user.email)
|
||||
assert Accounts.get_user_by_email(email)
|
||||
|
||||
# use confirm token again
|
||||
{:error, redirect} = live(conn, ~p"/users/settings/confirm_email/#{token}")
|
||||
assert {:live_redirect, %{to: path, flash: flash}} = redirect
|
||||
assert path == ~p"/users/settings"
|
||||
assert %{"error" => message} = flash
|
||||
assert message == "Email change link is invalid or it has expired."
|
||||
end
|
||||
|
||||
test "does not update email with invalid token", %{conn: conn, user: user} do
|
||||
{:error, redirect} = live(conn, ~p"/users/settings/confirm_email/oops")
|
||||
assert {:live_redirect, %{to: path, flash: flash}} = redirect
|
||||
assert path == ~p"/users/settings"
|
||||
assert %{"error" => message} = flash
|
||||
assert message == "Email change link is invalid or it has expired."
|
||||
assert Accounts.get_user_by_email(user.email)
|
||||
end
|
||||
|
||||
test "redirects if user is not logged in", %{token: token} do
|
||||
conn = build_conn()
|
||||
{:error, redirect} = live(conn, ~p"/users/settings/confirm_email/#{token}")
|
||||
assert {:redirect, %{to: path, flash: flash}} = redirect
|
||||
assert path == ~p"/users/log_in"
|
||||
assert %{"error" => message} = flash
|
||||
assert message == "You must log in to access this page."
|
||||
end
|
||||
end
|
||||
end
|
@ -1,6 +1,7 @@
|
||||
defmodule SomethingErlangWeb.UserAuthTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
alias Phoenix.LiveView
|
||||
alias SomethingErlang.Accounts
|
||||
alias SomethingErlangWeb.UserAuth
|
||||
import SomethingErlang.AccountsFixtures
|
||||
@ -21,7 +22,7 @@ defmodule SomethingErlangWeb.UserAuthTest do
|
||||
conn = UserAuth.log_in_user(conn, user)
|
||||
assert token = get_session(conn, :user_token)
|
||||
assert get_session(conn, :live_socket_id) == "users_sessions:#{Base.url_encode64(token)}"
|
||||
assert redirected_to(conn) == "/"
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
assert Accounts.get_user_by_session_token(token)
|
||||
end
|
||||
|
||||
@ -59,7 +60,7 @@ defmodule SomethingErlangWeb.UserAuthTest do
|
||||
refute get_session(conn, :user_token)
|
||||
refute conn.cookies[@remember_me_cookie]
|
||||
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
|
||||
assert redirected_to(conn) == "/"
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
refute Accounts.get_user_by_session_token(user_token)
|
||||
end
|
||||
|
||||
@ -78,7 +79,7 @@ defmodule SomethingErlangWeb.UserAuthTest do
|
||||
conn = conn |> fetch_cookies() |> UserAuth.log_out_user()
|
||||
refute get_session(conn, :user_token)
|
||||
assert %{max_age: 0} = conn.resp_cookies[@remember_me_cookie]
|
||||
assert redirected_to(conn) == "/"
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
end
|
||||
end
|
||||
|
||||
@ -101,8 +102,11 @@ defmodule SomethingErlangWeb.UserAuthTest do
|
||||
|> put_req_cookie(@remember_me_cookie, signed_token)
|
||||
|> UserAuth.fetch_current_user([])
|
||||
|
||||
assert get_session(conn, :user_token) == user_token
|
||||
assert conn.assigns.current_user.id == user.id
|
||||
assert get_session(conn, :user_token) == user_token
|
||||
|
||||
assert get_session(conn, :live_socket_id) ==
|
||||
"users_sessions:#{Base.url_encode64(user_token)}"
|
||||
end
|
||||
|
||||
test "does not authenticate if data is missing", %{conn: conn, user: user} do
|
||||
@ -113,11 +117,106 @@ defmodule SomethingErlangWeb.UserAuthTest do
|
||||
end
|
||||
end
|
||||
|
||||
describe "on_mount: mount_current_user" do
|
||||
test "assigns current_user based on a valid user_token ", %{conn: conn, user: user} do
|
||||
user_token = Accounts.generate_user_session_token(user)
|
||||
session = conn |> put_session(:user_token, user_token) |> get_session()
|
||||
|
||||
{:cont, updated_socket} =
|
||||
UserAuth.on_mount(:mount_current_user, %{}, session, %LiveView.Socket{})
|
||||
|
||||
assert updated_socket.assigns.current_user.id == user.id
|
||||
end
|
||||
|
||||
test "assigns nil to current_user assign if there isn't a valid user_token ", %{conn: conn} do
|
||||
user_token = "invalid_token"
|
||||
session = conn |> put_session(:user_token, user_token) |> get_session()
|
||||
|
||||
{:cont, updated_socket} =
|
||||
UserAuth.on_mount(:mount_current_user, %{}, session, %LiveView.Socket{})
|
||||
|
||||
assert updated_socket.assigns.current_user == nil
|
||||
end
|
||||
|
||||
test "assigns nil to current_user assign if there isn't a user_token", %{conn: conn} do
|
||||
session = conn |> get_session()
|
||||
|
||||
{:cont, updated_socket} =
|
||||
UserAuth.on_mount(:mount_current_user, %{}, session, %LiveView.Socket{})
|
||||
|
||||
assert updated_socket.assigns.current_user == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "on_mount: ensure_authenticated" do
|
||||
test "authenticates current_user based on a valid user_token ", %{conn: conn, user: user} do
|
||||
user_token = Accounts.generate_user_session_token(user)
|
||||
session = conn |> put_session(:user_token, user_token) |> get_session()
|
||||
|
||||
{:cont, updated_socket} =
|
||||
UserAuth.on_mount(:ensure_authenticated, %{}, session, %LiveView.Socket{})
|
||||
|
||||
assert updated_socket.assigns.current_user.id == user.id
|
||||
end
|
||||
|
||||
test "redirects to login page if there isn't a valid user_token ", %{conn: conn} do
|
||||
user_token = "invalid_token"
|
||||
session = conn |> put_session(:user_token, user_token) |> get_session()
|
||||
|
||||
socket = %LiveView.Socket{
|
||||
endpoint: SomethingErlangWeb.Endpoint,
|
||||
assigns: %{__changed__: %{}, flash: %{}}
|
||||
}
|
||||
|
||||
{:halt, updated_socket} = UserAuth.on_mount(:ensure_authenticated, %{}, session, socket)
|
||||
assert updated_socket.assigns.current_user == nil
|
||||
end
|
||||
|
||||
test "redirects to login page if there isn't a user_token ", %{conn: conn} do
|
||||
session = conn |> get_session()
|
||||
|
||||
socket = %LiveView.Socket{
|
||||
endpoint: SomethingErlangWeb.Endpoint,
|
||||
assigns: %{__changed__: %{}, flash: %{}}
|
||||
}
|
||||
|
||||
{:halt, updated_socket} = UserAuth.on_mount(:ensure_authenticated, %{}, session, socket)
|
||||
assert updated_socket.assigns.current_user == nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "on_mount: :redirect_if_user_is_authenticated" do
|
||||
test "redirects if there is an authenticated user ", %{conn: conn, user: user} do
|
||||
user_token = Accounts.generate_user_session_token(user)
|
||||
session = conn |> put_session(:user_token, user_token) |> get_session()
|
||||
|
||||
assert {:halt, _updated_socket} =
|
||||
UserAuth.on_mount(
|
||||
:redirect_if_user_is_authenticated,
|
||||
%{},
|
||||
session,
|
||||
%LiveView.Socket{}
|
||||
)
|
||||
end
|
||||
|
||||
test "Don't redirect is there is no authenticated user", %{conn: conn} do
|
||||
session = conn |> get_session()
|
||||
|
||||
assert {:cont, _updated_socket} =
|
||||
UserAuth.on_mount(
|
||||
:redirect_if_user_is_authenticated,
|
||||
%{},
|
||||
session,
|
||||
%LiveView.Socket{}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "redirect_if_user_is_authenticated/2" do
|
||||
test "redirects if user is authenticated", %{conn: conn, user: user} do
|
||||
conn = conn |> assign(:current_user, user) |> UserAuth.redirect_if_user_is_authenticated([])
|
||||
assert conn.halted
|
||||
assert redirected_to(conn) == "/"
|
||||
assert redirected_to(conn) == ~p"/"
|
||||
end
|
||||
|
||||
test "does not redirect if user is not authenticated", %{conn: conn} do
|
||||
@ -131,8 +230,11 @@ defmodule SomethingErlangWeb.UserAuthTest do
|
||||
test "redirects if user is not authenticated", %{conn: conn} do
|
||||
conn = conn |> fetch_flash() |> UserAuth.require_authenticated_user([])
|
||||
assert conn.halted
|
||||
assert redirected_to(conn) == Routes.user_session_path(conn, :new)
|
||||
assert get_flash(conn, :error) == "You must log in to access this page."
|
||||
|
||||
assert redirected_to(conn) == ~p"/users/log_in"
|
||||
|
||||
assert Phoenix.Flash.get(conn.assigns.flash, :error) ==
|
||||
"You must log in to access this page."
|
||||
end
|
||||
|
||||
test "stores the path to redirect to on GET", %{conn: conn} do
|
@ -1,15 +0,0 @@
|
||||
defmodule SomethingErlangWeb.ErrorViewTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
# Bring render/3 and render_to_string/3 for testing custom views
|
||||
import Phoenix.View
|
||||
|
||||
test "renders 404.html" do
|
||||
assert render_to_string(SomethingErlangWeb.ErrorView, "404.html", []) == "Not Found"
|
||||
end
|
||||
|
||||
test "renders 500.html" do
|
||||
assert render_to_string(SomethingErlangWeb.ErrorView, "500.html", []) ==
|
||||
"Internal Server Error"
|
||||
end
|
||||
end
|
@ -1,8 +0,0 @@
|
||||
defmodule SomethingErlangWeb.LayoutViewTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
|
||||
# When testing helpers, you may want to import Phoenix.HTML and
|
||||
# use functions such as safe_to_string() to convert the helper
|
||||
# result into an HTML string.
|
||||
# import Phoenix.HTML
|
||||
end
|
@ -1,3 +0,0 @@
|
||||
defmodule SomethingErlangWeb.PageViewTest do
|
||||
use SomethingErlangWeb.ConnCase, async: true
|
||||
end
|
@ -19,15 +19,15 @@ defmodule SomethingErlangWeb.ConnCase do
|
||||
|
||||
using do
|
||||
quote do
|
||||
# The default endpoint for testing
|
||||
@endpoint SomethingErlangWeb.Endpoint
|
||||
|
||||
use SomethingErlangWeb, :verified_routes
|
||||
|
||||
# Import conveniences for testing with connections
|
||||
import Plug.Conn
|
||||
import Phoenix.ConnTest
|
||||
import SomethingErlangWeb.ConnCase
|
||||
|
||||
alias SomethingErlangWeb.Router.Helpers, as: Routes
|
||||
|
||||
# The default endpoint for testing
|
||||
@endpoint SomethingErlangWeb.Endpoint
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -1,21 +0,0 @@
|
||||
defmodule SomethingErlang.ForumsFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `SomethingErlang.Forums` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a thread.
|
||||
"""
|
||||
def thread_fixture(attrs \\ %{}) do
|
||||
{:ok, thread} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
thread_id: 42,
|
||||
title: "some title"
|
||||
})
|
||||
|> SomethingErlang.Forums.create_thread()
|
||||
|
||||
thread
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user