logo

pleroma

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

audio_handling_test.exs (3020B)


  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.AudioHandlingTest do
  5. use Oban.Testing, repo: Pleroma.Repo
  6. use Pleroma.DataCase
  7. alias Pleroma.Activity
  8. alias Pleroma.Object
  9. alias Pleroma.Web.ActivityPub.Transmogrifier
  10. import Pleroma.Factory
  11. test "it works for incoming listens" do
  12. _user = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
  13. data = %{
  14. "@context" => "https://www.w3.org/ns/activitystreams",
  15. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  16. "cc" => [],
  17. "type" => "Listen",
  18. "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
  19. "actor" => "http://mastodon.example.org/users/admin",
  20. "object" => %{
  21. "type" => "Audio",
  22. "to" => ["https://www.w3.org/ns/activitystreams#Public"],
  23. "cc" => [],
  24. "id" => "http://mastodon.example.org/users/admin/listens/1234",
  25. "attributedTo" => "http://mastodon.example.org/users/admin",
  26. "title" => "lain radio episode 1",
  27. "artist" => "lain",
  28. "album" => "lain radio",
  29. "length" => 180_000
  30. }
  31. }
  32. {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
  33. object = Object.normalize(activity)
  34. assert object.data["title"] == "lain radio episode 1"
  35. assert object.data["artist"] == "lain"
  36. assert object.data["album"] == "lain radio"
  37. assert object.data["length"] == 180_000
  38. end
  39. test "Funkwhale Audio object" do
  40. Tesla.Mock.mock(fn
  41. %{url: "https://channels.tests.funkwhale.audio/federation/actors/compositions"} ->
  42. %Tesla.Env{
  43. status: 200,
  44. body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json")
  45. }
  46. end)
  47. data = File.read!("test/fixtures/tesla_mock/funkwhale_create_audio.json") |> Poison.decode!()
  48. {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
  49. assert object = Object.normalize(activity, false)
  50. assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
  51. assert object.data["cc"] == [
  52. "https://channels.tests.funkwhale.audio/federation/actors/compositions/followers"
  53. ]
  54. assert object.data["url"] == "https://channels.tests.funkwhale.audio/library/tracks/74"
  55. assert object.data["attachment"] == [
  56. %{
  57. "mediaType" => "audio/ogg",
  58. "type" => "Link",
  59. "name" => nil,
  60. "url" => [
  61. %{
  62. "href" =>
  63. "https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
  64. "mediaType" => "audio/ogg",
  65. "type" => "Link"
  66. }
  67. ]
  68. }
  69. ]
  70. end
  71. end