2023-03-04 10:56:09 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'rails_helper'
|
|
|
|
|
2024-09-04 01:12:25 -04:00
|
|
|
RSpec.describe RedownloadHeaderWorker do
|
2023-03-04 10:56:09 -05:00
|
|
|
let(:worker) { described_class.new }
|
|
|
|
|
2023-11-17 04:03:46 -05:00
|
|
|
describe '#perform' do
|
|
|
|
it 'returns nil for non-existent record' do
|
|
|
|
result = worker.perform(123_123_123)
|
|
|
|
|
|
|
|
expect(result).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil for suspended account' do
|
|
|
|
account = Fabricate(:account, suspended_at: 10.days.ago)
|
|
|
|
|
|
|
|
expect(worker.perform(account.id)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil with a domain block' do
|
|
|
|
account = Fabricate(:account, domain: 'host.example')
|
|
|
|
Fabricate(:domain_block, domain: account.domain, reject_media: true)
|
|
|
|
|
|
|
|
expect(worker.perform(account.id)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil without an header remote url' do
|
|
|
|
account = Fabricate(:account, header_remote_url: '')
|
|
|
|
|
|
|
|
expect(worker.perform(account.id)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil when header file name is present' do
|
|
|
|
stub_request(:get, 'https://example.host/file').to_return request_fixture('avatar.txt')
|
|
|
|
account = Fabricate(:account, header_remote_url: 'https://example.host/file', header_file_name: 'test.jpg')
|
|
|
|
|
|
|
|
expect(worker.perform(account.id)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'reprocesses a remote header' do
|
|
|
|
stub_request(:get, 'https://example.host/file').to_return request_fixture('avatar.txt')
|
|
|
|
account = Fabricate(:account, header_remote_url: 'https://example.host/file')
|
2024-01-15 08:46:47 -05:00
|
|
|
account.update_column(:header_file_name, nil)
|
2023-11-17 04:03:46 -05:00
|
|
|
|
|
|
|
result = worker.perform(account.id)
|
|
|
|
|
|
|
|
expect(result).to be(true)
|
|
|
|
expect(account.reload.header_file_name).to_not be_nil
|
2023-03-04 10:56:09 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|