From f287462f760bbc2402772e120148687565a39cc5 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Mon, 17 Jun 2024 06:21:29 -0400 Subject: [PATCH] Fix repeated Delete/Undo assertion in remove status service spec (#30715) --- spec/services/remove_status_service_spec.rb | 93 ++++++++++----------- 1 file changed, 46 insertions(+), 47 deletions(-) diff --git a/spec/services/remove_status_service_spec.rb b/spec/services/remove_status_service_spec.rb index b385cfa55be..917b66c6df4 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