mirror of
https://git.kescher.at/CatCatNya/catstodon.git
synced 2024-12-05 03:19:04 +01:00
e38fc319dc
* Change account and user fabricators to simplify and improve tests - `Fabricate(:account)` implicitly fabricates an associated `user` if no `domain` attribute is given (an account with `domain: nil` is considered a local account, but no user record was created), unless `user: nil` is passed - `Fabricate(:account, user: Fabricate(:user))` should still be possible but is discouraged. * Fix and refactor tests - avoid passing unneeded attributes to `Fabricate(:user)` or `Fabricate(:account)` - avoid embedding `Fabricate(:user)` into a `Fabricate(:account)` or the other way around - prefer `Fabricate(:user, account_attributes: …)` to `Fabricate(:user, account: Fabricate(:account, …)` - also, some tests were using remote accounts with local user records, which is not representative of production code.
48 lines
1.5 KiB
Ruby
48 lines
1.5 KiB
Ruby
require 'rails_helper'
|
|
|
|
RSpec.describe ReportService, type: :service do
|
|
subject { described_class.new }
|
|
|
|
let(:source_account) { Fabricate(:account) }
|
|
|
|
context 'for a remote account' do
|
|
let(:remote_account) { Fabricate(:account, domain: 'example.com', protocol: :activitypub, inbox_url: 'http://example.com/inbox') }
|
|
|
|
before do
|
|
stub_request(:post, 'http://example.com/inbox').to_return(status: 200)
|
|
end
|
|
|
|
it 'sends ActivityPub payload when forward is true' do
|
|
subject.call(source_account, remote_account, forward: true)
|
|
expect(a_request(:post, 'http://example.com/inbox')).to have_been_made
|
|
end
|
|
|
|
it 'does not send anything when forward is false' do
|
|
subject.call(source_account, remote_account, forward: false)
|
|
expect(a_request(:post, 'http://example.com/inbox')).to_not have_been_made
|
|
end
|
|
|
|
it 'has an uri' do
|
|
report = subject.call(source_account, remote_account, forward: true)
|
|
expect(report.uri).to_not be_nil
|
|
end
|
|
end
|
|
|
|
context 'when other reports already exist for the same target' do
|
|
let!(:target_account) { Fabricate(:account) }
|
|
let!(:other_report) { Fabricate(:report, target_account: target_account) }
|
|
|
|
subject do
|
|
-> { described_class.new.call(source_account, target_account) }
|
|
end
|
|
|
|
before do
|
|
ActionMailer::Base.deliveries.clear
|
|
source_account.user.settings.notification_emails['report'] = true
|
|
end
|
|
|
|
it 'does not send an e-mail' do
|
|
is_expected.to_not change(ActionMailer::Base.deliveries, :count).from(0)
|
|
end
|
|
end
|
|
end
|