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