Skip to content

Commit

Permalink
Merge 35b3a56 into b414faf
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Sep 10, 2019
2 parents b414faf + 35b3a56 commit 7d64953
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 41 deletions.
9 changes: 4 additions & 5 deletions .rubocop_todo.yml
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2019-09-05 13:23:58 -0500 using RuboCop version 0.74.0.
# on 2019-09-10 10:01:59 -0500 using RuboCop version 0.74.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand Down Expand Up @@ -30,7 +30,7 @@ Lint/UriEscapeUnescape:
- 'app/controllers/sdr_controller.rb'
- 'spec/controllers/sdr_controller_spec.rb'

# Offense count: 23
# Offense count: 22
Metrics/AbcSize:
Max: 87

Expand Down Expand Up @@ -90,8 +90,8 @@ Naming/VariableNumber:
# Offense count: 25
RSpec/AnyInstance:
Exclude:
- 'spec/controllers/objects_controller_spec.rb'
- 'spec/dor/update_marc_record_service_spec.rb'
- 'spec/requests/notify_goobi_spec.rb'
- 'spec/services/public_xml_service_spec.rb'
- 'spec/services/publish_metadata_service_spec.rb'
- 'spec/services/registration_service_spec.rb'
Expand Down Expand Up @@ -135,13 +135,12 @@ RSpec/DescribedClass:
- 'spec/dor/service_item_spec.rb'
- 'spec/dor/update_marc_record_service_spec.rb'

# Offense count: 8
# Offense count: 7
# Cop supports --auto-correct.
RSpec/EmptyLineAfterFinalLet:
Exclude:
- 'spec/controllers/sdr_controller_spec.rb'
- 'spec/dor/update_marc_record_service_spec.rb'
- 'spec/models/symphony_reader_spec.rb'

# Offense count: 1
# Cop supports --auto-correct.
Expand Down
36 changes: 0 additions & 36 deletions spec/controllers/objects_controller_spec.rb
Expand Up @@ -87,40 +87,4 @@
end
end
end

describe '/notify_goobi' do
let(:fake_request) { "<stanfordCreationRequest><objectId>#{item.pid}</objectId></stanfordCreationRequest>" }

before do
allow_any_instance_of(Dor::Goobi).to receive(:xml_request).and_return fake_request
end

context 'when it is successful' do
before do
stub_request(:post, Settings.goobi.url)
.to_return(body: fake_request,
headers: { 'Content-Type' => 'application/xml' },
status: 201)
end

it 'notifies goobi of a new registration by making a web service call' do
post :notify_goobi, params: { id: item.pid }
expect(response.status).to eq(201)
end
end

context 'when it is a conflict' do
before do
stub_request(:post, Settings.goobi.url)
.to_return(body: 'conflict',
status: 409)
end

it 'returns the conflict code' do
post :notify_goobi, params: { id: item.pid }
expect(response.status).to eq(409)
expect(response.body).to eq('conflict')
end
end
end
end
44 changes: 44 additions & 0 deletions spec/requests/notify_goobi_spec.rb
@@ -0,0 +1,44 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe 'Notify Goobi' do
let(:payload) { { sub: 'argo' } }
let(:jwt) { JWT.encode(payload, Settings.dor.hmac_secret, 'HS256') }
let(:object) { Dor::Item.new(pid: 'druid:1234') }
let(:fake_request) { "<stanfordCreationRequest><objectId>#{object.pid}</objectId></stanfordCreationRequest>" }

before do
allow(Dor).to receive(:find).and_return(object)
allow_any_instance_of(Dor::Goobi).to receive(:xml_request).and_return fake_request
end

context 'when it is successful' do
before do
stub_request(:post, Settings.goobi.url)
.to_return(body: fake_request,
headers: { 'Content-Type' => 'application/xml' },
status: 201)
end

it 'notifies goobi of a new registration by making a web service call' do
post '/v1/objects/druid:1234/notify_goobi', headers: { 'X-Auth' => "Bearer #{jwt}" }

expect(response.status).to eq(201)
end
end

context 'when it is a conflict' do
before do
stub_request(:post, Settings.goobi.url)
.to_return(body: 'conflict',
status: 409)
end

it 'returns the conflict code' do
post '/v1/objects/druid:1234/notify_goobi', headers: { 'X-Auth' => "Bearer #{jwt}" }
expect(response.status).to eq(409)
expect(response.body).to eq('conflict')
end
end
end

0 comments on commit 7d64953

Please sign in to comment.