GTS: cherry-picks and collection usage (#186)
[akkoma] / test / support / builders / user_builder.ex
1 defmodule Pleroma.Builders.UserBuilder do
2 alias Pleroma.Repo
3 alias Pleroma.User
4
5 def build(data \\ %{}) do
6 user = %User{
7 email: "test@example.org",
8 name: "Test Name",
9 nickname: "testname",
10 password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("test"),
11 bio: "A tester.",
12 ap_id: "some id",
13 last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
14 multi_factor_authentication_settings: %Pleroma.MFA.Settings{},
15 notification_settings: %Pleroma.User.NotificationSetting{}
16 }
17
18 Map.merge(user, data)
19 end
20
21 def insert(data \\ %{}) do
22 {:ok, user} = Repo.insert(build(data))
23 User.invalidate_cache(user)
24 {:ok, user}
25 end
26 end