Resolve follow activity from accept/reject without ID (#328)
[akkoma] / test / pleroma / web / activity_pub / transmogrifier / video_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.VideoHandlingTest 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 setup_all do
15 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
16 :ok
17 end
18
19 test "skip converting the content when it is nil" do
20 data =
21 File.read!("test/fixtures/tesla_mock/framatube.org-video.json")
22 |> Jason.decode!()
23 |> Kernel.put_in(["object", "content"], nil)
24
25 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
26
27 assert object = Object.normalize(activity, fetch: false)
28
29 assert object.data["content"] == nil
30 end
31
32 test "it converts content of object to html" do
33 data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!()
34
35 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
36
37 assert object = Object.normalize(activity, fetch: false)
38
39 assert object.data["content"] ==
40 "<p>Après avoir mené avec un certain succès la campagne « Dégooglisons Internet » en 2014, l’association Framasoft annonce fin 2019 arrêter progressivement un certain nombre de ses services alternatifs aux GAFAM. Pourquoi ?</p><p>Transcription par @aprilorg ici : <a href=\"https://www.april.org/deframasoftisons-internet-pierre-yves-gosset-framasoft\">https://www.april.org/deframasoftisons-internet-pierre-yves-gosset-framasoft</a></p>"
41 end
42
43 test "it remaps video URLs as attachments if necessary" do
44 {:ok, object} =
45 Fetcher.fetch_object_from_id(
46 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
47 )
48
49 assert object.data["url"] ==
50 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
51
52 assert object.data["attachment"] == [
53 %{
54 "type" => "Link",
55 "mediaType" => "video/mp4",
56 "url" => [
57 %{
58 "href" =>
59 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
60 "mediaType" => "video/mp4",
61 "type" => "Link",
62 "width" => 480
63 }
64 ]
65 }
66 ]
67
68 data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!()
69
70 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
71
72 assert object = Object.normalize(activity, fetch: false)
73
74 assert object.data["attachment"] == [
75 %{
76 "type" => "Link",
77 "mediaType" => "video/mp4",
78 "url" => [
79 %{
80 "href" =>
81 "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
82 "mediaType" => "video/mp4",
83 "type" => "Link",
84 "height" => 1080
85 }
86 ]
87 }
88 ]
89
90 assert object.data["url"] ==
91 "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
92 end
93
94 test "it works for peertube videos with only their mpegURL map" do
95 data =
96 File.read!("test/fixtures/peertube/video-object-mpegURL-only.json")
97 |> Jason.decode!()
98
99 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
100
101 assert object = Object.normalize(activity, fetch: false)
102
103 assert object.data["attachment"] == [
104 %{
105 "type" => "Link",
106 "mediaType" => "video/mp4",
107 "url" => [
108 %{
109 "href" =>
110 "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
111 "mediaType" => "video/mp4",
112 "type" => "Link",
113 "height" => 1080
114 }
115 ]
116 }
117 ]
118
119 assert object.data["url"] ==
120 "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6"
121 end
122 end