report_service_spec.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. require 'rails_helper'
  2. RSpec.describe ReportService, type: :service do
  3. subject { described_class.new }
  4. let(:source_account) { Fabricate(:user).account }
  5. context 'for a remote account' do
  6. let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
  7. before do
  8. stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
  9. end
  10. it 'sends ActivityPub payload when forward is true' do
  11. subject.call(source_account, remote_account, forward: true)
  12. expect(a_request(:post, 'http://example.com/inbox')).to have_been_made
  13. end
  14. it 'does not send anything when forward is false' do
  15. subject.call(source_account, remote_account, forward: false)
  16. expect(a_request(:post, 'http://example.com/inbox')).to_not have_been_made
  17. end
  18. it 'has an uri' do
  19. report = subject.call(source_account, remote_account, forward: true)
  20. expect(report.uri).to_not be_nil
  21. end
  22. end
  23. context 'when other reports already exist for the same target' do
  24. let!(:target_account) { Fabricate(:account) }
  25. let!(:other_report) { Fabricate(:report, target_account: target_account) }
  26. subject do
  27. -> { described_class.new.call(source_account, target_account) }
  28. end
  29. before do
  30. ActionMailer::Base.deliveries.clear
  31. source_account.user.settings.notification_emails['report'] = true
  32. end
  33. it 'does not send an e-mail' do
  34. is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
  35. end
  36. end
  37. end