2020-08-18 13:37:28 +02:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 07:49:20 +01:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-08-18 13:37:28 +02:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AudioHandlingTest do
|
|
|
|
use Oban.Testing, repo: Pleroma.Repo
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Object
|
|
|
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
test "it works for incoming listens" do
|
|
|
|
_user = insert(:user, ap_id: "http://mastodon.example.org/users/admin")
|
|
|
|
|
|
|
|
data = %{
|
|
|
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"cc" => [],
|
|
|
|
"type" => "Listen",
|
|
|
|
"id" => "http://mastodon.example.org/users/admin/listens/1234/activity",
|
|
|
|
"actor" => "http://mastodon.example.org/users/admin",
|
|
|
|
"object" => %{
|
|
|
|
"type" => "Audio",
|
2020-09-10 11:08:05 +02:00
|
|
|
"to" => ["https://www.w3.org/ns/activitystreams#Public"],
|
|
|
|
"cc" => [],
|
2020-08-18 13:37:28 +02:00
|
|
|
"id" => "http://mastodon.example.org/users/admin/listens/1234",
|
|
|
|
"attributedTo" => "http://mastodon.example.org/users/admin",
|
|
|
|
"title" => "lain radio episode 1",
|
|
|
|
"artist" => "lain",
|
|
|
|
"album" => "lain radio",
|
|
|
|
"length" => 180_000
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
2021-01-04 13:38:31 +01:00
|
|
|
object = Object.normalize(activity, fetch: false)
|
2020-08-18 13:37:28 +02:00
|
|
|
|
|
|
|
assert object.data["title"] == "lain radio episode 1"
|
|
|
|
assert object.data["artist"] == "lain"
|
|
|
|
assert object.data["album"] == "lain radio"
|
|
|
|
assert object.data["length"] == 180_000
|
|
|
|
end
|
2020-08-19 00:05:48 +02:00
|
|
|
|
|
|
|
test "Funkwhale Audio object" do
|
2020-08-19 14:36:42 +02:00
|
|
|
Tesla.Mock.mock(fn
|
|
|
|
%{url: "https://channels.tests.funkwhale.audio/federation/actors/compositions"} ->
|
|
|
|
%Tesla.Env{
|
|
|
|
status: 200,
|
2020-10-28 16:08:23 +01:00
|
|
|
body: File.read!("test/fixtures/tesla_mock/funkwhale_channel.json"),
|
|
|
|
headers: HttpRequestMock.activitypub_object_headers()
|
2020-08-19 14:36:42 +02:00
|
|
|
}
|
|
|
|
end)
|
|
|
|
|
2020-11-23 20:28:55 +01:00
|
|
|
data = File.read!("test/fixtures/tesla_mock/funkwhale_create_audio.json") |> Jason.decode!()
|
2020-08-19 00:05:48 +02:00
|
|
|
|
|
|
|
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
|
|
|
|
2021-01-04 13:38:31 +01:00
|
|
|
assert object = Object.normalize(activity, fetch: false)
|
2020-08-19 00:05:48 +02:00
|
|
|
|
|
|
|
assert object.data["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
|
|
|
|
|
2020-09-10 11:08:05 +02:00
|
|
|
assert object.data["cc"] == [
|
|
|
|
"https://channels.tests.funkwhale.audio/federation/actors/compositions/followers"
|
|
|
|
]
|
2020-08-19 00:05:48 +02:00
|
|
|
|
|
|
|
assert object.data["url"] == "https://channels.tests.funkwhale.audio/library/tracks/74"
|
|
|
|
|
|
|
|
assert object.data["attachment"] == [
|
|
|
|
%{
|
|
|
|
"mediaType" => "audio/ogg",
|
|
|
|
"type" => "Link",
|
|
|
|
"name" => nil,
|
2020-11-11 23:17:35 +01:00
|
|
|
"blurhash" => nil,
|
2020-08-19 00:05:48 +02:00
|
|
|
"url" => [
|
|
|
|
%{
|
|
|
|
"href" =>
|
|
|
|
"https://channels.tests.funkwhale.audio/api/v1/listen/3901e5d8-0445-49d5-9711-e096cf32e515/?upload=42342395-0208-4fee-a38d-259a6dae0871&download=false",
|
|
|
|
"mediaType" => "audio/ogg",
|
2021-05-12 22:38:49 +02:00
|
|
|
"type" => "Link",
|
|
|
|
"width" => nil,
|
|
|
|
"height" => nil
|
2020-08-19 00:05:48 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
end
|
2020-08-18 13:37:28 +02:00
|
|
|
end
|