MastoAPI: Add blocking to AccountView.
[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 "summary" => "2hu",
30 "tag" => ["2hu"],
31 "emoji" => %{
32 "2hu" => "corndog.png"
33 }
34 }
35
36 %Pleroma.Object{
37 data: data
38 }
39 end
40
41 def note_activity_factory do
42 note = insert(:note)
43 data = %{
44 "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
45 "type" => "Create",
46 "actor" => note.data["actor"],
47 "to" => note.data["to"],
48 "object" => note.data,
49 "published" => DateTime.utc_now() |> DateTime.to_iso8601,
50 "context" => note.data["context"]
51 }
52
53 %Pleroma.Activity{
54 data: data
55 }
56 end
57
58 def like_activity_factory do
59 note_activity = insert(:note_activity)
60 user = insert(:user)
61
62 data = %{
63 "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
64 "actor" => user.ap_id,
65 "type" => "Like",
66 "object" => note_activity.data["object"]["id"],
67 "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
68 }
69
70 %Pleroma.Activity{
71 data: data
72 }
73 end
74
75 def follow_activity_factory do
76 follower = insert(:user)
77 followed = insert(:user)
78
79 data = %{
80 "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id,
81 "actor" => follower.ap_id,
82 "type" => "Follow",
83 "object" => followed.ap_id,
84 "published_at" => DateTime.utc_now() |> DateTime.to_iso8601
85 }
86
87 %Pleroma.Activity{
88 data: data
89 }
90 end
91
92 def websub_subscription_factory do
93 %Pleroma.Web.Websub.WebsubServerSubscription{
94 topic: "http://example.org",
95 callback: "http://example/org/callback",
96 secret: "here's a secret",
97 valid_until: NaiveDateTime.add(NaiveDateTime.utc_now, 100),
98 state: "requested"
99 }
100 end
101
102 def websub_client_subscription_factory do
103 %Pleroma.Web.Websub.WebsubClientSubscription{
104 topic: "http://example.org",
105 secret: "here's a secret",
106 valid_until: nil,
107 state: "requested",
108 subscribers: []
109 }
110 end
111 end