Pleroma/test/support/builders/user_builder.ex

26 lines
596 B
Elixir
Raw Normal View History

2017-03-21 17:53:20 +01:00
defmodule Pleroma.Builders.UserBuilder do
2019-02-10 22:57:38 +01:00
alias Pleroma.Repo
alias Pleroma.User
2017-03-21 17:53:20 +01:00
2017-03-22 16:51:20 +01:00
def build(data \\ %{}) do
user = %User{
2017-03-21 17:53:20 +01:00
email: "test@example.org",
name: "Test Name",
nickname: "testname",
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
bio: "A tester.",
2019-04-19 18:26:41 +02:00
ap_id: "some id",
last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
info: %{}
2017-03-21 17:53:20 +01:00
}
2018-03-30 15:01:53 +02:00
2017-03-22 16:51:20 +01:00
Map.merge(user, data)
2017-03-21 17:53:20 +01:00
end
2017-03-22 16:51:20 +01:00
def insert(data \\ %{}) do
2018-02-25 18:08:41 +01:00
{:ok, user} = Repo.insert(build(data))
User.invalidate_cache(user)
{:ok, user}
2017-03-21 17:53:20 +01:00
end
end