Skip to content

Commit

Permalink
Update SCSB availability for record and search results page to displa…
Browse files Browse the repository at this point in the history
…y Unavailable when SCSB returns Not Available (#2340)
  • Loading branch information
christinach authored Apr 8, 2024
1 parent ebf208b commit 7c98883
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
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

0 comments on commit 7c98883

Please sign in to comment.