AP/AS serialization of Collections (#37434)

This commit is contained in:
David Roetzel authored and GitHub committed 2026-01-12 08:39:25 +00:00
1 parent a4b8b9fe98
commit a9cfddf28e
8 files changed
+139

No files matched your search

@@ -8,3 +8,10 @@ Fabricator(:collection) do
sensitive false
discoverable true
end
Fabricator(:remote_collection, from: :collection) do
account { Fabricate.build(:remote_account) }
local false
uri { sequence(:uri) { |i| "https://example.com/collections/#{i}" } }
original_number_of_items 0
end
+17
View File
@@ -192,6 +192,23 @@ RSpec.describe ActivityPub::TagManager do
expect(subject.uri_for(status.conversation)).to eq status.conversation.uri
end
end
context 'with a local collection' do
let(:collection) { Fabricate(:collection) }
it 'returns a string starting with web domain and with the expected path' do
expect(subject.uri_for(collection))
.to eq("#{host_prefix}/ap/users/#{collection.account.id}/featured_collections/#{collection.id}")
end
end
context 'with a remote collection' do
let(:collection) { Fabricate(:remote_collection) }
it 'returns the expected URL' do
expect(subject.uri_for(collection)).to eq collection.uri
end
end
end
describe '#key_uri_for' do
+6
View File
@@ -126,4 +126,10 @@ RSpec.describe Collection do
end
end
end
describe '#object_type' do
it 'returns `:featured_collection`' do
expect(subject.object_type).to eq :featured_collection
end
end
end
@@ -0,0 +1,48 @@
# frozen_string_literal: true
require 'rails_helper'
RSpec.describe ActivityPub::FeaturedCollectionSerializer do
subject { serialized_record_json(collection, described_class, adapter: ActivityPub::Adapter) }
let(:collection) do
Fabricate(:collection,
name: 'Incredible people',
description: 'These are really amazing',
tag_name: '#people',
discoverable: false)
end
let!(:collection_items) { Fabricate.times(2, :collection_item, collection:) }
it 'serializes to the expected structure' do
expect(subject).to include({
'type' => 'FeaturedCollection',
'id' => ActivityPub::TagManager.instance.uri_for(collection),
'name' => 'Incredible people',
'summary' => 'These are really amazing',
'attributedTo' => ActivityPub::TagManager.instance.uri_for(collection.account),
'sensitive' => false,
'discoverable' => false,
'topic' => {
'href' => match(%r{/tags/people$}),
'type' => 'Hashtag',
'name' => '#people',
},
'totalItems' => 2,
'orderedItems' => [
{
'type' => 'FeaturedItem',
'featuredObject' => ActivityPub::TagManager.instance.uri_for(collection_items.first.account),
'featuredObjectType' => 'Person',
},
{
'type' => 'FeaturedItem',
'featuredObject' => ActivityPub::TagManager.instance.uri_for(collection_items.last.account),
'featuredObjectType' => 'Person',
},
],
'published' => match_api_datetime_format,
'updated' => match_api_datetime_format,
})
end
end