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