2023-11-16 09:36:59 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 01:12:25 -04:00
|
|
|
RSpec.describe AccountRefreshWorker do
|
2023-11-16 09:36:59 -05:00
|
|
|
let(:worker) { described_class.new }
|
|
|
|
let(:service) { instance_double(ResolveAccountService, call: true) }
|
|
|
|
|
|
|
|
describe '#perform' do
|
2024-10-23 03:50:20 -04:00
|
|
|
before { stub_service }
|
2023-11-16 09:36:59 -05:00
|
|
|
|
|
|
|
context 'when account does not exist' do
|
|
|
|
it 'returns immediately without processing' do
|
|
|
|
worker.perform(123_123_123)
|
|
|
|
|
|
|
|
expect(service).to_not have_received(:call)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when account exists' do
|
|
|
|
context 'when account does not need refreshing' do
|
|
|
|
let(:account) { Fabricate(:account, last_webfingered_at: recent_webfinger_at) }
|
|
|
|
|
|
|
|
it 'returns immediately without processing' do
|
|
|
|
worker.perform(account.id)
|
|
|
|
|
|
|
|
expect(service).to_not have_received(:call)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when account needs refreshing' do
|
|
|
|
let(:account) { Fabricate(:account, last_webfingered_at: outdated_webfinger_at) }
|
|
|
|
|
|
|
|
it 'schedules an account update' do
|
|
|
|
worker.perform(account.id)
|
|
|
|
|
|
|
|
expect(service).to have_received(:call)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def recent_webfinger_at
|
|
|
|
(Account::BACKGROUND_REFRESH_INTERVAL - 3.days).ago
|
|
|
|
end
|
|
|
|
|
|
|
|
def outdated_webfinger_at
|
|
|
|
(Account::BACKGROUND_REFRESH_INTERVAL + 3.days).ago
|
|
|
|
end
|
|
|
|
end
|
2024-10-23 03:50:20 -04:00
|
|
|
|
|
|
|
def stub_service
|
|
|
|
allow(ResolveAccountService)
|
|
|
|
.to receive(:new)
|
|
|
|
.and_return(service)
|
|
|
|
end
|
2023-11-16 09:36:59 -05:00
|
|
|
end
|
|
|
|
end
|