[#1505] Improved replies-handling tests: updated Mastodon message fixture, used exact Pleroma federation message.

This commit is contained in:
Ivan Tashkinov 2020-02-10 11:46:16 +03:00
parent 24e49d14f2
commit b95dd5e217
2 changed files with 43 additions and 29 deletions

View File

@ -35,6 +35,19 @@
"inReplyTo": null, "inReplyTo": null,
"inReplyToAtomUri": null, "inReplyToAtomUri": null,
"published": "2018-02-12T14:08:20Z", "published": "2018-02-12T14:08:20Z",
"replies": {
"id": "http://mastodon.example.org/users/admin/statuses/99512778738411822/replies",
"type": "Collection",
"first": {
"type": "CollectionPage",
"next": "http://mastodon.example.org/users/admin/statuses/99512778738411822/replies?min_id=99512778738411824&page=true",
"partOf": "http://mastodon.example.org/users/admin/statuses/99512778738411822/replies",
"items": [
"http://mastodon.example.org/users/admin/statuses/99512778738411823",
"http://mastodon.example.org/users/admin/statuses/99512778738411824"
]
}
},
"sensitive": true, "sensitive": true,
"summary": "cw", "summary": "cw",
"tag": [ "tag": [

View File

@ -1350,27 +1350,20 @@ test "it accepts Move activities" do
end end
end end
describe "`replies` handling in handle_incoming/2" do describe "handle_incoming/2: `replies` handling:" do
setup do clear_config([:activitypub, :note_replies_output_limit]) do
data = Pleroma.Config.put([:activitypub, :note_replies_output_limit], 5)
File.read!("test/fixtures/mastodon-post-activity.json")
|> Poison.decode!()
items = ["https://shitposter.club/notice/2827873", "https://shitposter.club/notice/7387606"]
collection = %{"items" => items}
%{data: data, items: items, collection: collection}
end end
# Mastodon wraps reply URIs in `replies->first->items` test "with Mastodon-formatted `replies` collection, it schedules background fetching of items" do
test "with wrapped `replies` collection, it schedules background fetching of items", %{ data =
data: data, "test/fixtures/mastodon-post-activity.json"
items: items, |> File.read!()
collection: collection |> Poison.decode!()
} do
replies = %{"first" => collection} items = get_in(data, ["object", "replies", "first", "items"])
assert length(items) > 0
object = Map.put(data["object"], "replies", replies)
data = Map.put(data, "object", object)
{:ok, _activity} = Transmogrifier.handle_incoming(data) {:ok, _activity} = Transmogrifier.handle_incoming(data)
for id <- items do for id <- items do
@ -1379,19 +1372,27 @@ test "with wrapped `replies` collection, it schedules background fetching of ite
end end
end end
# Pleroma outputs reply URIs as `replies->items` test "with Pleroma-formatted `replies` collection, it schedules background fetching of items" do
test "it schedules background fetching of unwrapped `replies` collection items", %{ user = insert(:user)
data: data,
items: items,
collection: collection
} do
replies = collection
object = Map.put(data["object"], "replies", replies) {:ok, activity} = CommonAPI.post(user, %{"status" => "post1"})
data = Map.put(data, "object", object)
{:ok, _activity} = Transmogrifier.handle_incoming(data)
for id <- items do {:ok, reply1} =
CommonAPI.post(user, %{"status" => "reply1", "in_reply_to_status_id" => activity.id})
{:ok, reply2} =
CommonAPI.post(user, %{"status" => "reply2", "in_reply_to_status_id" => activity.id})
replies_uris = Enum.map([reply1, reply2], fn a -> a.object.data["id"] end)
{:ok, federation_output} = Transmogrifier.prepare_outgoing(activity.data)
Repo.delete(activity.object)
Repo.delete(activity)
{:ok, _activity} = Transmogrifier.handle_incoming(federation_output)
for id <- replies_uris do
job_args = %{"op" => "fetch_remote", "id" => id} job_args = %{"op" => "fetch_remote", "id" => id}
assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args) assert_enqueued(worker: Pleroma.Workers.RemoteFetcherWorker, args: job_args)
end end