Add limiting to activity pub fetching.
[akkoma] / test / support / builders / activity_builder.ex
1 defmodule Pleroma.Builders.ActivityBuilder do
2 alias Pleroma.Builders.UserBuilder
3 alias Pleroma.Web.ActivityPub.ActivityPub
4
5 def build(data \\ %{}, opts \\ %{}) do
6 user = opts[:user] || UserBuilder.build
7 activity = %{
8 "id" => 1,
9 "actor" => user.ap_id,
10 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
11 "object" => %{
12 "type" => "Note",
13 "content" => "test"
14 }
15 }
16 Map.merge(activity, data)
17 end
18
19 def insert(data \\ %{}, opts \\ %{}) do
20 activity = build(data, opts)
21 ActivityPub.insert(activity)
22 end
23
24 def insert_list(times, data \\ %{}, opts \\ %{}) do
25 Enum.map(1..times, fn (n) ->
26 {:ok, activity} = insert(%{"id" => n})
27 activity
28 end)
29 end
30
31 def public_and_non_public do
32 {:ok, user} = UserBuilder.insert
33
34 public = build(%{"id" => 1}, %{user: user})
35 non_public = build(%{"id" => 2, "to" => []}, %{user: user})
36
37 {:ok, public} = ActivityPub.insert(public)
38 {:ok, non_public} = ActivityPub.insert(non_public)
39
40 %{
41 public: public,
42 non_public: non_public,
43 user: user
44 }
45 end
46 end