diff --git a/spec/services/remove_status_service_spec.rb b/spec/services/remove_status_service_spec.rb index b385cfa55b..917b66c6df 100644 --- a/spec/services/remove_status_service_spec.rb +++ b/spec/services/remove_status_service_spec.rb @@ -48,30 +48,16 @@ RSpec.describe RemoveStatusService, :sidekiq_inline do it 'sends Delete activity to followers' do subject.call(status) - expect(a_request(:post, hank.inbox_url).with( - body: hash_including({ - 'type' => 'Delete', - 'object' => { - 'type' => 'Tombstone', - 'id' => ActivityPub::TagManager.instance.uri_for(status), - 'atomUri' => OStatus::TagManager.instance.uri_for(status), - }, - }) - )).to have_been_made.once + + expect(delete_delivery(hank, status)) + .to have_been_made.once end it 'sends Delete activity to rebloggers' do subject.call(status) - expect(a_request(:post, bill.inbox_url).with( - body: hash_including({ - 'type' => 'Delete', - 'object' => { - 'type' => 'Tombstone', - 'id' => ActivityPub::TagManager.instance.uri_for(status), - 'atomUri' => OStatus::TagManager.instance.uri_for(status), - }, - }) - )).to have_been_made.once + + expect(delete_delivery(bill, status)) + .to have_been_made.once end it 'remove status from notifications' do @@ -79,6 +65,22 @@ RSpec.describe RemoveStatusService, :sidekiq_inline do Notification.where(activity_type: 'Favourite', from_account: jeff, account: alice).count }.from(1).to(0) end + + def delete_delivery(target, status) + a_request(:post, target.inbox_url) + .with(body: delete_activity_for(status)) + end + + def delete_activity_for(status) + hash_including( + 'type' => 'Delete', + 'object' => { + 'type' => 'Tombstone', + 'id' => ActivityPub::TagManager.instance.uri_for(status), + 'atomUri' => OStatus::TagManager.instance.uri_for(status), + } + ) + end end context 'when removed status is a private self-reblog' do @@ -87,15 +89,9 @@ RSpec.describe RemoveStatusService, :sidekiq_inline do it 'sends Undo activity to followers' do subject.call(status) - expect(a_request(:post, hank.inbox_url).with( - body: hash_including({ - 'type' => 'Undo', - 'object' => hash_including({ - 'type' => 'Announce', - 'object' => ActivityPub::TagManager.instance.uri_for(original_status), - }), - }) - )).to have_been_made.once + + expect(undo_delivery(hank, original_status)) + .to have_been_made.once end end @@ -105,15 +101,9 @@ RSpec.describe RemoveStatusService, :sidekiq_inline do it 'sends Undo activity to followers' do subject.call(status) - expect(a_request(:post, hank.inbox_url).with( - body: hash_including({ - 'type' => 'Undo', - 'object' => hash_including({ - 'type' => 'Announce', - 'object' => ActivityPub::TagManager.instance.uri_for(original_status), - }), - }) - )).to have_been_made.once + + expect(undo_delivery(hank, original_status)) + .to have_been_made.once end end @@ -123,15 +113,24 @@ RSpec.describe RemoveStatusService, :sidekiq_inline do it 'sends Undo activity to followers' do subject.call(status) - expect(a_request(:post, bill.inbox_url).with( - body: hash_including({ - 'type' => 'Undo', - 'object' => hash_including({ - 'type' => 'Announce', - 'object' => ActivityPub::TagManager.instance.uri_for(original_status), - }), - }) - )).to have_been_made.once + + expect(undo_delivery(bill, original_status)) + .to have_been_made.once end end + + def undo_delivery(target, status) + a_request(:post, target.inbox_url) + .with(body: undo_activity_for(status)) + end + + def undo_activity_for(status) + hash_including( + 'type' => 'Undo', + 'object' => hash_including( + 'type' => 'Announce', + 'object' => ActivityPub::TagManager.instance.uri_for(status) + ) + ) + end end