Skip to content

Commit

Permalink
Merge pull request #386 from NYPL/main
Browse files Browse the repository at this point in the history
SCC-4088 main -> QA
danamansana authored May 28, 2024
2 parents 6e7c55a + 51d7f19 commit a380cd7
Showing 5 changed files with 864 additions and 9 deletions.
11 changes: 10 additions & 1 deletion lib/delivery-locations-resolver.js
Original file line number Diff line number Diff line change
@@ -236,7 +236,16 @@ class DeliveryLocationsResolver {
// location is not requestable:
let deliveryLocation
let eddRequestable
if (!isItemNyplOwned(item) || this.requestableBasedOnHoldingLocation(item)) {
const hasRecapCustomerCode = item.recapCustomerCode && item.recapCustomerCode[0]
const nyplItem = isItemNyplOwned(item)
if (!hasRecapCustomerCode) {
const requestableBasedOnHoldingLocation = nyplItem ? this.requestableBasedOnHoldingLocation(item) : true
// the length of the list of delivery locations is checked later to determine physical requestability
// In case of an offsite item with no recap customer code, we want this to be based on holding location
// so we put a placeholder '' in case it is requestable based on holding location
deliveryLocation = requestableBasedOnHoldingLocation ? [''] : []
eddRequestable = requestableBasedOnHoldingLocation
} else if (!nyplItem || this.requestableBasedOnHoldingLocation(item)) {
deliveryLocation = this.deliveryLocationsByRecapCustomerCode(item.recapCustomerCode[0])
eddRequestable = this.__eddRequestableByCustomerCode(item.recapCustomerCode[0])
} else {
13 changes: 6 additions & 7 deletions lib/requestability_resolver.js
Original file line number Diff line number Diff line change
@@ -12,15 +12,14 @@ class RequestabilityResolver {
const itemIsInRecap = isInRecap(item)
let physRequestableCriteria
const hasRecapCustomerCode = item.recapCustomerCode && item.recapCustomerCode[0]
if (itemIsInRecap && !hasRecapCustomerCode) {
if (itemIsInRecap) {
// recap items missing codes should default to true for phys and edd
// requestable.
physRequestableCriteria = 'Missing customer code'
deliveryInfo = { eddRequestable: true, deliveryLocation: [''] }
} else if (itemIsInRecap && hasRecapCustomerCode) {
// requestable, unless it has a non-requestable holding location
deliveryInfo = DeliveryLocationsResolver.getRecapDeliveryInfo(item)
physRequestableCriteria = `${deliveryInfo.deliveryLocation &&
deliveryInfo.deliveryLocation.length || 0} delivery locations.`
physRequestableCriteria = hasRecapCustomerCode
? `${deliveryInfo.deliveryLocation &&
deliveryInfo.deliveryLocation.length || 0} delivery locations.`
: 'Missing customer code'
} else if (!itemIsInRecap) {
deliveryInfo = DeliveryLocationsResolver.getOnsiteDeliveryInfo(item)
physRequestableCriteria = `${deliveryInfo.deliveryLocation &&
22 changes: 21 additions & 1 deletion test/delivery-locations-resolver.test.js
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ var sampleItems = {
],
'holdingLocation': [
{
'id': 'loc:scff3',
'id': 'loc:scff2',
'prefLabel': 'Schomburg Center - Research & Reference - Desk'
}
],
@@ -502,4 +502,24 @@ describe('Delivery-locations-resolver', function () {
).to.equal(true)
})
})
describe('getRecapDeliveryInfo', function () {
it('returns empty deliveryLocation and eddRequestable false based on holding location when missing recapCustomerCode', function () {
const resolved = DeliveryLocationsResolver.getRecapDeliveryInfo({
holdingLocation: [{ id: 'loc:rccd8' }],
uri: 'i14747243'
})
expect(resolved.deliveryLocation.length).to.equal(0)
expect(resolved.eddRequestable).to.equal(false)
})

it('returns empty string delivery location and eddRequestable true based on holding location when missing recapCustomerCode', function () {
const resolved = DeliveryLocationsResolver.getRecapDeliveryInfo({
holdingLocation: [{ id: 'loc:rcpm2' }],
uri: 'i14747243'
})
expect(resolved.deliveryLocation.length).to.equal(1)
expect(resolved.deliveryLocation[0]).to.equal('')
expect(resolved.eddRequestable).to.equal(true)
})
})
})
808 changes: 808 additions & 0 deletions test/fixtures/no_recap_response.js

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions test/requestability_resolver.test.js
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@ const elasticSearchResponse = require('./fixtures/elastic_search_response.js')
const specRequestableElasticSearchResponse = require('./fixtures/specRequestable-es-response')
const eddElasticSearchResponse = require('./fixtures/edd_elastic_search_response')
const noBarcodeResponse = require('./fixtures/no_barcode_es_response')
const noRecapResponse = require('./fixtures/no_recap_response')

describe('RequestabilityResolver', () => {
describe('fixItemRequestability', function () {
@@ -203,4 +204,22 @@ describe('RequestabilityResolver', () => {
expect(nonEddItem.eddRequestable).to.equal(false)
})
})

describe('Missing recapCustomerCode', function () {
const response = noRecapResponse.fakeElasticSearchResponseNyplItem()
const resolved = RequestabilityResolver.fixItemRequestability(response)
it('marks edd and physical requestability correctly', function () {
const items = resolved.hits.hits[0]._source.items
const firstItem = items.find((item) => {
return item.uri === 'i102836649'
})
const secondItem = items.find((item) => {
return item.uri === 'i102836659'
})
expect(firstItem.physRequestable).to.equal(true)
expect(firstItem.eddRequestable).to.equal(true)
expect(secondItem.physRequestable).to.equal(false)
expect(secondItem.eddRequestable).to.equal(false)
})
})
})

0 comments on commit a380cd7

Please sign in to comment.