akkoma/test/support/builders/user_builder.ex
floatingghost 9be6caf125 argon2 password hashing (#406)
Co-authored-by: FloatingGhost <hannah@coffee-and-dreams.uk>
Reviewed-on: AkkomaGang/akkoma#406
2022-12-30 02:46:58 +00:00

26 lines
718 B
Elixir

defmodule Pleroma.Builders.UserBuilder do
alias Pleroma.Repo
alias Pleroma.User
def build(data \\ %{}) do
user = %User{
email: "test@example.org",
name: "Test Name",
nickname: "testname",
password_hash: Pleroma.Password.hash_pwd_salt("test"),
bio: "A tester.",
ap_id: "some id",
last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
multi_factor_authentication_settings: %Pleroma.MFA.Settings{},
notification_settings: %Pleroma.User.NotificationSetting{}
}
Map.merge(user, data)
end
def insert(data \\ %{}) do
{:ok, user} = Repo.insert(build(data))
User.invalidate_cache(user)
{:ok, user}
end
end