chessh/test/auth/password_test.exs

37 lines
996 B
Elixir
Raw Normal View History

2022-12-19 22:45:01 -05:00
defmodule Chessh.Auth.PasswordAuthenticatorTest do
use ExUnit.Case
2022-12-28 01:50:22 -05:00
alias Chessh.{Player, Repo}
2022-12-19 22:45:01 -05:00
@valid_user %{username: "lizzy#0003", password: "password", discord_id: "1"}
2022-12-19 22:45:01 -05:00
2022-12-28 01:50:22 -05:00
setup_all do
2022-12-29 19:49:42 -05:00
Ecto.Adapters.SQL.Sandbox.checkout(Repo)
Ecto.Adapters.SQL.Sandbox.mode(Repo, {:shared, self()})
2022-12-19 22:45:01 -05:00
2022-12-30 07:46:35 -05:00
{:ok, _player} = Repo.insert(Player.registration_changeset(%Player{}, @valid_user))
2022-12-19 22:45:01 -05:00
:ok
end
2022-12-28 01:50:22 -05:00
test "Password can authenticate a hashed password" do
2022-12-19 22:45:01 -05:00
assert Chessh.Auth.PasswordAuthenticator.authenticate(
2022-12-29 19:21:20 -05:00
@valid_user.username,
@valid_user.password
2022-12-19 22:45:01 -05:00
)
refute Chessh.Auth.PasswordAuthenticator.authenticate(
2022-12-29 19:21:20 -05:00
@valid_user.username,
"a_bad_password"
2022-12-19 22:45:01 -05:00
)
end
2022-12-30 07:46:35 -05:00
test "Password can authenticate a user instance" do
player = Repo.get_by(Player, username: "lizzy#0003")
2022-12-30 07:46:35 -05:00
assert Chessh.Auth.PasswordAuthenticator.authenticate(
player,
@valid_user.password
)
end
2022-12-19 22:45:01 -05:00
end