1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Fix tests

This commit is contained in:
Daniel Barber 2023-02-04 21:33:48 -06:00
parent 01471967c8
commit 69f05a1c5d
4 changed files with 24 additions and 25 deletions

View File

@ -30,6 +30,7 @@ config :chess, Chess.Auth.Guardian,
secret_key: "vd2vXkrYTTFKSKmNMoS2/Hk4Fxn8BkyzsVArRkxJazdQ3mr6bI4YgAC6f8ODiWlM"
config :formulator,
validate: false,
translate_error_module: ChessWeb.ErrorHelpers
# Configure esbuild (the version is required)

View File

@ -76,6 +76,7 @@ defmodule Chess.Store.User do
if password do
changeset
|> change(Argon2.add_hash(password))
|> change(password: nil)
else
changeset
end

View File

@ -76,15 +76,13 @@ defmodule Chess.AuthTest do
test "authenticate_user/1 returns false on incorrect password " do
user_fixture(email: "link@hyrule.com", password: "eyeofsheikah")
assert {:error, message} =
Auth.authenticate_user("link@hyrule.com", "shadowtemple")
assert {:error, message} = Auth.authenticate_user("link@hyrule.com", "shadowtemple")
assert message == "invalid password"
end
test "authenticate_user/1 returns true on correct password " do
user = user_fixture(email: "link@hyrule.com", password: "eyeofsheikah")
assert {:ok, ^user} =
Auth.authenticate_user("link@hyrule.com", "eyeofsheikah")
assert {:ok, ^user} = Auth.authenticate_user("link@hyrule.com", "eyeofsheikah")
end
end
end

View File

@ -7,11 +7,12 @@ defmodule Chess.Features.ProfileTest do
import Chess.AuthenticationHelpers
test "user can update their details", %{session: session} do
user = insert(:user, %{
name: "Link",
email: "link@hyrule.com",
password: "ilovezelda"
})
user =
insert(:user, %{
name: "Link",
email: "link@hyrule.com",
password: "ilovezelda"
})
session
|> login(user.email, "ilovezelda")
@ -25,11 +26,12 @@ defmodule Chess.Features.ProfileTest do
end
test "name cannot be blank", %{session: session} do
user = insert(:user, %{
name: "Link",
email: "link@hyrule.com",
password: "ilovezelda"
})
user =
insert(:user, %{
name: "Link",
email: "link@hyrule.com",
password: "ilovezelda"
})
session
|> login(user.email, "ilovezelda")
@ -40,17 +42,16 @@ defmodule Chess.Features.ProfileTest do
|> click(button("Update Profile"))
session
|> assert_has(
css("[data-role='name-error']", text: "can't be blank")
)
|> assert_has(css("[data-role='name-error']", text: "can't be blank"))
end
test "email cannot be blank", %{session: session} do
user = insert(:user, %{
name: "Link",
email: "link@hyrule.com",
password: "ilovezelda"
})
user =
insert(:user, %{
name: "Link",
email: "link@hyrule.com",
password: "ilovezelda"
})
session
|> login(user.email, "ilovezelda")
@ -61,8 +62,6 @@ defmodule Chess.Features.ProfileTest do
|> click(button("Update Profile"))
session
|> assert_has(
css("[data-role='email-error']", text: "can't be blank")
)
|> assert_has(css("[data-role='email-error']", text: "can't be blank"))
end
end