From ea7016920e991afebb49c1ac7487c36f784c8a31 Mon Sep 17 00:00:00 2001 From: Vera Kahn Date: Fri, 20 Dec 2024 12:11:19 -0500 Subject: [PATCH] tests for phys requestable override --- lib/requestability_resolver.js | 2 +- .../specRequestable/findingAid-es-response.js | 287 +---------------- .../phys-requestable-override.js | 297 ++++++++++++++++++ test/requestability_resolver.test.js | 13 + 4 files changed, 312 insertions(+), 287 deletions(-) create mode 100644 test/fixtures/specRequestable/phys-requestable-override.js diff --git a/lib/requestability_resolver.js b/lib/requestability_resolver.js index cb3b8b8..c887f3e 100644 --- a/lib/requestability_resolver.js +++ b/lib/requestability_resolver.js @@ -27,7 +27,7 @@ class RequestabilityResolver { } item.specRequestable = this.buildSpecRequestable(item, parentBibHasFindingAid) item.physRequestable = !!deliveryInfo.deliveryLocation?.length - item.eddRequestable = !!deliveryInfo.eddRequestable && !item.specRequestable + item.eddRequestable = !!deliveryInfo.eddRequestable // items without barcodes should not be requestable const hasBarcode = (item.identifier || []).some((identifier) => /^(urn|bf):[bB]arcode:\w+/.test(identifier)) if (isItemNyplOwned(item) && !hasBarcode) { diff --git a/test/fixtures/specRequestable/findingAid-es-response.js b/test/fixtures/specRequestable/findingAid-es-response.js index e36a0bb..7de9c34 100644 --- a/test/fixtures/specRequestable/findingAid-es-response.js +++ b/test/fixtures/specRequestable/findingAid-es-response.js @@ -17,173 +17,7 @@ module.exports = () => { label: 'Finding aid', url: 'spaghetti.com' }], - numItems: [ - 4 - ], - createdString: [ - '1989' - ], - issuance: [ - { - label: 'monograph/item', - id: 'urn:biblevel:m' - } - ], - creatorLiteral: [ - 'Maḥfūẓ, Najīb, 1911-2006.' - ], - creator_sort: [ - 'maḥfūẓ, najīb, 1911-2006.' - ], - level: 'debug', items: [ - { - uri: 'i22566485', - identifier: [ - 'urn:barcode:33433058338470' - ], - status: [ - { - label: 'Available', - id: 'status:a' - } - ] - }, - { - uri: 'i22566489' - }, - { - holdingLocation_packed: [ - 'loc:scff2||Schomburg Center - Research & Reference' - ], - suppressed: [ - false - ], - shelfMark: [ - 'Sc D 90-863' - ], - accessMessage_packed: [ - 'accessMessage:1||USE IN LIBRARY' - ], - uri: 'i10283665', - accessMessage: [ - { - label: 'USE IN LIBRARY', - id: 'accessMessage:1' - } - ], - catalogItemType: [ - { - id: 'catalogItemType:2', - label: 'book non-circ' - } - ], - deliveryLocation_packed: [ - 'loc:sc||Schomburg Center' - ], - owner: [ - { - label: 'Schomburg Center for Research in Black Culture, Jean Blackwell Hutson Research and Reference Division', - id: 'orgs:1114' - } - ], - deliveryLocation: [ - { - label: 'Schomburg Center', - id: 'loc:sc' - } - ], - identifier: [ - 'urn:barcode:32101071572406' - ], - requestable: [ - true - ], - owner_packed: [ - 'orgs:1114||Schomburg Center for Research in Black Culture, Jean Blackwell Hutson Research and Reference Division' - ], - status: [ - { - label: 'Available', - id: 'status:a' - } - ], - holdingLocation: [ - { - label: 'Schomburg Center - Research & Reference', - id: 'loc:scff2' - } - ], - status_packed: [ - 'status:a||Available' - ] - }, - { - holdingLocation_packed: [ - 'loc:scff2||Schomburg Center - Research & Reference' - ], - suppressed: [ - false - ], - shelfMark: [ - 'Sc D 90-863' - ], - accessMessage_packed: [ - 'accessMessage:1||USE IN LIBRARY' - ], - uri: 'i10283665777', - accessMessage: [ - { - label: 'USE IN LIBRARY', - id: 'accessMessage:1' - } - ], - catalogItemType: [ - { - id: 'catalogItemType:2', - label: 'book non-circ' - } - ], - deliveryLocation_packed: [ - 'loc:sc||Schomburg Center' - ], - owner: [ - { - label: 'Schomburg Center for Research in Black Culture, Jean Blackwell Hutson Research and Reference Division', - id: 'orgs:1114' - } - ], - deliveryLocation: [ - { - label: 'Schomburg Center', - id: 'loc:sc' - } - ], - identifier: [ - 'urn:barcode:32101071572406777' - ], - requestable: [ - true - ], - owner_packed: [ - 'orgs:1114||Schomburg Center for Research in Black Culture, Jean Blackwell Hutson Research and Reference Division' - ], - status: [ - { - label: 'Not Available', - id: 'status:na' - } - ], - holdingLocation: [ - { - label: 'Schomburg Center - Research & Reference', - id: 'loc:mao82' - } - ], - status_packed: [ - 'status:na||Not Available' - ] - }, { holdingLocation: [ { @@ -304,127 +138,8 @@ module.exports = () => { false ] } - ], - message: 'ResourceSerializer#serialize', - materialType_packed: [ - 'resourcetypes:txt||Text' - ], - suppressed: [ - 'false' - ], - placeOfPublication: [ - 'New York :' - ], - dateEndString: [ - '1984' - ], - title_sort: [ - 'the thief and the dogs' - ], - uris: [ - 'b11293188', - 'b11293188-i22566485', - 'b11293188-i22566489', - 'b11293188-i10283665', - 'b11293188-i10283664' - ], - language: [ - { - id: 'lang:eng', - label: 'English' - } - ], - dateString: [ - '1989' - ], - identifier: [ - 'urn:bnum:11293188', - 'urn:oclc:12248278', - 'urn:lcc:PJ7846.A46', - 'urn:lccCoarse:PJ7695.8-7976' - ], - publisher: [ - 'Doubleday,' - ], - type: [ - 'nypl:Item' - ], - createdYear: [ - 1989 - ], - contributor_sort: [ - 'badawī, muḥammad muṣṭafá.' - ], - materialType: [ - { - id: 'resourcetypes:txt', - label: 'Text' - } - ], - numAvailable: [ - 2 - ], - dimensions: [ - '22 cm.' - ], - carrierType_packed: [ - 'carriertypes:nc||volume' - ], - note: [ - 'Translation of: al-Liṣṣ wa-al-kilāb.' - ], - dateStartYear: [ - 1989 - ], - shelfMark: [ - '*OFC 90-2649' - ], - idOwi: [ - 'urn:owi:58201773' - ], - mediaType: [ - { - label: 'unmediated', - id: 'mediatypes:n' - } - ], - title: [ - 'The thief and the dogs', - 'The thief and the dogs /' - ], - titleAlt: [ - 'Liṣṣ wa-al-kilāb.' - ], - language_packed: [ - 'lang:eng||English' - ], - mediaType_packed: [ - 'mediatypes:n||unmediated' - ], - titleDisplay: [ - 'The thief and the dogs / Naguib Mahfouz ; translated by Trevor Le Gassick, M.M. Badawi ; revised by John Rodenbeck.' - ], - uri: 'b11293188', - extent: [ - '158 p. ;' - ], - carrierType: [ - { - id: 'carriertypes:nc', - label: 'volume' - } - ], - issuance_packed: [ - 'urn:biblevel:m||monograph/item' - ], - contributorLiteral: [ - 'Badawī, Muḥammad Muṣṭafá.', - 'Le Gassick, Trevor.', - 'Rodenbeck, John.' - ], - dateEndYear: [ - 1984 ] + }, _type: 'resource', _index: 'resources-2017-06-13', diff --git a/test/fixtures/specRequestable/phys-requestable-override.js b/test/fixtures/specRequestable/phys-requestable-override.js new file mode 100644 index 0000000..6c02261 --- /dev/null +++ b/test/fixtures/specRequestable/phys-requestable-override.js @@ -0,0 +1,297 @@ +module.exports = { + _shards: { + failed: 0, + successful: 1, + total: 1 + }, + took: 1, + hits: { + total: 1, + max_score: 1.3862944, + hits: [ + { + _id: 'b10980129', + _source: { + numItems: [ + 4 + ], + createdString: [ + '1989' + ], + issuance: [ + { + label: 'monograph/item', + id: 'urn:biblevel:m' + } + ], + supplementaryContent: [{ label: 'Finding aid', url: 'spaghetti.com' }], + creatorLiteral: [ + 'Maḥfūẓ, Najīb, 1911-2006.' + ], + creator_sort: [ + 'maḥfūẓ, najīb, 1911-2006.' + ], + level: 'debug', + items: [ + { + holdingLocation_packed: [ + 'loc:scff2||Schomburg Center - Research & Reference' + ], + suppressed: [ + false + ], + shelfMark: [ + 'Sc D 90-863' + ], + accessMessage_packed: [ + 'accessMessage:1||USE IN LIBRARY' + ], + uri: 'i10283665', + accessMessage: [ + { + label: 'USE IN LIBRARY', + id: 'accessMessage:1' + } + ], + catalogItemType: [ + { + id: 'catalogItemType:2', + label: 'book non-circ' + } + ], + deliveryLocation_packed: [ + 'loc:sc||Schomburg Center' + ], + owner: [ + { + label: 'Schomburg Center for Research in Black Culture, Jean Blackwell Hutson Research and Reference Division', + id: 'orgs:1114' + } + ], + deliveryLocation: [ + { + label: 'Schomburg Center', + id: 'loc:sc' + } + ], + identifier: [ + 'urn:barcode:32101071572406' + ], + requestable: [ + true + ], + owner_packed: [ + 'orgs:1114||Schomburg Center for Research in Black Culture, Jean Blackwell Hutson Research and Reference Division' + ], + status: [ + { + label: 'Available', + id: 'status:a' + } + ], + holdingLocation: [ + { + label: 'Schomburg Center - Research & Reference', + id: 'loc:scff2' + } + ], + status_packed: [ + 'status:a||Available' + ] + }, + { + holdingLocation_packed: [ + 'loc:scff2||Schomburg Center - Research & Reference' + ], + suppressed: [ + false + ], + shelfMark: [ + 'Sc D 90-863' + ], + accessMessage_packed: [ + 'accessMessage:1||USE IN LIBRARY' + ], + uri: 'i10283665777', + accessMessage: [ + { + label: 'USE IN LIBRARY', + id: 'accessMessage:1' + } + ], + catalogItemType: [ + { + id: 'catalogItemType:2', + label: 'book non-circ' + } + ], + deliveryLocation_packed: [ + 'loc:sc||Schomburg Center' + ], + owner: [ + { + label: 'Schomburg Center for Research in Black Culture, Jean Blackwell Hutson Research and Reference Division', + id: 'orgs:1114' + } + ], + deliveryLocation: [ + { + label: 'Schomburg Center', + id: 'loc:sc' + } + ], + identifier: [ + 'urn:barcode:32101071572406777' + ], + requestable: [ + true + ], + owner_packed: [ + 'orgs:1114||Schomburg Center for Research in Black Culture, Jean Blackwell Hutson Research and Reference Division' + ], + status: [ + { + label: 'Not Available', + id: 'status:na' + } + ], + holdingLocation: [ + { + label: 'Schomburg Center - Research & Reference', + id: 'loc:scff2' + } + ], + status_packed: [ + 'status:na||Not Available' + ] + } + ], + message: 'ResourceSerializer#serialize', + materialType_packed: [ + 'resourcetypes:txt||Text' + ], + suppressed: [ + 'false' + ], + placeOfPublication: [ + 'New York :' + ], + dateEndString: [ + '1984' + ], + title_sort: [ + 'the thief and the dogs' + ], + uris: [ + 'b11293188', + 'b11293188-i22566485', + 'b11293188-i22566489', + 'b11293188-i10283665', + 'b11293188-i10283664' + ], + language: [ + { + id: 'lang:eng', + label: 'English' + } + ], + dateString: [ + '1989' + ], + identifier: [ + 'urn:bnum:11293188', + 'urn:oclc:12248278', + 'urn:lcc:PJ7846.A46', + 'urn:lccCoarse:PJ7695.8-7976' + ], + publisher: [ + 'Doubleday,' + ], + type: [ + 'nypl:Item' + ], + createdYear: [ + 1989 + ], + contributor_sort: [ + 'badawī, muḥammad muṣṭafá.' + ], + materialType: [ + { + id: 'resourcetypes:txt', + label: 'Text' + } + ], + numAvailable: [ + 2 + ], + dimensions: [ + '22 cm.' + ], + carrierType_packed: [ + 'carriertypes:nc||volume' + ], + note: [ + 'Translation of: al-Liṣṣ wa-al-kilāb.' + ], + dateStartYear: [ + 1989 + ], + shelfMark: [ + '*OFC 90-2649' + ], + idOwi: [ + 'urn:owi:58201773' + ], + mediaType: [ + { + label: 'unmediated', + id: 'mediatypes:n' + } + ], + title: [ + 'The thief and the dogs', + 'The thief and the dogs /' + ], + titleAlt: [ + 'Liṣṣ wa-al-kilāb.' + ], + language_packed: [ + 'lang:eng||English' + ], + mediaType_packed: [ + 'mediatypes:n||unmediated' + ], + titleDisplay: [ + 'The thief and the dogs / Naguib Mahfouz ; translated by Trevor Le Gassick, M.M. Badawi ; revised by John Rodenbeck.' + ], + uri: 'b11293188', + extent: [ + '158 p. ;' + ], + carrierType: [ + { + id: 'carriertypes:nc', + label: 'volume' + } + ], + issuance_packed: [ + 'urn:biblevel:m||monograph/item' + ], + contributorLiteral: [ + 'Badawī, Muḥammad Muṣṭafá.', + 'Le Gassick, Trevor.', + 'Rodenbeck, John.' + ], + dateEndYear: [ + 1984 + ] + }, + _type: 'resource', + _index: 'resources-2017-06-13', + _score: 154.93451 + } + ] + }, + timed_out: false +} diff --git a/test/requestability_resolver.test.js b/test/requestability_resolver.test.js index 0106188..da8de71 100644 --- a/test/requestability_resolver.test.js +++ b/test/requestability_resolver.test.js @@ -5,6 +5,8 @@ const eddElasticSearchResponse = require('./fixtures/edd_elastic_search_response const findingAidElasticSearchResponse = require('./fixtures/specRequestable/findingAid-es-response.js') const noBarcodeResponse = require('./fixtures/no_barcode_es_response') const noRecapResponse = require('./fixtures/no_recap_response') +const physRequestableOverride = require('./fixtures/specRequestable/phys-requestable-override.js') +const DeliveryLocationsResolver = require('../lib/delivery-locations-resolver.js') describe('RequestabilityResolver', () => { describe('fixItemRequestability', function () { @@ -17,6 +19,17 @@ describe('RequestabilityResolver', () => { const resp = RequestabilityResolver.fixItemRequestability(noBarcode) expect(resp.hits.hits[0]._source.items.every((item) => item.physRequestable === false)).to.equal(true) }) + it('specRequestable overrides physRequestable, when items have phys requestable holding location', () => { + const esResponseItems = physRequestableOverride.hits.hits[0]._source.items + const isPhysRequestable = (item) => !!item.deliveryLocation.length + const resp = RequestabilityResolver.fixItemRequestability(physRequestableOverride) + // verify that items are phys requestable based on location... + expect(esResponseItems + .map(DeliveryLocationsResolver.getOnsiteDeliveryInfo) + .every(isPhysRequestable)).to.equal(true) + // ...but overridden by specRequestability + expect(resp.hits.hits[0]._source.items.every((item) => !item.physRequestable && item.specRequestable)).to.equal(true) + }) it('will set requestable to false for an item not found in ReCAP', function () { const indexedButNotAvailableInSCSBURI = 'i22566485'