From 292459975c8f739ca42f2ca458ca292b70bc96bd Mon Sep 17 00:00:00 2001 From: Max Kadel Date: Wed, 3 May 2023 16:09:17 -0400 Subject: [PATCH] Add helper method to stub single holding locations - Move fixture files for ease of stubbing --- spec/features/login_account_spec.rb | 12 ++++-------- spec/features/requests/request_spec.rb | 12 +++--------- .../RES_SHARE_OUT_RS_REQ.json | 19 +++++++++++++++++++ .../engineer_res.json} | 0 .../engineer_stacks.json} | 0 .../mudd_stacks.json} | 0 .../rare_map.json} | 0 .../rare_num.json} | 0 .../recap_pa.json} | 0 .../scsbcul.json} | 0 spec/models/concerns/requests/scsb_spec.rb | 4 +--- spec/models/requests/request_spec.rb | 10 +++------- spec/models/requests/requestable_spec.rb | 4 +--- spec/support/webmock_stubs.rb | 6 ++++++ 14 files changed, 37 insertions(+), 30 deletions(-) create mode 100644 spec/fixtures/holding_locations/RES_SHARE_OUT_RS_REQ.json rename spec/fixtures/{bibdata/engineer_res_holding_locations.json => holding_locations/engineer_res.json} (100%) rename spec/fixtures/{bibdata/engineer_stacks_holding_locations.json => holding_locations/engineer_stacks.json} (100%) rename spec/fixtures/{bibdata/mudd_stacks_holding_locations.json => holding_locations/mudd_stacks.json} (100%) rename spec/fixtures/{bibdata/rare_map_holding_locations.json => holding_locations/rare_map.json} (100%) rename spec/fixtures/{bibdata/numismatics_holding_locations.json => holding_locations/rare_num.json} (100%) rename spec/fixtures/{bibdata/recap_pa_holding_locations.json => holding_locations/recap_pa.json} (100%) rename spec/fixtures/{bibdata/scsbcul_holding_locations.json => holding_locations/scsbcul.json} (100%) diff --git a/spec/features/login_account_spec.rb b/spec/features/login_account_spec.rb index 5b35e1d67..a40befc6d 100644 --- a/spec/features/login_account_spec.rb +++ b/spec/features/login_account_spec.rb @@ -97,8 +97,7 @@ stub_delivery_locations stub_request(:get, "#{Requests::Config[:pulsearch_base]}/catalog/SCSB-2143785/raw") .to_return(status: 200, body: fixture('/scsb/SCSB-2143785.json'), headers: {}) - stub_request(:get, "#{Requests::Config[:bibdata_base]}/locations/holding_locations/scsbcul.json") - .to_return(status: 200, body: fixture('/bibdata/scsbcul_holding_locations.json')) + stub_single_holding_location('scsbcul') stub_request(:get, "#{Requests::Config[:bibdata_base]}/bibliographic/SCSB-2143785/holdings/2110046/availability.json") .to_return(status: 200) end @@ -153,8 +152,7 @@ before do stub_request(:get, "#{Requests::Config[:pulsearch_base]}/catalog/coin-1167/raw") .to_return(status: 200, body: fixture('/numismatics/coin-1167.json'), headers: {}) - stub_request(:get, "#{Requests::Config[:bibdata_base]}/locations/holding_locations/rare$num.json") - .to_return(status: 200, body: fixture('/bibdata/numismatics_holding_locations.json')) + stub_single_holding_location('rare$num') end it 'does not require authentication', js: true do @@ -168,8 +166,7 @@ before do stub_request(:get, "#{Requests::Config[:pulsearch_base]}/catalog/dsp01tq57ns24j/raw") .to_return(status: 200, body: fixture('/theses_and_dissertations/dsp01tq57ns24j.json'), headers: {}) - stub_request(:get, "#{Requests::Config[:bibdata_base]}/locations/holding_locations/mudd$stacks.json") - .to_return(status: 200, body: fixture('/bibdata/mudd_stacks_holding_locations.json')) + stub_single_holding_location('mudd$stacks') end it 'does not require authentication', js: true do visit "/catalog/dsp01tq57ns24j" @@ -185,8 +182,7 @@ before do stub_request(:get, "#{Requests::Config[:pulsearch_base]}/catalog/99496133506421/raw") .to_return(status: 200, body: fixture('/alma/99496133506421.json'), headers: {}) - stub_request(:get, "#{Requests::Config[:bibdata_base]}/locations/holding_locations/rare$map.json") - .to_return(status: 200, body: fixture('/bibdata/rare_map_holding_locations.json')) + stub_single_holding_location('rare$map') stub_request(:get, "#{Requests::Config[:bibdata_base]}/bibliographic/99496133506421/holdings/22745123330006421/availability.json") .to_return(status: 200, body: availability) end diff --git a/spec/features/requests/request_spec.rb b/spec/features/requests/request_spec.rb index f08144e3d..dd6de6366 100644 --- a/spec/features/requests/request_spec.rb +++ b/spec/features/requests/request_spec.rb @@ -1727,14 +1727,10 @@ patron: } end - let(:stacks_holding_location_info) { File.open('spec/fixtures/bibdata/engineer_stacks_holding_locations.json') } - let(:res_holding_location_info) { File.open('spec/fixtures/bibdata/engineer_res_holding_locations.json') } before do - stub_request(:get, 'https://bibdata-staging.princeton.edu/locations/holding_locations/engineer$stacks.json') - .to_return(status: 200, body: stacks_holding_location_info) - stub_request(:get, 'https://bibdata-staging.princeton.edu/locations/holding_locations/engineer$res.json') - .to_return(status: 200, body: res_holding_location_info) + stub_single_holding_location('engineer$stacks') + stub_single_holding_location('engineer$res') stub_request(:get, bibdata_availability_url) .to_return(status: 200, body: bibdata_availability_response) stub_request(:get, 'https://catalog.princeton.edu/catalog/9960102253506421/raw') @@ -1766,7 +1762,6 @@ patron: } end - let(:holding_location_info) { File.open('spec/fixtures/bibdata/recap_pa_holding_locations.json') } let(:first_item) { request_scsb.items['22511126440006421'].first } before do @@ -1775,8 +1770,7 @@ .to_return(status: 200, body: bibdata_availability_response) stub_request(:get, 'https://catalog.princeton.edu/catalog/99122304923506421/raw') .to_return(status: 200, body: File.read('spec/fixtures/raw_99122304923506421.json')) - stub_request(:get, 'https://bibdata-staging.princeton.edu/locations/holding_locations/recap$pa.json') - .to_return(status: 200, body: holding_location_info) + stub_single_holding_location('recap$pa') stub_request(:get, "#{Requests::Config[:bibdata_base]}/patron/#{user.uid}?ldap=true") .to_return(status: 200, body: valid_patron_response, headers: {}) login_as user diff --git a/spec/fixtures/holding_locations/RES_SHARE_OUT_RS_REQ.json b/spec/fixtures/holding_locations/RES_SHARE_OUT_RS_REQ.json new file mode 100644 index 000000000..53cb88c9f --- /dev/null +++ b/spec/fixtures/holding_locations/RES_SHARE_OUT_RS_REQ.json @@ -0,0 +1,19 @@ +{ + "label": "Borrowing Resource Sharing Requests", + "code": "RES_SHARE$OUT_RS_REQ", + "aeon_location": false, + "recap_electronic_delivery_location": false, + "open": true, + "requestable": true, + "always_requestable": false, + "circulates": true, + "remote_storage": "", + "fulfillment_unit": "RES_FU", + "library": { + "label": "Resource Sharing Library", + "code": "RES_SHARE", + "order": 0 + }, + "holding_library": null, + "delivery_locations": [] +} diff --git a/spec/fixtures/bibdata/engineer_res_holding_locations.json b/spec/fixtures/holding_locations/engineer_res.json similarity index 100% rename from spec/fixtures/bibdata/engineer_res_holding_locations.json rename to spec/fixtures/holding_locations/engineer_res.json diff --git a/spec/fixtures/bibdata/engineer_stacks_holding_locations.json b/spec/fixtures/holding_locations/engineer_stacks.json similarity index 100% rename from spec/fixtures/bibdata/engineer_stacks_holding_locations.json rename to spec/fixtures/holding_locations/engineer_stacks.json diff --git a/spec/fixtures/bibdata/mudd_stacks_holding_locations.json b/spec/fixtures/holding_locations/mudd_stacks.json similarity index 100% rename from spec/fixtures/bibdata/mudd_stacks_holding_locations.json rename to spec/fixtures/holding_locations/mudd_stacks.json diff --git a/spec/fixtures/bibdata/rare_map_holding_locations.json b/spec/fixtures/holding_locations/rare_map.json similarity index 100% rename from spec/fixtures/bibdata/rare_map_holding_locations.json rename to spec/fixtures/holding_locations/rare_map.json diff --git a/spec/fixtures/bibdata/numismatics_holding_locations.json b/spec/fixtures/holding_locations/rare_num.json similarity index 100% rename from spec/fixtures/bibdata/numismatics_holding_locations.json rename to spec/fixtures/holding_locations/rare_num.json diff --git a/spec/fixtures/bibdata/recap_pa_holding_locations.json b/spec/fixtures/holding_locations/recap_pa.json similarity index 100% rename from spec/fixtures/bibdata/recap_pa_holding_locations.json rename to spec/fixtures/holding_locations/recap_pa.json diff --git a/spec/fixtures/bibdata/scsbcul_holding_locations.json b/spec/fixtures/holding_locations/scsbcul.json similarity index 100% rename from spec/fixtures/bibdata/scsbcul_holding_locations.json rename to spec/fixtures/holding_locations/scsbcul.json diff --git a/spec/models/concerns/requests/scsb_spec.rb b/spec/models/concerns/requests/scsb_spec.rb index c56efb11a..0fa7cca04 100644 --- a/spec/models/concerns/requests/scsb_spec.rb +++ b/spec/models/concerns/requests/scsb_spec.rb @@ -50,17 +50,15 @@ patron: } end - let(:holding_location_info) { File.open('spec/fixtures/bibdata/recap_pa_holding_locations.json') } let(:first_item) { request_scsb.items['22511126440006421'].first } before do + stub_single_holding_location('recap$pa') stub_scsb_availability(bib_id: "99122304923506421", institution_id: "PUL", barcode: nil, item_availability_status: nil, error_message: "Bib Id doesn't exist in SCSB database.") stub_request(:get, bibdata_availability_url) .to_return(status: 200, body: bibdata_availability_response) stub_request(:get, 'https://catalog.princeton.edu/catalog/99122304923506421/raw') .to_return(status: 200, body: File.read('spec/fixtures/raw_99122304923506421.json')) - stub_request(:get, 'https://bibdata-staging.princeton.edu/locations/holding_locations/recap$pa.json') - .to_return(status: 200, body: holding_location_info) end it 'is in process' do diff --git a/spec/models/requests/request_spec.rb b/spec/models/requests/request_spec.rb index 7be92e496..82093dcd5 100644 --- a/spec/models/requests/request_spec.rb +++ b/spec/models/requests/request_spec.rb @@ -33,14 +33,10 @@ let(:user) { FactoryBot.create(:user) } let(:bibdata_availability_url) { 'https://bibdata-staging.princeton.edu/bibliographic/9960102253506421/holdings/22548491940006421/availability.json' } let(:bibdata_availability_response) { File.open('spec/fixtures/bibdata/9960102253506421_availability.json') } - let(:stacks_holding_location_info) { File.open('spec/fixtures/bibdata/engineer_stacks_holding_locations.json') } - let(:res_holding_location_info) { File.open('spec/fixtures/bibdata/engineer_res_holding_locations.json') } before do - stub_request(:get, 'https://bibdata-staging.princeton.edu/locations/holding_locations/engineer$stacks.json') - .to_return(status: 200, body: stacks_holding_location_info) - stub_request(:get, 'https://bibdata-staging.princeton.edu/locations/holding_locations/engineer$res.json') - .to_return(status: 200, body: res_holding_location_info) + stub_single_holding_location('engineer$stacks') + stub_single_holding_location('engineer$res') stub_request(:get, bibdata_availability_url) .to_return(status: 200, body: bibdata_availability_response) stub_request(:get, 'https://catalog.princeton.edu/catalog/9960102253506421/raw') @@ -554,7 +550,7 @@ expect(request_with_only_system_id.requestable[0].aeon_mapped_params[:Form]).to eq('21') end - it 'shouuld have an Aeon Action Param' do + it 'should have an Aeon Action Param' do expect(request_with_only_system_id.requestable[0].aeon_mapped_params.key?(:Action)).to be true expect(request_with_only_system_id.requestable[0].aeon_mapped_params[:Action]).to eq('10') end diff --git a/spec/models/requests/requestable_spec.rb b/spec/models/requests/requestable_spec.rb index 4dc7246d2..6161a386c 100644 --- a/spec/models/requests/requestable_spec.rb +++ b/spec/models/requests/requestable_spec.rb @@ -1185,9 +1185,7 @@ '"status":"Unavailable","status_label":"Resource Sharing Request","status_source":"process_type","process_type":"ILL","on_reserve":"N","item_type":"Gen","pickup_location_id":"RES_SHARE",'\ '"pickup_location_code":"RES_SHARE","location":"RES_SHARE$OUT_RS_REQ","label":"ReCAP","description":"","enum_display":"","chron_display":"","in_temp_library":true,"temp_library_code":"RES_SHARE",'\ '"temp_library_label":"Resource Sharing Library","temp_location_code":"RES_SHARE$OUT_RS_REQ","temp_location_label":"Resource Sharing Library"}]') - stub_request(:get, "#{Requests::Config[:bibdata_base]}/locations/holding_locations/RES_SHARE$OUT_RS_REQ.json") - .to_return(status: 200, body: '{"label":"Borrowing Resource Sharing Requests","code":"RES_SHARE$OUT_RS_REQ","aeon_location":false,"recap_electronic_delivery_location":false,"open":true,"requestable":true,"always_requestable":false,"circulates":true,'\ - '"remote_storage":"","library":{"label":"Resource Sharing Library","code":"RES_SHARE","order":0},"holding_library":null,"hours_location":null,"delivery_locations":[]}') + stub_single_holding_location('RES_SHARE$OUT_RS_REQ') stub_request(:post, "#{Requests::Config[:scsb_base]}/sharedCollection/bibAvailabilityStatus") .to_return(status: 200, body: "[{\"itemBarcode\":\"MR72802120\",\"itemAvailabilityStatus\":\"Available\",\"errorMessage\":null,\"collectionGroupDesignation\":\"Shared\"}]") end diff --git a/spec/support/webmock_stubs.rb b/spec/support/webmock_stubs.rb index 0e15205d0..5b5ec9006 100644 --- a/spec/support/webmock_stubs.rb +++ b/spec/support/webmock_stubs.rb @@ -12,6 +12,12 @@ def stub_alma_holding_locations body: File.read(File.join(fixture_path, 'bibdata', 'alma', 'holding_locations.json'))) end +def stub_single_holding_location(location_code) + file_path = File.join(fixture_path, 'holding_locations', "#{location_code.tr('$', '_')}.json") + stub_request(:get, "#{Requests.config['bibdata_base']}/locations/holding_locations/#{location_code}.json") + .to_return(status: 200, body: File.read(file_path)) +end + def stub_test_document stub_request(:get, "#{Requests.config['bibdata_base']}/bibliographic/test-id") .to_return(status: 200, body: '')