mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-21 21:57:19 +00:00
Reduce factory creation (48 -> 8) in AP::Note
serializer spec (#32492)
This commit is contained in:
parent
a11b599ffa
commit
b1c10969ac
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue