account_refresh_worker_spec.rb 1.4 KB

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