Skip to content

Commit

Permalink
Fix bug in delivery-locations-by-barcode
Browse files Browse the repository at this point in the history
.. introduced by params parsing cleanup. Added a test.
  • Loading branch information
nonword committed Nov 26, 2024
1 parent 38b9136 commit 60e60b8
Show file tree
Hide file tree
Showing 4 changed files with 50 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
20 changes: 20 additions & 0 deletions test/resources-responses.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -842,4 +842,24 @@ describe('Test Resources responses', function () {
})
})
})

describe('deliveryLocationsByBarcode', () => {
it('empty search returns status code 200', async () => {
const url = `${global.TEST_BASE_URL}/api/v0.1/request/deliveryLocationsByBarcode?barcodes=33433128201161`

return request.get(url, function (err, response, body) {
if (err) throw err

assert.equal(200, response.statusCode)
expect(response.statusCode).to.eq(200)

const result = JSON.parse(body)
console.log('Got result: ', result)
expect(result).to.nested.include({
'itemListElement[0].deliveryLocation[0].@id': 'loc:mal',
'itemListElement[0].deliveryLocation[0].prefLabel': 'Schwarzman Building - Main Reading Room 315'
})
})
})
})
})

0 comments on commit 60e60b8

Please sign in to comment.