From 60e60b894d83c08840424f2198d379c8e05a26e5 Mon Sep 17 00:00:00 2001 From: Paul Beaudoin Date: Tue, 26 Nov 2024 17:12:42 -0500 Subject: [PATCH] Fix bug in delivery-locations-by-barcode .. introduced by params parsing cleanup. Added a test. --- routes/resources.js | 2 +- test/delivery-locations-resolver.test.js | 54 ++++++++++++------------ test/fixtures.js | 3 +- test/resources-responses.test.js | 20 +++++++++ 4 files changed, 50 insertions(+), 29 deletions(-) diff --git a/routes/resources.js b/routes/resources.js index 852b71c0..9da2309b 100644 --- a/routes/resources.js +++ b/routes/resources.js @@ -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)) }) diff --git a/test/delivery-locations-resolver.test.js b/test/delivery-locations-resolver.test.js index dd0b055a..97cf33b1 100644 --- a/test/delivery-locations-resolver.test.js +++ b/test/delivery-locations-resolver.test.js @@ -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(() => { @@ -377,8 +379,6 @@ describe('Delivery-locations-resolver', function () { }) describe('attachDeliveryLocationsAndEddRequestability - romcom', () => { - before(takeThisPartyPartiallyOffline) - const requestableM2Location = 'map92' const requestableM1Location = 'map82' const nonrequestableM2Location = 'ccj92' diff --git a/test/fixtures.js b/test/fixtures.js index 43d16e1c..dbc78cb9 100644 --- a/test/fixtures.js +++ b/test/fixtures.js @@ -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')) } /** diff --git a/test/resources-responses.test.js b/test/resources-responses.test.js index dff30c5a..60661976 100644 --- a/test/resources-responses.test.js +++ b/test/resources-responses.test.js @@ -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' + }) + }) + }) + }) })