From 6342ddd698934e310db23c4ff5901aaee3c698e3 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 22 Feb 2024 05:48:42 -0500 Subject: [PATCH] Add basic coverage for `UnfavouriteService` class (#29329) --- spec/services/unfavourite_service_spec.rb | 36 +++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 spec/services/unfavourite_service_spec.rb diff --git a/spec/services/unfavourite_service_spec.rb b/spec/services/unfavourite_service_spec.rb new file mode 100644 index 0000000000..a714cc0675 --- /dev/null +++ b/spec/services/unfavourite_service_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe UnfavouriteService do + describe '#call' do + context 'with a favourited status' do + let(:status) { Fabricate(:status, account: account) } + let!(:favourite) { Fabricate(:favourite, status: status) } + + context 'when the status account is local' do + let(:account) { Fabricate(:account, domain: nil) } + + it 'destroys the favourite' do + subject.call(favourite.account, status) + + expect { favourite.reload } + .to raise_error(ActiveRecord::RecordNotFound) + end + end + + context 'when the status account is a remote activitypub account' do + let(:account) { Fabricate(:account, domain: 'host.example', protocol: :activitypub) } + + it 'destroys the favourite and sends a notification' do + subject.call(favourite.account, status) + + expect { favourite.reload } + .to raise_error(ActiveRecord::RecordNotFound) + expect(ActivityPub::DeliveryWorker) + .to have_enqueued_sidekiq_job(anything, favourite.account.id, status.account.inbox_url) + end + end + end + end +end