Skip to content

Commit

Permalink
Merge 99e0168 into 417c2e9
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 10, 2019
2 parents 417c2e9 + 99e0168 commit c5a5dc7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 19 deletions.
19 changes: 0 additions & 19 deletions spec/controllers/objects_controller_spec.rb
Expand Up @@ -69,25 +69,6 @@
end
end

describe '/publish' do
it 'calls PublishMetadataService and returns 201' do
expect(PublishMetadataService).to receive(:publish).with(item)
post :publish, params: { id: item.pid }
expect(response.status).to eq(201)
end

context 'with bad metadata' do
let(:error_message) { "DublinCoreService#ng_xml produced incorrect xml (no children):\n<xml/>" }

it 'returns a 500 error' do
allow(PublishMetadataService).to receive(:publish).and_raise(DublinCoreService::CrosswalkError, error_message)
post :publish, params: { id: item.pid }
expect(response.status).to eq(500)
expect(response.body).to eq(error_message)
end
end
end

describe '/update_marc_record' do
it 'updates a marc record' do
# TODO: add some more expectations
Expand Down
40 changes: 40 additions & 0 deletions spec/requests/publish_object_spec.rb
@@ -0,0 +1,40 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Publish object' do
let(:payload) { { sub: 'argo' } }
let(:jwt) { JWT.encode(payload, Settings.dor.hmac_secret, 'HS256') }
let(:object) { Dor::Item.new(pid: 'druid:1234') }

before do
allow(Dor).to receive(:find).and_return(object)
end

context 'with bad metadata' do
let(:error_message) { "DublinCoreService#ng_xml produced incorrect xml (no children):\n<xml/>" }

before do
allow(PublishMetadataService).to receive(:publish).and_raise(DublinCoreService::CrosswalkError, error_message)
end

it 'returns a 409 error with location header' do
post '/v1/objects/druid:1234/publish', headers: { 'X-Auth' => "Bearer #{jwt}" }
expect(response.status).to eq(500)
expect(response.body).to eq(error_message)
end
end

context 'when the request is successful' do
before do
allow(PublishMetadataService).to receive(:publish)
end

it 'calls PublishMetadataService and returns 201' do
post '/v1/objects/druid:1234/publish', headers: { 'X-Auth' => "Bearer #{jwt}" }

expect(PublishMetadataService).to have_received(:publish)
expect(response.status).to eq(201)
end
end
end

0 comments on commit c5a5dc7

Please sign in to comment.