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

Update SCSB availability for record and search results page to display Unavailable when SCSB returns Not Available #2340

Merged
merged 1 commit into from
Apr 8, 2024
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
8 changes: 6 additions & 2 deletions app/models/concerns/scsb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ module Scsb
def items_by_id(id, source = 'scsb')
request_body = scsb_bib_id_request(id, source)
request_body_json = request_body.to_json
scsb_request('/sharedCollection/bibAvailabilityStatus', request_body_json)
scsb_request_response_customize(scsb_request_response: scsb_request('/sharedCollection/bibAvailabilityStatus', request_body_json))
end

# Retrieves items from the SCSB endpoint using a barcode
def items_by_barcode(barcodes)
request_body = scsb_barcode_request(barcodes)
request_body_json = request_body.to_json
scsb_request('/sharedCollection/itemAvailabilityStatus', request_body_json)
scsb_request_response_customize(scsb_request_response: scsb_request('/sharedCollection/itemAvailabilityStatus', request_body_json))
end

def scsb_request_response_customize(scsb_request_response:)
scsb_request_response.each { |r| r["itemAvailabilityStatus"] = "Unavailable" if r["itemAvailabilityStatus"] == "Not Available" }
end

def scsb_barcode_request(barcodes)
Expand Down
23 changes: 23 additions & 0 deletions spec/controllers/availability_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@
bib_barcodes = JSON.parse(response.body)
expect(bib_barcodes).to eq(bib_response)
end
it 'returns status Unavailable when SCSB status is Not Available' do
stub_request(:post, "https://test.api.com/sharedCollection/bibAvailabilityStatus")
.with(body: '{"bibliographicId":"5270946","institutionId":"scsb"}',
headers: request_headers)
.to_return(status: 200, body: '[{ "itemBarcode": "32101055068314", "itemAvailabilityStatus": "Not Available", "errorMessage": null}]', headers: {})

get :index, params: { scsb_id:, format: :json }
bib_barcodes = JSON.parse(response.body)
expect(bib_barcodes["32101055068314"]["itemAvailabilityStatus"]).to eq('Unavailable')
end
end

describe 'scsb by barcode' do
Expand Down Expand Up @@ -133,5 +143,18 @@
bib_barcodes = JSON.parse(response.body)
expect(bib_barcodes).to eq(bib_response)
end

it 'updates barcode status to Unavaible when the SCSB response says Not Available' do
stub_request(:post, "https://test.api.com/sharedCollection/itemAvailabilityStatus")
.with(body: "{\"barcodes\":[\"32101055068314\",\"32101055068313\"]}",
headers: request_headers)
.to_return(status: 200, body: '[{ "itemBarcode": "32101055068314", "itemAvailabilityStatus": "Available", "errorMessage": null},{ "itemBarcode": "32101055068313", "itemAvailabilityStatus": "Not Available", "errorMessage": null}]', headers: {})

get :index, params: { barcodes: ['32101055068314', '32101055068313'], format: :json }
bib_barcodes = JSON.parse(response.body)

scsb_barcode_unavailable = bib_barcodes["32101055068313"]
expect(scsb_barcode_unavailable["itemAvailabilityStatus"]).to eq('Unavailable')
end
end
end
Loading