Skip to content

Commit

Permalink
Merge pull request #421 from NYPL/NOREF-fix-delivery-locations-bug
Browse files Browse the repository at this point in the history
Fix bug in delivery-locations-by-barcode
  • Loading branch information
nonword authored Nov 27, 2024
2 parents 38b9136 + ecb3054 commit 75f1ae9
Show file tree
Hide file tree
Showing 5 changed files with 27,504 additions and 29 deletions.
2 changes: 1 addition & 1 deletion routes/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ module.exports = function (app) {

const handler = app.resources.deliveryLocationsByBarcode

return handler(req.query.params, { baseUrl: app.baseUrl })
return handler(params, { baseUrl: app.baseUrl })
.then((resp) => respond(res, resp, params))
.catch((error) => handleError(res, error, params))
})
Expand Down
54 changes: 27 additions & 27 deletions test/delivery-locations-resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,32 +124,34 @@ const scholarRooms = [
}
]

function takeThisPartyPartiallyOffline () {
// Reroute HTC API requests mapping specific barcodes tested above to recap customer codes:
DeliveryLocationsResolver.__recapCustomerCodesByBarcodes = (barcodes) => {
const stubbedLookups = {
'recap-barcode-for-pj': 'PJ',
33433047331719: 'NP',
32101062243553: 'PA',
CU56521537: 'CU',
33433011759648: 'NA',
// Let's pretend this is a valid NYPL Map Division item barcode
// and let's further pretend that HTC API tells us it's recap customer code is ND
'made-up-barcode-that-recap-says-belongs-to-ND': 'ND'
}

// Return hash containing only requested barcodes:
return Promise.resolve(
barcodes.reduce((h, barcode) => {
h[barcode] = stubbedLookups[barcode]
return h
}, {})
)
}
}

describe('Delivery-locations-resolver', function () {
before(takeThisPartyPartiallyOffline)
before(() => {
// Reroute HTC API requests mapping specific barcodes tested above to recap customer codes:
sinon.stub(DeliveryLocationsResolver, '__recapCustomerCodesByBarcodes').callsFake((barcodes) => {
const stubbedLookups = {
'recap-barcode-for-pj': 'PJ',
33433047331719: 'NP',
32101062243553: 'PA',
CU56521537: 'CU',
33433011759648: 'NA',
// Let's pretend this is a valid NYPL Map Division item barcode
// and let's further pretend that HTC API tells us it's recap customer code is ND
'made-up-barcode-that-recap-says-belongs-to-ND': 'ND'
}

// Return hash containing only requested barcodes:
return Promise.resolve(
barcodes.reduce((h, barcode) => {
h[barcode] = stubbedLookups[barcode]
return h
}, {})
)
})
})

after(() => {
DeliveryLocationsResolver.__recapCustomerCodesByBarcodes.restore()
})

describe('SC delivery locations', () => {
before(() => {
Expand Down Expand Up @@ -377,8 +379,6 @@ describe('Delivery-locations-resolver', function () {
})

describe('attachDeliveryLocationsAndEddRequestability - romcom', () => {
before(takeThisPartyPartiallyOffline)

const requestableM2Location = 'map92'
const requestableM1Location = 'map82'
const nonrequestableM2Location = 'ccj92'
Expand Down
3 changes: 2 additions & 1 deletion test/fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ function enableScsbFixtures () {
}
})

sinon.stub(scsbClient, 'recapCustomerCodeByBarcode').callsFake(() => Promise.resolve('NC'))
// Let's hardcode recapCustomerCode-lookups to return NA, a common location
sinon.stub(scsbClient, 'recapCustomerCodeByBarcode').callsFake(() => Promise.resolve('NA'))
}

/**
Expand Down
Loading

0 comments on commit 75f1ae9

Please sign in to comment.