Add failing service case to remote account refresh worker spec (#38922)

This commit is contained in:
Matt Jankowski 2026-05-06 11:10:12 -04:00 committed by GitHub
parent f6f45c43a9
commit 65b7ddb3e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 14 deletions

View File

@ -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

View File

@ -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