33bacd40cdab61c9c63c70c7ad99cc1f9415913d
[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), follower_address: Pleroma.User.ap_followers(user) }
13 end
14
15 def note_factory do
16 text = sequence(:text, &"This is :moominmamma: note #{&1}")
17
18 user = insert(:user)
19 data = %{
20 "type" => "Note",
21 "content" => text,
22 "id" => Pleroma.Web.ActivityPub.Utils.generate_object_id,
23 "actor" => user.ap_id,
24 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
25 "published" => DateTime.utc_now() |> DateTime.to_iso8601,
26 "likes" => [],
27 "like_count" => 0,
28 "context" => "2hu",
29 "tag" => ["2hu"],
30 "emoji" => %{
31 "2hu" => "corndog.png"
32 }
33 }
34
35 %Pleroma.Object{
36 data: data
37 }
38 end
39
40 def note_activity_factory do
41 note = insert(:note)
42 data = %{
43 "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
44 "type" => "Create",
45 "actor" => note.data["actor"],
46 "to" => note.data["to"],
47 "object" => note.data,
48 "published" => DateTime.utc_now() |> DateTime.to_iso8601,
49 "context" => note.data["context"]
50 }
51
52 %Pleroma.Activity{
53 data: data
54 }
55 end
56
57 def like_activity_factory do
58 note_activity = insert(:note_activity)
59 user = insert(:user)
60
61 data = %{
62 "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
63 "actor" => user.ap_id,
64 "type" => "Like",
65 "object" => note_activity.data["object"]["id"],
66 "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
67 }
68
69 %Pleroma.Activity{
70 data: data
71 }
72 end
73
74 def follow_activity_factory do
75 follower = insert(:user)
76 followed = insert(:user)
77
78 data = %{
79 "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
80 "actor" => follower.ap_id,
81 "type" => "Follow",
82 "object" => followed.ap_id,
83 "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
84 }
85
86 %Pleroma.Activity{
87 data: data
88 }
89 end
90
91 def websub_subscription_factory do
92 %Pleroma.Web.Websub.WebsubServerSubscription{
93 topic: "http://example.org",
94 callback: "http://example/org/callback",
95 secret: "here's a secret",
96 valid_until: NaiveDateTime.add(NaiveDateTime.utc_now, 100),
97 state: "requested"
98 }
99 end
100
101 def websub_client_subscription_factory do
102 %Pleroma.Web.Websub.WebsubClientSubscription{
103 topic: "http://example.org",
104 secret: "here's a secret",
105 valid_until: nil,
106 state: "requested",
107 subscribers: []
108 }
109 end
110 end