Federate activity when remote account is added to a Collection (#37992)
This commit is contained in:
1 parent
951a42f491
commit
b09e63da87
10 files changed
+156
-15
No files matched your search
@@ -16,14 +16,6 @@ RSpec.describe CollectionItem do
|
||||
it { is_expected.to validate_presence_of(:account) }
|
||||
end
|
||||
|
||||
context 'when item is local and account is remote' do
|
||||
subject { Fabricate.build(:collection_item, account: remote_account) }
|
||||
|
||||
let(:remote_account) { Fabricate.build(:remote_account) }
|
||||
|
||||
it { is_expected.to validate_presence_of(:activity_uri) }
|
||||
end
|
||||
|
||||
context 'when item is not local' do
|
||||
subject { Fabricate.build(:collection_item, collection: remote_collection) }
|
||||
|
||||
@@ -58,5 +50,11 @@ RSpec.describe CollectionItem do
|
||||
expect(unrelated_item.position).to eq 1
|
||||
expect(custom_item.position).to eq 7
|
||||
end
|
||||
|
||||
it 'automatically sets `activity_uri` when account is remote' do
|
||||
item = collection.collection_items.create(account: Fabricate(:remote_account))
|
||||
|
||||
expect(item.activity_uri).to be_present
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,26 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::FeatureRequestSerializer do
|
||||
subject { serialized_record_json(collection_item, described_class, adapter: ActivityPub::Adapter) }
|
||||
|
||||
let(:tag_manager) { ActivityPub::TagManager.instance }
|
||||
let(:target_account) { Fabricate(:remote_account) }
|
||||
let(:collection) { Fabricate(:collection) }
|
||||
let(:collection_item) { Fabricate(:collection_item, collection:, account: target_account) }
|
||||
|
||||
it 'serializes to the expected json' do
|
||||
expect(subject).to include({
|
||||
'id' => collection_item.activity_uri,
|
||||
'type' => 'FeatureRequest',
|
||||
'instrument' => tag_manager.uri_for(collection_item.collection),
|
||||
'object' => tag_manager.uri_for(target_account),
|
||||
})
|
||||
|
||||
expect(subject).to_not have_key('published')
|
||||
expect(subject).to_not have_key('to')
|
||||
expect(subject).to_not have_key('cc')
|
||||
expect(subject).to_not have_key('target')
|
||||
end
|
||||
end
|
||||
@@ -21,10 +21,22 @@ RSpec.describe AddAccountToCollectionService do
|
||||
expect(new_item.account).to eq account
|
||||
end
|
||||
|
||||
it 'federates an `Add` activity', feature: :collections_federation do
|
||||
subject.call(collection, account)
|
||||
context 'when the account is local' do
|
||||
it 'federates an `Add` activity', feature: :collections_federation do
|
||||
subject.call(collection, account)
|
||||
|
||||
expect(ActivityPub::AccountRawDistributionWorker).to have_enqueued_sidekiq_job
|
||||
expect(ActivityPub::AccountRawDistributionWorker).to have_enqueued_sidekiq_job
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the account is remote', feature: :collections_federation do
|
||||
let(:account) { Fabricate(:remote_account, feature_approval_policy: (0b10 << 16)) }
|
||||
|
||||
it 'federates a `FeatureRequest` activity' do
|
||||
subject.call(collection, account)
|
||||
|
||||
expect(ActivityPub::FeatureRequestWorker).to have_enqueued_sidekiq_job
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -61,6 +61,16 @@ RSpec.describe CreateCollectionService do
|
||||
end.to raise_error(Mastodon::NotPermittedError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when some accounts are remote' do
|
||||
let(:accounts) { Fabricate.times(2, :remote_account, feature_approval_policy: (0b10 << 16)) }
|
||||
|
||||
it 'federates `FeatureRequest` activities', feature: :collections_federation do
|
||||
subject.call(params, author)
|
||||
|
||||
expect(ActivityPub::FeatureRequestWorker).to have_enqueued_sidekiq_job.exactly(2).times
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'when given a tag' do
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe ActivityPub::FeatureRequestWorker do
|
||||
subject { described_class.new }
|
||||
|
||||
let(:account) { Fabricate(:account, inbox_url: 'http://example.com', domain: 'example.com') }
|
||||
let(:collection_owner) { Fabricate(:account) }
|
||||
let(:collection) { Fabricate(:collection, account: collection_owner) }
|
||||
let(:collection_item) { Fabricate(:collection_item, collection:, account:) }
|
||||
|
||||
describe '#perform' do
|
||||
it 'sends the expected `FeatureRequest` activity' do
|
||||
subject.perform(collection_item.id)
|
||||
|
||||
expect(ActivityPub::DeliveryWorker)
|
||||
.to have_enqueued_sidekiq_job(expected_json, collection_owner.id, 'http://example.com', {})
|
||||
end
|
||||
|
||||
def expected_json
|
||||
match_json_values(
|
||||
id: a_string_matching(/^http/),
|
||||
type: 'FeatureRequest',
|
||||
object: ActivityPub::TagManager.instance.uri_for(account),
|
||||
instrument: ActivityPub::TagManager.instance.uri_for(collection_item.collection)
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user