Add factories for testing.
[akkoma] / test / support / factory.ex
1 defmodule Pleroma.Factory do
2 use ExMachina.Ecto, repo: Pleroma.Repo
3
4 def user_factory do
5 user = %Pleroma.User{
6 name: sequence(:name, &"Test User #{&1}"),
7 email: sequence(:email, &"user#{&1}@example.com"),
8 nickname: sequence(:nickname, &"nick#{&1}"),
9 password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
10 bio: sequence(:bio, &"Tester Number #{&1}"),
11 }
12 %{ user | ap_id: Pleroma.User.ap_id(user) }
13 end
14
15 def note_factory do
16 text = sequence(:text, &"This is note #{&1}")
17
18 user = insert(:user)
19 data = %{
20 "type" => "Note",
21 "content" => text,
22 "id" => Pleroma.Web.ActivityPub.ActivityPub.generate_object_id,
23 "actor" => user.ap_id,
24 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
25 "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
26 }
27
28 %Pleroma.Object{
29 data: data
30 }
31 end
32
33 def note_activity_factory do
34 note = insert(:note)
35 data = %{
36 "id" => Pleroma.Web.ActivityPub.ActivityPub.generate_activity_id,
37 "actor" => note.data["actor"],
38 "to" => note.data["to"],
39 "object" => note.data,
40 "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
41 }
42
43 %Pleroma.Activity{
44 data: data
45 }
46 end
47 end