Resolve follow activity from accept/reject without ID (#328)
[akkoma] / test / pleroma / web / activity_pub / transmogrifier / article_handling_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.ArticleHandlingTest do
6 use Oban.Testing, repo: Pleroma.Repo
7 use Pleroma.DataCase
8
9 alias Pleroma.Activity
10 alias Pleroma.Object
11 alias Pleroma.Object.Fetcher
12 alias Pleroma.Web.ActivityPub.Transmogrifier
13
14 test "Pterotype (Wordpress Plugin) Article" do
15 Tesla.Mock.mock(fn %{url: "https://wedistribute.org/wp-json/pterotype/v1/actor/-blog"} ->
16 %Tesla.Env{
17 status: 200,
18 body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json"),
19 headers: HttpRequestMock.activitypub_object_headers()
20 }
21 end)
22
23 data =
24 File.read!("test/fixtures/tesla_mock/wedistribute-create-article.json") |> Jason.decode!()
25
26 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
27
28 object = Object.normalize(data["object"], fetch: false)
29
30 assert object.data["name"] == "The end is near: Mastodon plans to drop OStatus support"
31
32 assert object.data["summary"] ==
33 "One of the largest platforms in the federated social web is dropping the protocol that it started with."
34
35 assert object.data["url"] == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
36 end
37
38 test "Plume Article" do
39 Tesla.Mock.mock(fn
40 %{url: "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"} ->
41 %Tesla.Env{
42 status: 200,
43 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json"),
44 headers: HttpRequestMock.activitypub_object_headers()
45 }
46
47 %{url: "https://baptiste.gelez.xyz/@/BaptisteGelez"} ->
48 %Tesla.Env{
49 status: 200,
50 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json"),
51 headers: HttpRequestMock.activitypub_object_headers()
52 }
53 end)
54
55 {:ok, object} =
56 Fetcher.fetch_object_from_id(
57 "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
58 )
59
60 assert object.data["name"] == "This Month in Plume: June 2018"
61
62 assert object.data["url"] ==
63 "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
64 end
65
66 test "Prismo Article" do
67 Tesla.Mock.mock(fn %{url: "https://prismo.news/@mxb"} ->
68 %Tesla.Env{
69 status: 200,
70 body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json"),
71 headers: HttpRequestMock.activitypub_object_headers()
72 }
73 end)
74
75 data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!()
76
77 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
78 object = Object.normalize(data["object"], fetch: false)
79
80 assert object.data["url"] == "https://prismo.news/posts/83"
81 end
82 end