From 26c51cfa07952b39802ce6de4c952c6adf56b748 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 21 Sep 2022 22:46:35 +0200 Subject: [PATCH] Fix various rspec warnings in ReportService tests (#19189) * Fix various rspec warnings in ReportService tests * Add tests to ReportService --- spec/services/report_service_spec.rb | 37 +++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/spec/services/report_service_spec.rb b/spec/services/report_service_spec.rb index ea68b3344..02bc42ac1 100644 --- a/spec/services/report_service_spec.rb +++ b/spec/services/report_service_spec.rb @@ -42,13 +42,44 @@ RSpec.describe ReportService, type: :service do end it 'creates a report' do - is_expected.to change { target_account.targeted_reports.count }.from(0).to(1) + expect { subject.call }.to change { target_account.targeted_reports.count }.from(0).to(1) + end + + it 'attaches the DM to the report' do + subject.call + expect(target_account.targeted_reports.pluck(:status_ids)).to eq [[status.id]] end end context 'when it is not addressed to the reporter' do it 'errors out' do - is_expected.to raise_error + expect { subject.call }.to raise_error(ActiveRecord::RecordNotFound) + end + end + + context 'when the reporter is remote' do + let(:source_account) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/users/1') } + + context 'when it is addressed to the reporter' do + before do + status.mentions.create(account: source_account) + end + + it 'creates a report' do + expect { subject.call }.to change { target_account.targeted_reports.count }.from(0).to(1) + end + + it 'attaches the DM to the report' do + subject.call + expect(target_account.targeted_reports.pluck(:status_ids)).to eq [[status.id]] + end + end + + context 'when it is not addressed to the reporter' do + it 'does not add the DM to the report' do + subject.call + expect(target_account.targeted_reports.pluck(:status_ids)).to eq [[]] + end end end end @@ -67,7 +98,7 @@ RSpec.describe ReportService, type: :service do end it 'does not send an e-mail' do - is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0) + expect { subject.call }.to_not change(ActionMailer::Base.deliveries, :count).from(0) end end end