1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
6 use Oban.Testing, repo: Pleroma.Repo
11 alias Pleroma.Object.Fetcher
12 alias Pleroma.Web.ActivityPub.Transmogrifier
15 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
19 test "skip converting the content when it is nil" do
21 File.read!("test/fixtures/tesla_mock/framatube.org-video.json")
23 |> Kernel.put_in(["object", "content"], nil)
25 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
27 assert object = Object.normalize(activity, fetch: false)
29 assert object.data["content"] == nil
32 test "it converts content of object to html" do
33 data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!()
35 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
37 assert object = Object.normalize(activity, fetch: false)
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>"
43 test "it remaps video URLs as attachments if necessary" do
45 Fetcher.fetch_object_from_id(
46 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
49 assert object.data["url"] ==
50 "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
52 assert object.data["attachment"] == [
55 "mediaType" => "video/mp4",
59 "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
60 "mediaType" => "video/mp4",
68 data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!()
70 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
72 assert object = Object.normalize(activity, fetch: false)
74 assert object.data["attachment"] == [
77 "mediaType" => "video/mp4",
81 "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
82 "mediaType" => "video/mp4",
90 assert object.data["url"] ==
91 "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
94 test "it works for peertube videos with only their mpegURL map" do
96 File.read!("test/fixtures/peertube/video-object-mpegURL-only.json")
99 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
101 assert object = Object.normalize(activity, fetch: false)
103 assert object.data["attachment"] == [
106 "mediaType" => "video/mp4",
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",
119 assert object.data["url"] ==
120 "https://peertube.stream/videos/watch/abece3c3-b9c6-47f4-8040-f3eed8c602e6"