mirror of
https://github.com/mastodon/mastodon.git
synced 2024-08-20 21:08:15 -07:00
Extract spec helper for verifing to/from public AP collection namespace (#28472)
This commit is contained in:
parent
b6e353537b
commit
185c806d69
2 changed files with 31 additions and 6 deletions
|
@ -79,7 +79,7 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
it 'returns orderedItems with public or unlisted statuses' do
|
||||
expect(body[:orderedItems]).to be_an Array
|
||||
expect(body[:orderedItems].size).to eq 2
|
||||
expect(body[:orderedItems].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true
|
||||
expect(body[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
|
||||
end
|
||||
|
||||
it_behaves_like 'cacheable response'
|
||||
|
@ -132,7 +132,7 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
json = body_as_json
|
||||
expect(json[:orderedItems]).to be_an Array
|
||||
expect(json[:orderedItems].size).to eq 2
|
||||
expect(json[:orderedItems].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true
|
||||
expect(json[:orderedItems].all? { |item| targets_public_collection?(item) }).to be true
|
||||
end
|
||||
|
||||
it 'returns private Cache-Control header' do
|
||||
|
@ -158,7 +158,7 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
json = body_as_json
|
||||
expect(json[:orderedItems]).to be_an Array
|
||||
expect(json[:orderedItems].size).to eq 3
|
||||
expect(json[:orderedItems].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:to].include?(account_followers_url(account, ActionMailer::Base.default_url_options)) }).to be true
|
||||
expect(json[:orderedItems].all? { |item| targets_public_collection?(item) || targets_followers_collection?(item, account) }).to be true
|
||||
end
|
||||
|
||||
it 'returns private Cache-Control header' do
|
||||
|
@ -217,4 +217,20 @@ RSpec.describe ActivityPub::OutboxesController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ap_public_collection
|
||||
ActivityPub::TagManager::COLLECTIONS[:public]
|
||||
end
|
||||
|
||||
def targets_public_collection?(item)
|
||||
item[:to].include?(ap_public_collection) || item[:cc].include?(ap_public_collection)
|
||||
end
|
||||
|
||||
def targets_followers_collection?(item, account)
|
||||
item[:to].include?(
|
||||
account_followers_url(account, ActionMailer::Base.default_url_options)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -84,7 +84,7 @@ RSpec.describe ActivityPub::RepliesController do
|
|||
expect(page_json).to be_a Hash
|
||||
expect(page_json[:items]).to be_an Array
|
||||
expect(page_json[:items].size).to eq 1
|
||||
expect(page_json[:items].all? { |item| item[:to].include?(ActivityPub::TagManager::COLLECTIONS[:public]) || item[:cc].include?(ActivityPub::TagManager::COLLECTIONS[:public]) }).to be true
|
||||
expect(page_json[:items].all? { |item| targets_public_collection?(item) }).to be true
|
||||
end
|
||||
|
||||
context 'when there are few self-replies' do
|
||||
|
@ -117,8 +117,7 @@ RSpec.describe ActivityPub::RepliesController do
|
|||
|
||||
it 'only inlines items that are local and public or unlisted replies' do
|
||||
inlined_replies = page_json[:items].select { |x| x.is_a?(Hash) }
|
||||
public_collection = ActivityPub::TagManager::COLLECTIONS[:public]
|
||||
expect(inlined_replies.all? { |item| item[:to].include?(public_collection) || item[:cc].include?(public_collection) }).to be true
|
||||
expect(inlined_replies.all? { |item| targets_public_collection?(item) }).to be true
|
||||
expect(inlined_replies.all? { |item| ActivityPub::TagManager.instance.local_uri?(item[:id]) }).to be true
|
||||
end
|
||||
|
||||
|
@ -194,4 +193,14 @@ RSpec.describe ActivityPub::RepliesController do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def ap_public_collection
|
||||
ActivityPub::TagManager::COLLECTIONS[:public]
|
||||
end
|
||||
|
||||
def targets_public_collection?(item)
|
||||
item[:to].include?(ap_public_collection) || item[:cc].include?(ap_public_collection)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue