ObjectValidator.CommonFixes: Introduce fix_objects_defaults and fix_activity_defaults
[akkoma] / test / pleroma / web / activity_pub / transmogrifier / audio_handling_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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 test "it works for incoming listens" do
16 _user = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
17
18 data = %{
19 "@context" => "https://www.w3.org/ns/activitystreams",
20 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
21 "cc" => [],
22 "type" => "Listen",
23 "id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
24 "actor" => "http://mastodon.example.org/users/admin",
25 "object" => %{
26 "type" => "Audio",
27 "to" => ["https://www.w3.org/ns/activitystreams#Public"],
28 "cc" => [],
29 "id" => "http://mastodon.example.org/users/admin/listens/1234",
30 "attributedTo" => "http://mastodon.example.org/users/admin",
31 "title" => "lain radio episode 1",
32 "artist" => "lain",
33 "album" => "lain radio",
34 "length" => 180_000
35 }
36 }
37
38 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
39
40 object = Object.normalize(activity, fetch: false)
41
42 assert object.data["title"] == "lain radio episode 1"
43 assert object.data["artist"] == "lain"
44 assert object.data["album"] == "lain radio"
45 assert object.data["length"] == 180_000
46 end
47
48 test "Funkwhale Audio object" do
49 Tesla.Mock.mock(fn
50 %{url: "https://channels.tests.funkwhale.audio/federation/actors/compositions"} ->
51 %Tesla.Env{
52 status: 200,
53 body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json"),
54 headers: HttpRequestMock.activitypub_object_headers()
55 }
56 end)
57
58 data = File.read!("test/fixtures/tesla_mock/funkwhale_create_audio.json") |> Jason.decode!()
59
60 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
61
62 assert object = Object.normalize(activity, fetch: false)
63
64 assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
65
66 assert object.data["cc"] == [
67 "https://channels.tests.funkwhale.audio/federation/actors/compositions/followers"
68 ]
69
70 assert object.data["url"] == "https://channels.tests.funkwhale.audio/library/tracks/74"
71
72 assert object.data["attachment"] == [
73 %{
74 "mediaType" => "audio/ogg",
75 "type" => "Link",
76 "name" => nil,
77 "blurhash" => nil,
78 "url" => [
79 %{
80 "href" =>
81 "https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
82 "mediaType" => "audio/ogg",
83 "type" => "Link"
84 }
85 ]
86 }
87 ]
88 end
89 end