You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB

  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. end
  19. context 'when other reports already exist for the same target' do
  20. let!(:target_account) { Fabricate(:account) }
  21. let!(:other_report) { Fabricate(:report, target_account: target_account) }
  22. subject do
  23. -> { described_class.new.call(source_account, target_account) }
  24. end
  25. before do
  26. ActionMailer::Base.deliveries.clear
  27. source_account.user.settings.notification_emails['report'] = true
  28. end
  29. it 'does not send an e-mail' do
  30. is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
  31. end
  32. end
  33. end