Add failing service case to remote account refresh worker spec (#38922)
This commit is contained in:
parent
f6f45c43a9
commit
65b7ddb3e8
@ -8,8 +8,8 @@ class RemoteAccountRefreshWorker
|
||||
sidekiq_options queue: 'pull', retry: 3
|
||||
|
||||
def perform(id)
|
||||
account = Account.find_by(id: id)
|
||||
return if account.nil? || account.local?
|
||||
account = Account.remote.find_by(id: id)
|
||||
return if account.nil?
|
||||
|
||||
ActivityPub::FetchRemoteAccountService.new.call(account.uri)
|
||||
rescue Mastodon::UnexpectedResponseError => e
|
||||
|
||||
@ -4,29 +4,44 @@ require 'rails_helper'
|
||||
|
||||
RSpec.describe RemoteAccountRefreshWorker do
|
||||
let(:worker) { described_class.new }
|
||||
let(:service) { instance_double(ActivityPub::FetchRemoteAccountService, call: true) }
|
||||
|
||||
describe '#perform' do
|
||||
before { stub_service }
|
||||
|
||||
let(:account) { Fabricate(:account, domain: 'host.example') }
|
||||
|
||||
it 'sends the status to the service' do
|
||||
worker.perform(account.id)
|
||||
context 'with a working service' do
|
||||
let(:service) { instance_double(ActivityPub::FetchRemoteAccountService, call: true) }
|
||||
|
||||
expect(service).to have_received(:call).with(account.uri)
|
||||
it 'sends the status to the service' do
|
||||
worker.perform(account.id)
|
||||
|
||||
expect(service).to have_received(:call).with(account.uri)
|
||||
end
|
||||
|
||||
it 'returns nil for non-existent record' do
|
||||
result = worker.perform(123_123_123)
|
||||
|
||||
expect(result).to be_nil
|
||||
end
|
||||
|
||||
it 'returns nil for a local record' do
|
||||
account = Fabricate :account, domain: nil
|
||||
result = worker.perform(account.id)
|
||||
expect(result).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it 'returns nil for non-existent record' do
|
||||
result = worker.perform(123_123_123)
|
||||
context 'with a failing service' do
|
||||
let(:service) { instance_double(ActivityPub::FetchRemoteAccountService) }
|
||||
let(:response) { instance_double(HTTP::Response, code: 500) }
|
||||
|
||||
expect(result).to be_nil
|
||||
end
|
||||
before { allow(service).to receive(:call).and_raise(Mastodon::UnexpectedResponseError, response) }
|
||||
|
||||
it 'returns nil for a local record' do
|
||||
account = Fabricate :account, domain: nil
|
||||
result = worker.perform(account)
|
||||
expect(result).to be_nil
|
||||
it 'raises error when service fails' do
|
||||
expect { worker.perform(account.id) }
|
||||
.to raise_error(Mastodon::UnexpectedResponseError)
|
||||
end
|
||||
end
|
||||
|
||||
def stub_service
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user