1 defmodule Akkoma.Collections.FetcherTest do
3 use Oban.Testing, repo: Pleroma.Repo
5 alias Akkoma.Collections.Fetcher
10 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
14 test "it should extract items from an embedded array in a Collection" do
15 unordered_collection =
16 "test/fixtures/collections/unordered_array.json"
19 ap_id = "https://example.com/collection/ordered_array"
28 body: unordered_collection,
29 headers: [{"content-type", "application/activity+json"}]
33 {:ok, objects} = Fetcher.fetch_collection(ap_id)
34 assert [%{"type" => "Create"}, %{"type" => "Like"}] = objects
37 test "it should extract items from an embedded array in an OrderedCollection" do
39 "test/fixtures/collections/ordered_array.json"
42 ap_id = "https://example.com/collection/ordered_array"
51 body: ordered_collection,
52 headers: [{"content-type", "application/activity+json"}]
56 {:ok, objects} = Fetcher.fetch_collection(ap_id)
57 assert [%{"type" => "Create"}, %{"type" => "Like"}] = objects
60 test "it should extract items from an referenced first page in a Collection" do
61 unordered_collection =
62 "test/fixtures/collections/unordered_page_reference.json"
66 "test/fixtures/collections/unordered_page_first.json"
70 "test/fixtures/collections/unordered_page_second.json"
73 ap_id = "https://example.com/collection/unordered_page_reference"
74 first_page_id = "https://example.com/collection/unordered_page_reference?page=1"
75 second_page_id = "https://example.com/collection/unordered_page_reference?page=2"
84 body: unordered_collection,
85 headers: [{"content-type", "application/activity+json"}]
95 headers: [{"content-type", "application/activity+json"}]
105 headers: [{"content-type", "application/activity+json"}]
109 {:ok, objects} = Fetcher.fetch_collection(ap_id)
110 assert [%{"type" => "Create"}, %{"type" => "Like"}] = objects
113 test "it should stop fetching when we hit :max_collection_objects" do
114 clear_config([:activitypub, :max_collection_objects], 1)
116 unordered_collection =
117 "test/fixtures/collections/unordered_page_reference.json"
121 "test/fixtures/collections/unordered_page_first.json"
125 "test/fixtures/collections/unordered_page_second.json"
128 ap_id = "https://example.com/collection/unordered_page_reference"
129 first_page_id = "https://example.com/collection/unordered_page_reference?page=1"
130 second_page_id = "https://example.com/collection/unordered_page_reference?page=2"
139 body: unordered_collection,
140 headers: [{"content-type", "application/activity+json"}]
150 headers: [{"content-type", "application/activity+json"}]
160 headers: [{"content-type", "application/activity+json"}]
164 {:ok, objects} = Fetcher.fetch_collection(ap_id)
165 assert [%{"type" => "Create"}] = objects
168 test "it should stop fetching when we hit a 404" do
169 clear_config([:activitypub, :max_collection_objects], 1)
171 unordered_collection =
172 "test/fixtures/collections/unordered_page_reference.json"
176 "test/fixtures/collections/unordered_page_first.json"
179 ap_id = "https://example.com/collection/unordered_page_reference"
180 first_page_id = "https://example.com/collection/unordered_page_reference?page=1"
181 second_page_id = "https://example.com/collection/unordered_page_reference?page=2"
190 body: unordered_collection,
191 headers: [{"content-type", "application/activity+json"}]
201 headers: [{"content-type", "application/activity+json"}]
211 headers: [{"content-type", "application/activity+json"}]
215 {:ok, objects} = Fetcher.fetch_collection(ap_id)
216 assert [%{"type" => "Create"}] = objects