Merge branch 'develop' of git.pleroma.social:pleroma/pleroma into feature/expire...
[akkoma] / test / pleroma / web / activity_pub / transmogrifier / article_handling_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 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{status: 200, body: File.read!("test/fixtures/tesla_mock/wedistribute-user.json")}
17 end)
18
19 data =
20 File.read!("test/fixtures/tesla_mock/wedistribute-create-article.json") |> Jason.decode!()
21
22 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
23
24 object = Object.normalize(data["object"])
25
26 assert object.data["name"] == "The end is near: Mastodon plans to drop OStatus support"
27
28 assert object.data["summary"] ==
29 "One of the largest platforms in the federated social web is dropping the protocol that it started with."
30
31 assert object.data["url"] == "https://wedistribute.org/2019/07/mastodon-drops-ostatus/"
32 end
33
34 test "Plume Article" do
35 Tesla.Mock.mock(fn
36 %{url: "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"} ->
37 %Tesla.Env{
38 status: 200,
39 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-article.json")
40 }
41
42 %{url: "https://baptiste.gelez.xyz/@/BaptisteGelez"} ->
43 %Tesla.Env{
44 status: 200,
45 body: File.read!("test/fixtures/tesla_mock/baptiste.gelex.xyz-user.json")
46 }
47 end)
48
49 {:ok, object} =
50 Fetcher.fetch_object_from_id(
51 "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
52 )
53
54 assert object.data["name"] == "This Month in Plume: June 2018"
55
56 assert object.data["url"] ==
57 "https://baptiste.gelez.xyz/~/PlumeDevelopment/this-month-in-plume-june-2018/"
58 end
59
60 test "Prismo Article" do
61 Tesla.Mock.mock(fn %{url: "https://prismo.news/@mxb"} ->
62 %Tesla.Env{
63 status: 200,
64 body: File.read!("test/fixtures/tesla_mock/https___prismo.news__mxb.json")
65 }
66 end)
67
68 data = File.read!("test/fixtures/prismo-url-map.json") |> Jason.decode!()
69
70 {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
71 object = Object.normalize(data["object"])
72
73 assert object.data["url"] == "https://prismo.news/posts/83"
74 end
75 end