logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

video_handling_test.exs (3403B)


  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.ActivityPub.Transmogrifier.VideoHandlingTest do
  5. use Oban.Testing, repo: Pleroma.Repo
  6. use Pleroma.DataCase
  7. alias Pleroma.Activity
  8. alias Pleroma.Object
  9. alias Pleroma.Object.Fetcher
  10. alias Pleroma.Web.ActivityPub.Transmogrifier
  11. setup_all do
  12. Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
  13. :ok
  14. end
  15. test "skip converting the content when it is nil" do
  16. data =
  17. File.read!("test/fixtures/tesla_mock/framatube.org-video.json")
  18. |> Jason.decode!()
  19. |> Kernel.put_in(["object", "content"], nil)
  20. {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
  21. assert object = Object.normalize(activity, false)
  22. assert object.data["content"] == nil
  23. end
  24. test "it converts content of object to html" do
  25. data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!()
  26. {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
  27. assert object = Object.normalize(activity, false)
  28. assert object.data["content"] ==
  29. "<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>"
  30. end
  31. test "it remaps video URLs as attachments if necessary" do
  32. {:ok, object} =
  33. Fetcher.fetch_object_from_id(
  34. "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
  35. )
  36. assert object.data["url"] ==
  37. "https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
  38. assert object.data["attachment"] == [
  39. %{
  40. "type" => "Link",
  41. "mediaType" => "video/mp4",
  42. "name" => nil,
  43. "url" => [
  44. %{
  45. "href" =>
  46. "https://peertube.moe/static/webseed/df5f464b-be8d-46fb-ad81-2d4c2d1630e3-480.mp4",
  47. "mediaType" => "video/mp4",
  48. "type" => "Link"
  49. }
  50. ]
  51. }
  52. ]
  53. data = File.read!("test/fixtures/tesla_mock/framatube.org-video.json") |> Jason.decode!()
  54. {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
  55. assert object = Object.normalize(activity, false)
  56. assert object.data["attachment"] == [
  57. %{
  58. "type" => "Link",
  59. "mediaType" => "video/mp4",
  60. "name" => nil,
  61. "url" => [
  62. %{
  63. "href" =>
  64. "https://framatube.org/static/webseed/6050732a-8a7a-43d4-a6cd-809525a1d206-1080.mp4",
  65. "mediaType" => "video/mp4",
  66. "type" => "Link"
  67. }
  68. ]
  69. }
  70. ]
  71. assert object.data["url"] ==
  72. "https://framatube.org/videos/watch/6050732a-8a7a-43d4-a6cd-809525a1d206"
  73. end
  74. end