Reduce factory creation (48 -> 8) in `AP::Note` serializer spec (#32492)

pull/2887/head
Matt Jankowski 2024-10-15 09:10:03 -04:00 committed by GitHub
parent a11b599ffa
commit b1c10969ac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 17 deletions

View File

@ -14,7 +14,7 @@ RSpec.describe ActivityPub::NoteSerializer do
let!(:reply_by_account_third) { Fabricate(:status, account: account, thread: parent, visibility: :public) }
let!(:reply_by_account_visibility_direct) { Fabricate(:status, account: account, thread: parent, visibility: :direct) }
it 'has the expected shape' do
it 'has the expected shape and replies collection' do
expect(subject).to include({
'@context' => include('https://www.w3.org/ns/activitystreams'),
'type' => 'Note',
@ -22,26 +22,23 @@ RSpec.describe ActivityPub::NoteSerializer do
'contentMap' => include({
'zh-TW' => a_kind_of(String),
}),
'replies' => replies_collection_values,
})
end
it 'has a replies collection' do
expect(subject['replies']['type']).to eql('Collection')
def replies_collection_values
include(
'type' => eql('Collection'),
'first' => include(
'type' => eql('CollectionPage'),
'items' => reply_items
)
)
end
it 'has a replies collection with a first Page' do
expect(subject['replies']['first']['type']).to eql('CollectionPage')
end
it 'includes public self-replies in its replies collection' do
expect(subject['replies']['first']['items']).to include(reply_by_account_first.uri, reply_by_account_next.uri, reply_by_account_third.uri)
end
it 'does not include replies from others in its replies collection' do
expect(subject['replies']['first']['items']).to_not include(reply_by_other_first.uri)
end
it 'does not include replies with direct visibility in its replies collection' do
expect(subject['replies']['first']['items']).to_not include(reply_by_account_visibility_direct.uri)
def reply_items
include(reply_by_account_first.uri, reply_by_account_next.uri, reply_by_account_third.uri) # Public self replies
.and(not_include(reply_by_other_first.uri)) # Replies from others
.and(not_include(reply_by_account_visibility_direct.uri)) # Replies with direct visibility
end
end