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