akkoma/test/pleroma/web/metadata/providers/ap_url_test.exs
Oneric ed03eaade9 web/metadata: provide alternate link for ActivityPub
This allows discovering a page represents an ActivityPub object
and also where to find the underlying representation.
Other servers already implement this and some tools
came to rely or profit from it.

The alternate link is provided both with the "application/activity+json"
format as used by Mastodon and the standard-compliant media type.

Just like the feed provider, ActivityPub links are always enabled
unless access to local posts is restricted and not configurable.

The commit is based on earlier work by Charlotte 🦝 Deleńkec
but with fixes and some tweaks.

Co-authored-by: Charlotte 🦝 Deleńkec <lotte@chir.rs>
2025-04-27 00:35:02 +02:00

31 lines
1.1 KiB
Elixir

# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Metadata.Providers.ApUrlTest do
use Pleroma.DataCase, async: true
import Pleroma.Factory
alias Pleroma.Web.Metadata.Providers.ApUrl
@ap_type_compliant "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""
@ap_type_mastodon "application/activity+json"
test "it preferentially renders a link to a post" do
user = insert(:user)
note = insert(:note, user: user)
assert ApUrl.build_tags(%{object: note, user: user}) == [
{:link, [rel: "alternate", href: note.data["id"], type: @ap_type_mastodon], []},
{:link, [rel: "alternate", href: note.data["id"], type: @ap_type_compliant], []}
]
end
test "it renders a link to a user" do
user = insert(:user)
assert ApUrl.build_tags(%{user: user}) == [
{:link, [rel: "alternate", href: user.ap_id, type: @ap_type_mastodon], []},
{:link, [rel: "alternate", href: user.ap_id, type: @ap_type_compliant], []}
]
end
end