From 7c7dfe7de33c27b65805960061bd5d0a42733722 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Thu, 22 Feb 2024 05:51:04 -0500 Subject: [PATCH] Add basic coverage for `RemoveFeaturedTagService` class (#29328) --- .../remove_featured_tag_service_spec.rb | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 spec/services/remove_featured_tag_service_spec.rb diff --git a/spec/services/remove_featured_tag_service_spec.rb b/spec/services/remove_featured_tag_service_spec.rb new file mode 100644 index 0000000000..6cf5388c7f --- /dev/null +++ b/spec/services/remove_featured_tag_service_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe RemoveFeaturedTagService do + describe '#call' do + context 'with a featured tag' do + let(:featured_tag) { Fabricate(:featured_tag) } + + context 'when called by a local account' do + let(:account) { Fabricate(:account, domain: nil) } + + it 'destroys the featured tag and sends a distribution' do + subject.call(account, featured_tag) + + expect { featured_tag.reload } + .to raise_error(ActiveRecord::RecordNotFound) + expect(ActivityPub::AccountRawDistributionWorker) + .to have_enqueued_sidekiq_job(anything, account.id) + end + end + + context 'when called by a non local account' do + let(:account) { Fabricate(:account, domain: 'host.example') } + + it 'destroys the featured tag and does not send a distribution' do + subject.call(account, featured_tag) + + expect { featured_tag.reload } + .to raise_error(ActiveRecord::RecordNotFound) + expect(ActivityPub::AccountRawDistributionWorker) + .to_not have_enqueued_sidekiq_job + end + end + end + end +end