account_refresh_worker_spec.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe AccountRefreshWorker do
  4. let(:worker) { described_class.new }
  5. let(:service) { instance_double(ResolveAccountService, call: true) }
  6. describe '#perform' do
  7. before do
  8. allow(ResolveAccountService).to receive(:new).and_return(service)
  9. end
  10. context 'when account does not exist' do
  11. it 'returns immediately without processing' do
  12. worker.perform(123_123_123)
  13. expect(service).to_not have_received(:call)
  14. end
  15. end
  16. context 'when account exists' do
  17. context 'when account does not need refreshing' do
  18. let(:account) { Fabricate(:account, last_webfingered_at: recent_webfinger_at) }
  19. it 'returns immediately without processing' do
  20. worker.perform(account.id)
  21. expect(service).to_not have_received(:call)
  22. end
  23. end
  24. context 'when account needs refreshing' do
  25. let(:account) { Fabricate(:account, last_webfingered_at: outdated_webfinger_at) }
  26. it 'schedules an account update' do
  27. worker.perform(account.id)
  28. expect(service).to have_received(:call)
  29. end
  30. end
  31. def recent_webfinger_at
  32. (Account::BACKGROUND_REFRESH_INTERVAL - 3.days).ago
  33. end
  34. def outdated_webfinger_at
  35. (Account::BACKGROUND_REFRESH_INTERVAL + 3.days).ago
  36. end
  37. end
  38. end
  39. end