redownload_header_worker_spec.rb 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe RedownloadHeaderWorker do
  4. let(:worker) { described_class.new }
  5. describe '#perform' do
  6. it 'returns nil for non-existent record' do
  7. result = worker.perform(123_123_123)
  8. expect(result).to be_nil
  9. end
  10. it 'returns nil for suspended account' do
  11. account = Fabricate(:account, suspended_at: 10.days.ago)
  12. expect(worker.perform(account.id)).to be_nil
  13. end
  14. it 'returns nil with a domain block' do
  15. account = Fabricate(:account, domain: 'host.example')
  16. Fabricate(:domain_block, domain: account.domain, reject_media: true)
  17. expect(worker.perform(account.id)).to be_nil
  18. end
  19. it 'returns nil without an header remote url' do
  20. account = Fabricate(:account, header_remote_url: '')
  21. expect(worker.perform(account.id)).to be_nil
  22. end
  23. it 'returns nil when header file name is present' do
  24. stub_request(:get, 'https://example.host/file').to_return request_fixture('avatar.txt')
  25. account = Fabricate(:account, header_remote_url: 'https://example.host/file', header_file_name: 'test.jpg')
  26. expect(worker.perform(account.id)).to be_nil
  27. end
  28. it 'reprocesses a remote header' do
  29. stub_request(:get, 'https://example.host/file').to_return request_fixture('avatar.txt')
  30. account = Fabricate(:account, header_remote_url: 'https://example.host/file')
  31. account.update_column(:header_file_name, nil)
  32. result = worker.perform(account.id)
  33. expect(result).to be(true)
  34. expect(account.reload.header_file_name).to_not be_nil
  35. end
  36. end
  37. end