From 8f61e32569ca2ad68ec26b391c5c7f6ee6a333a8 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Wed, 21 Feb 2024 12:12:31 -0500 Subject: [PATCH] Add basic coverage for `AppealService` class (#29322) --- spec/services/appeal_service_spec.rb | 40 ++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 spec/services/appeal_service_spec.rb diff --git a/spec/services/appeal_service_spec.rb b/spec/services/appeal_service_spec.rb new file mode 100644 index 0000000000..10c0f148dc --- /dev/null +++ b/spec/services/appeal_service_spec.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +require 'rails_helper' + +RSpec.describe AppealService do + describe '#call' do + let!(:admin) { Fabricate(:user, role: UserRole.find_by(name: 'Admin')) } + + context 'with an existing strike' do + let(:strike) { Fabricate(:account_warning) } + let(:text) { 'Appeal text' } + + it 'creates an appeal and notifies staff' do + emails = capture_emails { subject.call(strike, text) } + + expect(Appeal.last) + .to have_attributes( + strike: strike, + text: text, + account: strike.target_account + ) + + expect(emails.size) + .to eq(1) + + expect(emails.first) + .to have_attributes( + to: contain_exactly(admin.email), + subject: eq( + I18n.t( + 'admin_mailer.new_appeal.subject', + username: strike.target_account.acct, + instance: Rails.configuration.x.local_domain + ) + ) + ) + end + end + end +end