forked from pow-auth/pow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context_mock.ex
28 lines (20 loc) · 958 Bytes
/
context_mock.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
defmodule Pow.Test.ContextMock do
@moduledoc false
alias Pow.Test.Ecto.Users.User
use Pow.Ecto.Context
@valid_params %{"email" => "[email protected]", "password" => "secret"}
@user %User{id: 1, email: "[email protected]", password_hash: ""}
def authenticate(@valid_params), do: @user
def authenticate(_params), do: nil
def create(@valid_params), do: {:ok, @user}
def create(params), do: {:error, %{User.changeset(%User{}, params) | action: :insert}}
def update(%{id: 1}, @valid_params), do: {:ok, %{@user | id: :updated}}
def update(user, params), do: {:error, %{User.changeset(user, params) | action: :update}}
def delete(%{id: 1}), do: {:ok, %{@user | id: :deleted}}
def delete(_user), do: {:error, %{User.changeset(%User{}, %{}) | action: :delete}}
defmodule UsernameUser do
@moduledoc false
alias Pow.Test.Ecto.Users.UsernameUser
def create(_any), do: {:ok, %UsernameUser{id: 1, username: "test"}}
end
end