62b4a2cb37ba2d6f9a1274472897e551e41100da
[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 "name" => nil,
57 "blurhash" => nil,
58 "url" => [
59 %{
60 "href" =>
61 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
62 "mediaType" => "video/mp4",
63 "type" => "Link",
64 "width" => nil,
65 "height" => nil
66 }
67 ]
68 }
69 ]
70
71 data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!()
72
73 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
74
75 assert object = Object.normalize(activity, fetch: false)
76
77 assert object.data["attachment"] == [
78 %{
79 "type" => "Link",
80 "mediaType" => "video/mp4",
81 "name" => nil,
82 "blurhash" => nil,
83 "url" => [
84 %{
85 "href" =>
86 "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
87 "mediaType" => "video/mp4",
88 "type" => "Link",
89 "width" => nil,
90 "height" => nil
91 }
92 ]
93 }
94 ]
95
96 assert object.data["url"] ==
97 "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
98 end
99
100 test "it works for peertube videos with only their mpegURL map" do
101 data =
102 File.read!("test/fixtures/peertube/video-object-mpegURL-only.json")
103 |> Jason.decode!()
104
105 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
106
107 assert object = Object.normalize(activity, fetch: false)
108
109 assert object.data["attachment"] == [
110 %{
111 "type" => "Link",
112 "mediaType" => "video/mp4",
113 "name" => nil,
114 "blurhash" => nil,
115 "url" => [
116 %{
117 "href" =>
118 "https://peertube.stream/static/streaming-playlists/hls/abece3c3-b9c6-47f4-8040-f3eed8c602e6/abece3c3-b9c6-47f4-8040-f3eed8c602e6-1080-fragmented.mp4",
119 "mediaType" => "video/mp4",
120 "type" => "Link",
121 "width" => nil,
122 "height" => nil
123 }
124 ]
125 }
126 ]
127
128 assert object.data["url"] ==
129 "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6"
130 end
131 end