Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor stub for availability for tests #3544

Merged
merged 1 commit into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions spec/features/login_account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@
stub_request(:get, "#{Requests::Config[:pulsearch_base]}/catalog/SCSB-2143785/raw")
.to_return(status: 200, body: fixture('/scsb/SCSB-2143785.json'), headers: {})
stub_single_holding_location('scsbcul')
stub_request(:get, "#{Requests::Config[:bibdata_base]}/bibliographic/SCSB-2143785/holdings/2110046/availability.json")
.to_return(status: 200)
stub_availability_by_holding_id(bib_id: 'SCSB-2143785', holding_id: '2110046', body: false)
end

context 'with a CAS account' do
Expand Down Expand Up @@ -176,15 +175,11 @@
end
end
describe 'requesting a special collections holding with a single item' do
let(:availability) do
'[{"barcode":"32101070796881","id":"23745123320006421","holding_id":"22745123330006421","copy_number":"1","status":"Available","status_label":"Item in place","status_source":"base_status","process_type":null,"on_reserve":"N","item_type":"Closed","pickup_location_id":"rare","pickup_location_code":"rare","location":"rare$map","label":"Special Collections - Rare Books Historic Map Collection","description":"","enum_display":"","chron_display":"","in_temp_library":false}]'
end
before do
stub_request(:get, "#{Requests::Config[:pulsearch_base]}/catalog/99496133506421/raw")
.to_return(status: 200, body: fixture('/alma/99496133506421.json'), headers: {})
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)
stub_availability_by_holding_id(bib_id: '99496133506421', holding_id: '22745123330006421')
end
it 'does not require authentication', js: true do
visit "/catalog/99496133506421"
Expand Down
3 changes: 1 addition & 2 deletions spec/features/request_options_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

describe 'the request page', js: true do
before do
stub_request(:get, "#{Requests.config['bibdata_base']}/bibliographic/99113436223506421/holdings/22553672700006421/availability.json")
.to_return(status: 200, body: {}.to_json, headers: {})
stub_availability_by_holding_id(bib_id: '99113436223506421', holding_id: '22553672700006421', body: false)
stub_request(:get, "https://catalog.princeton.edu/catalog/99113436223506421/raw")
.to_return(status: 200, body: {}.to_json, headers: {})
stub_request(:get, "#{Requests.config['bibdata_base']}/availability?id=99113436223506421")
Expand Down
15 changes: 3 additions & 12 deletions spec/features/requests/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,7 @@
it 'allows patrons to request electronic delivery of a Forrestal item' do
stub_request(:get, "#{Requests::Config[:pulsearch_base]}/catalog/9956562643506421/raw")
.to_return(status: 200, body: fixture('/9956562643506421.json'), headers: {})
stub_request(:get, "#{Requests::Config[:bibdata_base]}/bibliographic/9956562643506421/holdings/22700125400006421/availability.json")
.to_return(status: 200, body: fixture('/availability_9956562643506421.json'), headers: {})
stub_availability_by_holding_id(bib_id: '9956562643506421', holding_id: '22700125400006421')
stub_illiad_patron
stub_request(:post, transaction_url)
.to_return(status: 200, body: responses[:transaction_created], headers: {})
Expand Down Expand Up @@ -1717,8 +1716,6 @@
end
context 'when a holding has items on and off reserve' do
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(:params) do
{
system_id: '9960102253506421',
Expand All @@ -1731,8 +1728,7 @@
before do
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_availability_by_holding_id(bib_id: '9960102253506421', holding_id: '22548491940006421')
stub_request(:get, 'https://catalog.princeton.edu/catalog/9960102253506421/raw')
.to_return(status: 200, body: File.read('spec/fixtures/9960102253506421.json'))
stub_request(:get, "#{Requests::Config[:bibdata_base]}/patron/#{user.uid}?ldap=true")
Expand All @@ -1750,10 +1746,6 @@
end
context 'when a Princeton item has not made it into SCSB yet' do
let(:user) { FactoryBot.create(:user) }
let(:bibdata_availability_url) { 'https://bibdata-staging.princeton.edu/bibliographic/99122304923506421/holdings/22511126440006421/availability.json' }
let(:bibdata_availability_response) do
'[{"barcode":"32101112612526","id":"23511126430006421","holding_id":"22511126440006421","copy_number":"0","status":"Available","status_label":"Item in place","status_source":"base_status","process_type":null,"on_reserve":"N","item_type":"Gen","pickup_location_id":"recap","pickup_location_code":"recap","location":"recap$pa","label":"ReCAP - Remote Storage","description":"","enum_display":"","chron_display":"","in_temp_library":false}]'
end
let(:params) do
{
system_id: '99122304923506421',
Expand All @@ -1766,8 +1758,7 @@

before do
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_availability_by_holding_id(bib_id: '99122304923506421', holding_id: '22511126440006421')
stub_request(:get, 'https://catalog.princeton.edu/catalog/99122304923506421/raw')
.to_return(status: 200, body: File.read('spec/fixtures/raw_99122304923506421.json'))
stub_single_holding_location('recap$pa')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"barcode": "32101112612526",
"id": "23511126430006421",
"holding_id": "22511126440006421",
"copy_number": "0",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Gen",
"pickup_location_id": "recap",
"pickup_location_code": "recap",
"location": "recap$pa",
"label": "ReCAP - Remote Storage",
"description": "",
"enum_display": "",
"chron_display": "",
"in_temp_library": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"barcode": "32101070796881",
"id": "23745123320006421",
"holding_id": "22745123330006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Closed",
"pickup_location_id": "rare",
"pickup_location_code": "rare",
"location": "rare$map",
"label": "Special Collections - Rare Books Historic Map Collection",
"description": "",
"enum_display": "",
"chron_display": "",
"in_temp_library": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"barcode": "32101071926461",
"id": "23700125390006421",
"holding_id": "22700125400006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Gen",
"pickup_location_id": "annex",
"pickup_location_code": "annex",
"location": "annex$stacks",
"label": "Forrestal Annex - Stacks",
"description": "",
"enum_display": "",
"chron_display": "",
"in_temp_library": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
[
{
"barcode": "32101091130938",
"id": "23563389680006421",
"holding_id": "22563389780006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Closed",
"pickup_location_id": "rare",
"pickup_location_code": "rare",
"location": "rare$ex",
"label": "Special Collections - Rare Books",
"description": "v.7",
"enum_display": "v.7",
"chron_display": "",
"in_temp_library": false
},
{
"barcode": "32101091130920",
"id": "23563389700006421",
"holding_id": "22563389780006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Closed",
"pickup_location_id": "rare",
"pickup_location_code": "rare",
"location": "rare$ex",
"label": "Special Collections - Rare Books",
"description": "v.6",
"enum_display": "v.6",
"chron_display": "",
"in_temp_library": false
},
{
"barcode": "32101091130912",
"id": "23563389710006421",
"holding_id": "22563389780006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Closed",
"pickup_location_id": "rare",
"pickup_location_code": "rare",
"location": "rare$ex",
"label": "Special Collections - Rare Books",
"description": "v.5",
"enum_display": "v.5",
"chron_display": "",
"in_temp_library": false
},
{
"barcode": "32101091130904",
"id": "23563389770006421",
"holding_id": "22563389780006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Closed",
"pickup_location_id": "rare",
"pickup_location_code": "rare",
"location": "rare$ex",
"label": "Special Collections - Rare Books",
"description": "v.4",
"enum_display": "v.4",
"chron_display": "",
"in_temp_library": false
},
{
"barcode": "32101091130896",
"id": "23563389740006421",
"holding_id": "22563389780006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Closed",
"pickup_location_id": "rare",
"pickup_location_code": "rare",
"location": "rare$ex",
"label": "Special Collections - Rare Books",
"description": "v.3",
"enum_display": "v.3",
"chron_display": "",
"in_temp_library": false
},
{
"barcode": "32101091130888",
"id": "23563389750006421",
"holding_id": "22563389780006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Closed",
"pickup_location_id": "rare",
"pickup_location_code": "rare",
"location": "rare$ex",
"label": "Special Collections - Rare Books",
"description": "v.2",
"enum_display": "v.2",
"chron_display": "",
"in_temp_library": false
},
{
"barcode": "32101091130870",
"id": "23563389760006421",
"holding_id": "22563389780006421",
"copy_number": "1",
"status": "Available",
"status_label": "Item in place",
"status_source": "base_status",
"process_type": null,
"on_reserve": "N",
"item_type": "Closed",
"pickup_location_id": "rare",
"pickup_location_code": "rare",
"location": "rare$ex",
"label": "Special Collections - Rare Books",
"description": "v.1",
"enum_display": "v.1",
"chron_display": "",
"in_temp_library": false
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"barcode": "32101092097763",
"id": "23109013710006421",
"holding_id": "22109013720006421",
"copy_number": "1",
"status": "Unavailable",
"status_label": "Resource Sharing Request",
"status_source": "process_type",
"process_type": "ILL",
"on_reserve": "N",
"item_type": "Gen",
"pickup_location_code": "RES_SHARE",
"location": "RES_SHARE$OUT_RS_REQ",
"label": "ReCAP",
"pickup_location_id": "RES_SHARE",
"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"
}
]
1 change: 0 additions & 1 deletion spec/fixtures/availability_9956562643506421.json

This file was deleted.

2 changes: 1 addition & 1 deletion spec/fixtures/bibdata/availability.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"9946093213506421":{"22258298950006421":{"on_reserve":"N","location":"rare$whs","label":"Special Collections - William H. Scheide Library","status_label":"Available","copy_number":null,"cdl":false,"temp_location":false,"id":"22258298950006421"},"22258298920006421":{"on_reserve":"N","location":"rare$whs","label":"Special Collections - William H. Scheide Library","status_label":"Available","copy_number":null,"cdl":false,"temp_location":false,"id":"22258298920006421"}}}
{"9946093213506421":{"22258298950006421":{"on_reserve":"N","location":"rare$whs","label":"Special Collections - William H. Scheide Library","status_label":"Available","copy_number":null,"cdl":false,"temp_location":false,"id":"22258298950006421"},"22258298920006421":{"on_reserve":"N","location":"rare$whs","label":"Special Collections - William H. Scheide Library","status_label":"Available","copy_number":null,"cdl":false,"temp_location":false,"id":"22258298920006421"}}}
19 changes: 8 additions & 11 deletions spec/models/concerns/requests/scsb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,24 @@
end

context 'when a Princeton item has not made it into SCSB yet' do
let(:bibdata_availability_url) { 'https://bibdata-staging.princeton.edu/bibliographic/99122304923506421/holdings/22511126440006421/availability.json' }
let(:bibdata_availability_response) do
'[{"barcode":"32101112612526","id":"23511126430006421","holding_id":"22511126440006421","copy_number":"0","status":"Available","status_label":"Item in place","status_source":"base_status","process_type":null,"on_reserve":"N","item_type":"Gen","pickup_location_id":"recap","pickup_location_code":"recap","location":"recap$pa","label":"ReCAP - Remote Storage","description":"","enum_display":"","chron_display":"","in_temp_library":false}]'
end
let(:bib_id) { '99122304923506421' }
let(:holding_id) { '22511126440006421' }
let(:params) do
{
system_id: '99122304923506421',
system_id: bib_id,
source: 'pulsearch',
mfhd: nil,
patron:
}
end
let(:first_item) { request_scsb.items['22511126440006421'].first }
let(:first_item) { request_scsb.items[holding_id].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_scsb_availability(bib_id:, institution_id: "PUL", barcode: nil, item_availability_status: nil, error_message: "Bib Id doesn't exist in SCSB database.")
stub_availability_by_holding_id(bib_id:, holding_id:)
stub_request(:get, "https://catalog.princeton.edu/catalog/#{bib_id}/raw")
.to_return(status: 200, body: File.read("spec/fixtures/raw_#{bib_id}.json"))
end

it 'is in process' do
Expand Down
Loading