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" secret_key: "vd2vXkrYTTFKSKmNMoS2/Hk4Fxn8BkyzsVArRkxJazdQ3mr6bI4YgAC6f8ODiWlM"
config :formulator, config :formulator,
validate: false,
translate_error_module: ChessWeb.ErrorHelpers translate_error_module: ChessWeb.ErrorHelpers
# Configure esbuild (the version is required) # Configure esbuild (the version is required)

View File

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

View File

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

View File

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