2017-03-21 12:53:20 -04:00
|
|
|
defmodule Pleroma.Builders.UserBuilder do
|
|
|
|
alias Pleroma.{User, Repo}
|
|
|
|
|
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",
|
|
|
|
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
|
|
|
|
bio: "A tester.",
|
|
|
|
ap_id: "some id"
|
|
|
|
}
|
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
|