Fix various rspec warnings in ReportService tests (#19189)

* Fix various rspec warnings in ReportService tests

* Add tests to ReportService
This commit is contained in:
Claire 2022-09-21 22:46:35 +02:00 committed by GitHub
parent 8cf7006d4e
commit 26c51cfa07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 3 deletions

View File

@ -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