From 35b3a56c9e3738ee85e1e1f8b66f014af18a4c30 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Tue, 10 Sep 2019 10:02:31 -0500 Subject: [PATCH] Extract notify goobi spec to a request spec Controller specs are deprecated --- .rubocop_todo.yml | 9 ++--- spec/controllers/objects_controller_spec.rb | 36 ----------------- spec/requests/notify_goobi_spec.rb | 44 +++++++++++++++++++++ 3 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 spec/requests/notify_goobi_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 436ba86c17..da30d5d90b 100644 --- a/.rubocop_todo.yml +++ b/.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 @@ -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 @@ -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' @@ -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. diff --git a/spec/controllers/objects_controller_spec.rb b/spec/controllers/objects_controller_spec.rb index 612dbdf03c..8421faa9d7 100644 --- a/spec/controllers/objects_controller_spec.rb +++ b/spec/controllers/objects_controller_spec.rb @@ -87,40 +87,4 @@ end end end - - describe '/notify_goobi' do - let(:fake_request) { "#{item.pid}" } - - 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 diff --git a/spec/requests/notify_goobi_spec.rb b/spec/requests/notify_goobi_spec.rb new file mode 100644 index 0000000000..55411439db --- /dev/null +++ b/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) { "#{object.pid}" } + + 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