honkoma/test/support/builders/user_builder.ex

31 lines
884 B
Elixir
Raw Normal View History

2022-02-26 06:11:42 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/>
2022-02-26 06:11:42 +00:00
# SPDX-License-Identifier: AGPL-3.0-only
2017-03-21 16:53:20 +00:00
defmodule Pleroma.Builders.UserBuilder do
2019-02-10 21:57:38 +00:00
alias Pleroma.Repo
alias Pleroma.User
2017-03-21 16:53:20 +00:00
2017-03-22 15:51:20 +00:00
def build(data \\ %{}) do
user = %User{
2017-03-21 16:53:20 +00:00
email: "test@example.org",
name: "Test Name",
nickname: "testname",
2021-01-14 14:06:16 +00:00
password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt("test"),
2017-03-21 16:53:20 +00:00
bio: "A tester.",
2019-04-19 16:26:41 +00:00
ap_id: "some id",
2019-10-28 09:47:23 +00:00
last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
multi_factor_authentication_settings: %Pleroma.MFA.Settings{},
2019-10-28 09:47:23 +00:00
notification_settings: %Pleroma.User.NotificationSetting{}
2017-03-21 16:53:20 +00:00
}
2018-03-30 13:01:53 +00:00
2017-03-22 15:51:20 +00:00
Map.merge(user, data)
2017-03-21 16:53:20 +00:00
end
2017-03-22 15:51:20 +00:00
def insert(data \\ %{}) do
2018-02-25 17:08:41 +00:00
{:ok, user} = Repo.insert(build(data))
User.invalidate_cache(user)
{:ok, user}
2017-03-21 16:53:20 +00:00
end
end