diff options
| author | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-09-17 17:14:20 +0300 | 
|---|---|---|
| committer | Ivan Tashkinov <ivantashkinov@gmail.com> | 2020-09-17 17:14:20 +0300 | 
| commit | d9fb5bc08ad67b55d0cd25c1a0d7d3a740758427 (patch) | |
| tree | 6303695147d01ab5e71e556f2b8f7725536e475f /test/web/activity_pub/transmogrifier/video_handling_test.exs | |
| parent | 7cdbd91d83c02a79c22783ca489ef82e82b31a51 (diff) | |
| parent | cd93aa2aed6fda516d4fc2aabb44c5e178a6543d (diff) | |
| download | pleroma-d9fb5bc08ad67b55d0cd25c1a0d7d3a740758427.tar.gz pleroma-d9fb5bc08ad67b55d0cd25c1a0d7d3a740758427.zip  | |
Merge remote-tracking branch 'remotes/origin/develop' into media-preview-proxy-nostream
Diffstat (limited to 'test/web/activity_pub/transmogrifier/video_handling_test.exs')
| -rw-r--r-- | test/web/activity_pub/transmogrifier/video_handling_test.exs | 93 | 
1 files changed, 93 insertions, 0 deletions
diff --git a/test/web/activity_pub/transmogrifier/video_handling_test.exs b/test/web/activity_pub/transmogrifier/video_handling_test.exs new file mode 100644 index 000000000..69c953a2e --- /dev/null +++ b/test/web/activity_pub/transmogrifier/video_handling_test.exs @@ -0,0 +1,93 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do +  use Oban.Testing, repo: Pleroma.Repo +  use Pleroma.DataCase + +  alias Pleroma.Activity +  alias Pleroma.Object +  alias Pleroma.Object.Fetcher +  alias Pleroma.Web.ActivityPub.Transmogrifier + +  setup_all do +    Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end) +    :ok +  end + +  test "skip converting the content when it is nil" do +    data = +      File.read!("test/fixtures/tesla_mock/framatube.org-video.json") +      |> Jason.decode!() +      |> Kernel.put_in(["object", "content"], nil) + +    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) + +    assert object = Object.normalize(activity, false) + +    assert object.data["content"] == nil +  end + +  test "it converts content of object to html" do +    data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!() + +    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) + +    assert object = Object.normalize(activity, false) + +    assert object.data["content"] == +             "<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>" +  end + +  test "it remaps video URLs as attachments if necessary" do +    {:ok, object} = +      Fetcher.fetch_object_from_id( +        "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" +      ) + +    assert object.data["url"] == +             "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3" + +    assert object.data["attachment"] == [ +             %{ +               "type" => "Link", +               "mediaType" => "video/mp4", +               "name" => nil, +               "url" => [ +                 %{ +                   "href" => +                     "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4", +                   "mediaType" => "video/mp4", +                   "type" => "Link" +                 } +               ] +             } +           ] + +    data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!() + +    {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data) + +    assert object = Object.normalize(activity, false) + +    assert object.data["attachment"] == [ +             %{ +               "type" => "Link", +               "mediaType" => "video/mp4", +               "name" => nil, +               "url" => [ +                 %{ +                   "href" => +                     "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4", +                   "mediaType" => "video/mp4", +                   "type" => "Link" +                 } +               ] +             } +           ] + +    assert object.data["url"] == +             "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206" +  end +end  | 
