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