mirror of
https://framagit.org/framasoft/mobilizon.git
synced 2024-12-23 00:14:48 +00:00
9a080c1f10
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
29 lines
1.1 KiB
Elixir
29 lines
1.1 KiB
Elixir
defmodule Mobilizon.Service.Auth.MobilizonAuthenticatorTest do
|
|
use Mobilizon.DataCase
|
|
|
|
alias Mobilizon.Service.Auth.MobilizonAuthenticator
|
|
alias Mobilizon.Users.User
|
|
import Mobilizon.Factory
|
|
|
|
setup do
|
|
password = "testpassword"
|
|
email = "someone@somewhere.tld"
|
|
user = insert(:user, email: email, password_hash: Argon2.hash_pwd_salt(password))
|
|
{:ok, [user: user, email: email, password: password]}
|
|
end
|
|
|
|
test "login", %{email: email, password: password, user: user} do
|
|
assert {:ok, %User{} = returned_user} = MobilizonAuthenticator.login(email, password)
|
|
assert returned_user.id == user.id
|
|
end
|
|
|
|
test "login with invalid password", %{email: email} do
|
|
assert {:error, :bad_password} == MobilizonAuthenticator.login(email, "invalid")
|
|
assert {:error, :bad_password} == MobilizonAuthenticator.login(email, nil)
|
|
end
|
|
|
|
test "login with no credentials" do
|
|
assert {:error, :user_not_found} == MobilizonAuthenticator.login("some@email.com", nil)
|
|
assert {:error, :user_not_found} == MobilizonAuthenticator.login(nil, nil)
|
|
end
|
|
end
|