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