initial work on fixing user tests
This commit is contained in:
parent
6598455c39
commit
77f3dc4614
|
@ -5,32 +5,32 @@ defmodule PokemonCouture.AccountsTest do
|
|||
import PokemonCouture.AccountsFixtures
|
||||
alias PokemonCouture.Accounts.{User, UserToken}
|
||||
|
||||
describe "get_user_by_email/1" do
|
||||
test "does not return the user if the email does not exist" do
|
||||
refute Accounts.get_user_by_email("unknown@example.com")
|
||||
describe "get_user_by_username/1" do
|
||||
test "does not return the user if the username does not exist" do
|
||||
refute Accounts.get_user_by_username("unknown@example.com")
|
||||
end
|
||||
|
||||
test "returns the user if the email exists" do
|
||||
test "returns the user if the username exists" do
|
||||
%{id: id} = user = user_fixture()
|
||||
assert %User{id: ^id} = Accounts.get_user_by_email(user.email)
|
||||
assert %User{id: ^id} = Accounts.get_user_by_username(user.username)
|
||||
end
|
||||
end
|
||||
|
||||
describe "get_user_by_email_and_password/2" do
|
||||
test "does not return the user if the email does not exist" do
|
||||
refute Accounts.get_user_by_email_and_password("unknown@example.com", "hello world!")
|
||||
describe "get_user_by_username_and_password/2" do
|
||||
test "does not return the user if the username does not exist" do
|
||||
refute Accounts.get_user_by_username_and_password("unknown@example.com", "hello world!")
|
||||
end
|
||||
|
||||
test "does not return the user if the password is not valid" do
|
||||
user = user_fixture()
|
||||
refute Accounts.get_user_by_email_and_password(user.email, "invalid")
|
||||
refute Accounts.get_user_by_username_and_password(user.username, "invalid")
|
||||
end
|
||||
|
||||
test "returns the user if the email and password are valid" do
|
||||
test "returns the user if the username and password are valid" do
|
||||
%{id: id} = user = user_fixture()
|
||||
|
||||
assert %User{id: ^id} =
|
||||
Accounts.get_user_by_email_and_password(user.email, valid_user_password())
|
||||
Accounts.get_user_by_username_and_password(user.username, valid_user_password())
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -52,6 +52,7 @@ defmodule PokemonCouture.AccountsTest do
|
|||
{:error, changeset} = Accounts.register_user(%{})
|
||||
|
||||
assert %{
|
||||
username: ["can't be blank"],
|
||||
password: ["can't be blank"],
|
||||
email: ["can't be blank"]
|
||||
} = errors_on(changeset)
|
||||
|
@ -294,7 +295,7 @@ defmodule PokemonCouture.AccountsTest do
|
|||
})
|
||||
|
||||
assert is_nil(user.password)
|
||||
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||
assert Accounts.get_user_by_username_and_password(user.username, "new valid password")
|
||||
end
|
||||
|
||||
test "deletes all tokens for the given user", %{user: user} do
|
||||
|
@ -489,7 +490,7 @@ defmodule PokemonCouture.AccountsTest do
|
|||
test "updates the password", %{user: user} do
|
||||
{:ok, updated_user} = Accounts.reset_user_password(user, %{password: "new valid password"})
|
||||
assert is_nil(updated_user.password)
|
||||
assert Accounts.get_user_by_email_and_password(user.email, "new valid password")
|
||||
assert Accounts.get_user_by_username_and_password(user.username, "new valid password")
|
||||
end
|
||||
|
||||
test "deletes all tokens for the given user", %{user: user} do
|
||||
|
|
|
@ -86,7 +86,7 @@ defmodule PokemonCoutureWeb.UserResetPasswordControllerTest do
|
|||
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")
|
||||
assert Accounts.get_user_by_username_and_password(user.username, "new valid password")
|
||||
end
|
||||
|
||||
test "does not reset password on invalid data", %{conn: conn, token: token} do
|
||||
|
|
|
@ -35,7 +35,7 @@ defmodule PokemonCoutureWeb.UserSettingsControllerTest do
|
|||
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")
|
||||
assert Accounts.get_user_by_username_and_password(user.username, "new valid password")
|
||||
end
|
||||
|
||||
test "does not update password on invalid data", %{conn: conn} do
|
||||
|
|
|
@ -6,9 +6,11 @@ defmodule PokemonCouture.AccountsFixtures do
|
|||
|
||||
def unique_user_email, do: "user#{System.unique_integer()}@example.com"
|
||||
def valid_user_password, do: "hello world!"
|
||||
def unique_username, do: "user#{System.unique_integer()}"
|
||||
|
||||
def valid_user_attributes(attrs \\ %{}) do
|
||||
Enum.into(attrs, %{
|
||||
username: unique_username(),
|
||||
email: unique_user_email(),
|
||||
password: valid_user_password()
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue