Skip to content

Commit 6dfc3bf

Browse files
fix physrequest logic and tests
1 parent c922cec commit 6dfc3bf

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

lib/requestability_resolver.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,29 @@ class RequestabilityResolver {
2424
return elasticSearchResponse
2525
}
2626

27-
static buildPhysRequestable (item, numDeliveryLocations) {
27+
static buildPhysRequestable (item, numDeliveryLocations, requestableBasedOnHoldingLocation) {
2828
let physRequestableCriteria
2929
let physRequestable
3030
const hasRecapCustomerCode = item.recapCustomerCode?.[0]
3131
const itemIsInRecapMissingRecapCustomerCode = isInRecap(item) && !hasRecapCustomerCode
32-
// recap items missing codes should default to true for phys and edd
33-
// requestable, unless it has a non-requestable holding location
32+
// The following cases are NOT mutually exclusive
3433
if (itemIsInRecapMissingRecapCustomerCode) {
34+
// recap items missing codes should default to true for phys and edd
35+
// requestable, unless it has a non-requestable holding location.
3536
physRequestable = true
3637
physRequestableCriteria = 'Missing customer code'
38+
} else if (!DeliveryLocationsResolver.requestableBasedOnHoldingLocation(item)) {
39+
physRequestableCriteria = 'Unrequestable holding location'
40+
physRequestable = false
41+
} else if (numDeliveryLocations === 0) {
42+
physRequestableCriteria = 'No delivery locations.'
43+
physRequestable = false
3744
}
45+
// This case is mutually exclusive with the prior 3
3846
if (numDeliveryLocations > 0) {
3947
physRequestableCriteria = `${numDeliveryLocations} delivery locations.`
4048
physRequestable = true
4149
}
42-
if (!numDeliveryLocations) {
43-
physRequestableCriteria = 'No delivery locations.'
44-
physRequestable = false
45-
}
4650
// items without barcodes should not be requestable
4751
const hasBarcode = (item.identifier || []).some((identifier) => /^(urn|bf):[bB]arcode:\w+/.test(identifier))
4852
if (isItemNyplOwned(item) && !hasBarcode) {

test/fixtures/no_recap_response.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ exports.fakeElasticSearchResponseNyplItem = () => {
305305
holdingLocation: [
306306
{
307307
label: 'OFFSITE - Request in Advance',
308-
id: 'loc:dya0f'
308+
id: 'loc:rcpt8'
309309
}
310310
],
311311
status_packed: [

test/requestability_resolver.test.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const RequestabilityResolver = require('../lib/requestability_resolver')
22
const elasticSearchResponse = require('./fixtures/elastic_search_response.js')
33
const specRequestableElasticSearchResponse = require('./fixtures/specRequestable/specRequestable-es-response.js')
44
const eddElasticSearchResponse = require('./fixtures/edd_elastic_search_response')
5-
const findingAidElasticSearchResponse = require('./fixtures/specRequestable/findingAid-es-response.js')
65
const noBarcodeResponse = require('./fixtures/no_barcode_es_response')
76
const noRecapResponse = require('./fixtures/no_recap_response')
87

@@ -228,16 +227,16 @@ describe('RequestabilityResolver', () => {
228227

229228
it('marks edd and physical requestability correctly', function () {
230229
const items = resolved.hits.hits[0]._source.items
231-
const firstItem = items.find((item) => {
230+
const requestableLocationNoRecapCode = items.find((item) => {
232231
return item.uri === 'i102836649'
233232
})
234-
const secondItem = items.find((item) => {
233+
const nonRequestableLocationNoRecapCode = items.find((item) => {
235234
return item.uri === 'i102836659'
236235
})
237-
expect(firstItem.physRequestable).to.equal(true)
238-
expect(firstItem.eddRequestable).to.equal(true)
239-
expect(secondItem.physRequestable).to.equal(false)
240-
expect(secondItem.eddRequestable).to.equal(false)
236+
expect(requestableLocationNoRecapCode.physRequestable).to.equal(true)
237+
expect(requestableLocationNoRecapCode.eddRequestable).to.equal(true)
238+
expect(nonRequestableLocationNoRecapCode.physRequestable).to.equal(false)
239+
expect(nonRequestableLocationNoRecapCode.eddRequestable).to.equal(false)
241240
})
242241
})
243242
})

0 commit comments

Comments
 (0)