Sha256: f033b94c148598a362432d0c640b708ac72a538d9ef7f856c96061dbb2d36060

Contents?: true

Size: 1.92 KB

Versions: 4

Compression:

Stored size: 1.92 KB

Contents

# frozen_string_literal: true

describe Spotlight::AddUploadsFromCsv do
  subject(:job) { described_class.new(data, exhibit, user) }

  let(:exhibit) { FactoryBot.create(:exhibit) }
  let(:user) { FactoryBot.create(:exhibit_curator, exhibit: exhibit) }
  let(:data) do
    [
      { 'url' => 'x' },
      { 'url' => 'y' },
      { 'url' => '~' }
    ]
  end

  let(:resource_x) { instance_double(Spotlight::Resource) }
  let(:resource_y) { instance_double(Spotlight::Resource) }

  before do
    allow(Spotlight::IndexingCompleteMailer).to receive(:documents_indexed).and_return(double(deliver_now: true))
  end

  context 'with empty data' do
    let(:data) { [] }

    it 'sends the user an email after the indexing job is complete' do
      expect(Spotlight::IndexingCompleteMailer).to receive(:documents_indexed).and_return(double(deliver_now: true))
      job.perform_now
    end
  end

  it 'creates uploaded resources for each row of data' do
    upload = FactoryBot.create(:uploaded_resource)
    expect(Spotlight::Resources::Upload).to receive(:new).exactly(3).times.and_return(upload)

    expect(upload).to receive(:build_upload).with(remote_image_url: 'x').and_call_original
    expect(upload).to receive(:build_upload).with(remote_image_url: 'y').and_call_original
    expect(upload).not_to receive(:build_upload).with(remote_image_url: '~')
    expect(upload).to receive(:save_and_index).at_least(:once)

    job.perform_now
  end

  context 'with errors' do
    it 'collects errors uploaded resources for each row of data' do
      allow(Spotlight::IndexingCompleteMailer).to receive(:documents_indexed).and_return(double(deliver_now: true))
      job.perform_now
      expect(Spotlight::IndexingCompleteMailer).to have_received(:documents_indexed).with(
        data, exhibit, user,
        indexed_count: 1,
        errors: { 1 => array_including(match(/relative URI: x/)), 2 => array_including(match(/Upload is invalid/)) }
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
blacklight-spotlight-3.0.0.rc4 spec/jobs/spotlight/add_uploads_from_csv_spec.rb
blacklight-spotlight-3.0.0.rc3 spec/jobs/spotlight/add_uploads_from_csv_spec.rb
blacklight-spotlight-3.0.0.rc2 spec/jobs/spotlight/add_uploads_from_csv_spec.rb
blacklight-spotlight-3.0.0.rc1 spec/jobs/spotlight/add_uploads_from_csv_spec.rb