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