architex/test/support/factory.ex

25 lines
618 B
Elixir
Raw Permalink Normal View History

2021-09-01 12:43:55 +00:00
defmodule Architex.Factory do
use ExMachina.Ecto, repo: Architex.Repo
2021-07-13 15:08:07 +00:00
2021-09-01 12:43:55 +00:00
alias Architex.{Account, Device}
2021-07-13 15:08:07 +00:00
def account_factory do
%Account{
localpart: sequence(:localpart, &"account#{&1}"),
password_hash: Bcrypt.hash_pwd_salt("lemmein")
}
end
def device_factory do
%Account{localpart: localpart} = account = build(:account)
device_id = sequence(:device_id, &"device#{&1}")
%Device{
2021-09-04 14:40:17 +00:00
id: device_id,
2021-07-13 15:08:07 +00:00
access_token: Device.generate_access_token(localpart, device_id),
display_name: sequence(:display_name, &"Device #{&1}"),
account: account
}
end
end