Skip to content

Commit

Permalink
Increasing test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Jun 22, 2018
1 parent 27057ca commit db43346
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions spec/commands/migrate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,26 +74,66 @@

before do
allow(response).to receive(:body).and_return(manifest.to_json)
allow(response).to receive(:success?).and_return(true)
allow(Faraday).to receive(:get).and_return(response)

allow(exhibit_thumbnail).to receive(:document).and_return(document)
allow(exhibit_thumbnail).to receive(:iiif_manifest_url=)
allow(exhibit_thumbnail).to receive(:iiif_canvas_id=)
allow(exhibit_thumbnail).to receive(:iiif_tilesource=)
allow(exhibit_thumbnail).to receive(:save)
allow(Spotlight::ExhibitThumbnail).to receive(:all).and_return(exhibit_thumbnails)

command.exhibit_thumbnails
end

it "migrates the Spotlight::ExhibitThumbnail IIIF Manifests" do
allow(response).to receive(:success?).and_return(true)
allow(Faraday).to receive(:get).and_return(response)

command.exhibit_thumbnails

expect(exhibit_thumbnail).to have_received(:iiif_manifest_url=).with("https://figgy.princeton.edu/concern/scanned_resources/d917e0d6-2894-4d1e-939b-93fdc0796c96/manifest")
expect(exhibit_thumbnail).to have_received(:iiif_canvas_id=).with("https://figgy.princeton.edu/concern/scanned_resources/fbc2d7b3-164b-4458-b2c3-9007c2ed08a5/manifest/canvas/ac8a822f-60db-4c97-a79e-2ed1b3676072")
expect(exhibit_thumbnail).to have_received(:iiif_tilesource=).with("https://libimages1.princeton.edu/loris/figgy_prod/3f%2F26%2F5b%2F3f265b23fbce4298b251d84c19439396%2Fintermediate_file.jp2")

expect(exhibit_thumbnail).to have_received(:save)
end

context "when the request for the IIIF Manifest results in a server-side error" do
let(:logger) { instance_double(ActiveSupport::Logger) }

before do

allow(logger).to receive(:debug)
allow(logger).to receive(:warn)
allow(Rails).to receive(:logger).and_return(logger)
end

it "does not migrate the Spotlight::ExhibitThumbnail and logs a warning" do
allow(response).to receive(:success?).and_return(false)
allow(Faraday).to receive(:get).and_return(response)

command.exhibit_thumbnails

expect(exhibit_thumbnail).not_to have_received(:save)
expect(logger).to have_received(:warn).with("Failed to get https://figgy.princeton.edu/concern/scanned_resources/d917e0d6-2894-4d1e-939b-93fdc0796c96/manifest")
end
end

context "when the request for the IIIF Manifest fails" do
let(:logger) { instance_double(ActiveSupport::Logger) }

before do
allow(Faraday).to receive(:get).and_raise(Faraday::Error::ConnectionFailed.new("Connection failure"))
allow(logger).to receive(:debug)
allow(logger).to receive(:warn)
allow(Rails).to receive(:logger).and_return(logger)
end

it "does not migrate the Spotlight::ExhibitThumbnail and logs a warning" do
command.exhibit_thumbnails

expect(exhibit_thumbnail).not_to have_received(:save)
expect(logger).to have_received(:warn).with("Failed to get https://figgy.princeton.edu/concern/scanned_resources/d917e0d6-2894-4d1e-939b-93fdc0796c96/manifest: Connection failure")
end
end
end

after do
Expand Down

0 comments on commit db43346

Please sign in to comment.