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
|
sidekiq_options queue: 'pull', retry: 3
|
||||||
|
|
||||||
def perform(id)
|
def perform(id)
|
||||||
account = Account.find_by(id: id)
|
account = Account.remote.find_by(id: id)
|
||||||
return if account.nil? || account.local?
|
return if account.nil?
|
||||||
|
|
||||||
ActivityPub::FetchRemoteAccountService.new.call(account.uri)
|
ActivityPub::FetchRemoteAccountService.new.call(account.uri)
|
||||||
rescue Mastodon::UnexpectedResponseError => e
|
rescue Mastodon::UnexpectedResponseError => e
|
||||||
|
|||||||
@ -4,13 +4,15 @@ require 'rails_helper'
|
|||||||
|
|
||||||
RSpec.describe RemoteAccountRefreshWorker do
|
RSpec.describe RemoteAccountRefreshWorker do
|
||||||
let(:worker) { described_class.new }
|
let(:worker) { described_class.new }
|
||||||
let(:service) { instance_double(ActivityPub::FetchRemoteAccountService, call: true) }
|
|
||||||
|
|
||||||
describe '#perform' do
|
describe '#perform' do
|
||||||
before { stub_service }
|
before { stub_service }
|
||||||
|
|
||||||
let(:account) { Fabricate(:account, domain: 'host.example') }
|
let(:account) { Fabricate(:account, domain: 'host.example') }
|
||||||
|
|
||||||
|
context 'with a working service' do
|
||||||
|
let(:service) { instance_double(ActivityPub::FetchRemoteAccountService, call: true) }
|
||||||
|
|
||||||
it 'sends the status to the service' do
|
it 'sends the status to the service' do
|
||||||
worker.perform(account.id)
|
worker.perform(account.id)
|
||||||
|
|
||||||
@ -25,9 +27,22 @@ RSpec.describe RemoteAccountRefreshWorker do
|
|||||||
|
|
||||||
it 'returns nil for a local record' do
|
it 'returns nil for a local record' do
|
||||||
account = Fabricate :account, domain: nil
|
account = Fabricate :account, domain: nil
|
||||||
result = worker.perform(account)
|
result = worker.perform(account.id)
|
||||||
expect(result).to be_nil
|
expect(result).to be_nil
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with a failing service' do
|
||||||
|
let(:service) { instance_double(ActivityPub::FetchRemoteAccountService) }
|
||||||
|
let(:response) { instance_double(HTTP::Response, code: 500) }
|
||||||
|
|
||||||
|
before { allow(service).to receive(:call).and_raise(Mastodon::UnexpectedResponseError, response) }
|
||||||
|
|
||||||
|
it 'raises error when service fails' do
|
||||||
|
expect { worker.perform(account.id) }
|
||||||
|
.to raise_error(Mastodon::UnexpectedResponseError)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def stub_service
|
def stub_service
|
||||||
allow(ActivityPub::FetchRemoteAccountService)
|
allow(ActivityPub::FetchRemoteAccountService)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user