Skip to content

Commit

Permalink
Merge pull request #127 from NYPL-discovery/investigate-AvailableDeli…
Browse files Browse the repository at this point in the history
…veryLocationTypes-method

Investigate available delivery location types method
  • Loading branch information
ktp242 authored Mar 6, 2019
2 parents 87f81ed + 2f4c692 commit 3e0eaac
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ NYPL_OAUTH_ID=who-you-will-connect-to-the-api-as
NYPL_OAUTH_SECRET=that-accounts-pw
NYPL_CORE_VERSION=v1.21

CATALOG_WEBPUB_DEF_URL=[fqdn to catalog webpub.def]
CATALOG_WEBPUB_DEF_URL=[fqdn to catalog webpub.def. Only required for running scripts/update-annotated-marc-rules.js]
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ This app uses [nvm](https://github.com/creationix/nvm).
1. `cd` into the newly cloned directory
1. `nvm use`
1. `npm install`
1. Decrypt the appropriate config/[environment].env file and copy to .env. development is encrypted
using nypl-sandbox and the others using nypl-digital-dev
1. Decrypt the appropriate config/[environment].env file and copy to .env. The values are encrypted using nypl-digital-dev
`npm start` to start the app!

## About Environment Variables
Expand Down
10 changes: 0 additions & 10 deletions config/development.env

This file was deleted.

21 changes: 17 additions & 4 deletions lib/available_delivery_location_types.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
let logger = require('./logger')
const { makeNyplDataApiClient } = require('./data-api-client')

class AvailableDeliveryLocationTypes {

class AvailableDeliveryLocationTypes {
static getByPatronId (patronID) {
// If patronID is falsy (i.e. patron is not logged in) they're just a Rearcher:
if (!patronID) return Promise.resolve(['Research'])

const patronTypeMapping = require('@nypl/nypl-core-objects')('by-patron-type')
return this._getPatronTypeOf(patronID).then((patronType) => {
return patronTypeMapping[patronType]['accessibleDeliveryLocationTypes']
})

return this._getPatronTypeOf(patronID)
.then((patronType) => {
const accessibleDeliveryLocationTypes = this._isUnfamiliarPatronType(patronTypeMapping, patronType)
? ['Research'] : patronTypeMapping[patronType]['accessibleDeliveryLocationTypes']

return accessibleDeliveryLocationTypes
})
}

static _getPatronTypeOf (patronID) {
Expand All @@ -34,6 +39,14 @@ class AvailableDeliveryLocationTypes {
})
}

static _isUnfamiliarPatronType (patronTypeMapping, patronType) {
if (!patronTypeMapping[patronType]) {
logger.info(`Found the Patron Type: ${patronType} is not recognizable.`)
return true
} else {
return false
}
}
}

let patronTypeMapping = require('@nypl/nypl-core-objects')('by-patron-type')
Expand Down
2 changes: 1 addition & 1 deletion lib/delivery-locations-resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DeliveryLocationsResolver {

static resolveDeliveryLocations (items, deliveryLocationTypes) {
// Assert sensible default for location types:
if (!deliveryLocationTypes || !Array.isArray(deliveryLocationTypes)) deliveryLocationTypes = ['Research']
if (!Array.isArray(deliveryLocationTypes) || deliveryLocationTypes.length === 0) deliveryLocationTypes = ['Research']

// Extract barcodes from items:
var barcodes = items.map((i) => i.identifier.filter((i) => /^urn:barcode:/.test(i))[0].split(':')[2])
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
"it"
]
},
"version": "1.1.1"
"version": "1.1.2"
}
9 changes: 8 additions & 1 deletion test/available_delivery_location_types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ describe('AvailableDeliveryLocationTypes', function () {
// Reroute these (and only these) api paths to local fixtures:
fixtures.enableDataApiFixtures({
'patrons/branch-patron-id': 'patron-research.json',
'patrons/scholar-patron-id': 'patron-scholar.json'
'patrons/scholar-patron-id': 'patron-scholar.json',
'patrons/unrecognizable-ptype-patron-id': 'patron-unrecognizable-type.json'
})
})

Expand All @@ -26,4 +27,10 @@ describe('AvailableDeliveryLocationTypes', function () {
expect(deliveryLocationTypes).to.eql(['Scholar', 'Research'])
})
})

it('maps an unrecognizable patron type to [\'Research\']', function () {
return AvailableDeliveryLocationTypes.getByPatronId('unrecognizable-ptype-patron-id').then((deliveryLocationTypes) => {
expect(deliveryLocationTypes).to.eql(['Research'])
})
})
})
6 changes: 6 additions & 0 deletions test/delivery-locations-resolver.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,10 @@ describe('Delivery-locations-resolver', function () {
})
})
})

it('will reveal "Research" deliveryLocation for users with no PType found', function () {
return DeliveryLocationsResolver.resolveDeliveryLocations([sampleItems.onsiteNypl], []).then((items) => {
expect(items[0].deliveryLocation).to.not.be.empty
})
})
})
280 changes: 280 additions & 0 deletions test/fixtures/patron-unrecognizable-type.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
{
"data": {
"id": "620xxxx",
"updatedDate": "2017-04-28T15:48:53+00:00",
"createdDate": "2015-01-08T18:40:36+00:00",
"deletedDate": null,
"deleted": false,
"suppressed": false,
"names": [
"Hugenhold, Amanda"
],
"barCodes": [
"examplebarcode"
],
"expirationDate": "2018-01-08",
"homeLibraryCode": "lb",
"birthDate": null,
"emails": [
"[email protected]"
],
"fixedFields": {
"43": {
"label": "Expiration Date",
"value": "2018-01-08T09:00:00Z",
"display": null
},
"44": {
"label": "E-Communications",
"value": "s",
"display": null
},
"45": {
"label": "Education Level",
"value": "-",
"display": null
},
"46": {
"label": "Home Region",
"value": "4",
"display": null
},
"47": {
"label": "Patron Type",
"value": "not-a-real-patron-type",
"display": null
},
"48": {
"label": "Total Checkouts",
"value": 51,
"display": null
},
"49": {
"label": "Total Renewals",
"value": 24,
"display": null
},
"50": {
"label": "Current Checkouts",
"value": 0,
"display": null
},
"53": {
"label": "Home Library",
"value": "lb ",
"display": null
},
"54": {
"label": "Patron Message",
"value": "-",
"display": null
},
"55": {
"label": "Highest Overdues",
"value": 3,
"display": null
},
"56": {
"label": "Manual Block",
"value": "-",
"display": null
},
"80": {
"label": "Record Type",
"value": "p",
"display": null
},
"81": {
"label": "Record Number",
"value": "620xxxx",
"display": null
},
"83": {
"label": "Created Date",
"value": "2015-01-08T18:40:36Z",
"display": null
},
"84": {
"label": "Updated Date",
"value": "2017-04-28T15:48:53Z",
"display": null
},
"85": {
"label": "No. of Revisions",
"value": "632",
"display": null
},
"86": {
"label": "Agency",
"value": "1",
"display": null
},
"95": {
"label": "Claims Returned",
"value": 0,
"display": null
},
"96": {
"label": "Money Owed",
"value": 0,
"display": null
},
"98": {
"label": "PDATE",
"value": "2016-12-08T13:57:13Z",
"display": null
},
"99": {
"label": "FIRM",
"value": " ",
"display": null
},
"102": {
"label": "Current Item A",
"value": 0,
"display": null
},
"103": {
"label": "Current Item B",
"value": 0,
"display": null
},
"104": {
"label": "PIUSE",
"value": 0,
"display": null
},
"105": {
"label": "Overdue Penalty",
"value": 0,
"display": null
},
"122": {
"label": "ILL Request",
"value": 0,
"display": null
},
"123": {
"label": "Debit Balance",
"value": 0,
"display": null
},
"124": {
"label": "Current Item C",
"value": 0,
"display": null
},
"125": {
"label": "Current Item D",
"value": 0,
"display": null
},
"126": {
"label": "School Code",
"value": "0",
"display": null
},
"158": {
"label": "Patron Agency",
"value": "41",
"display": null
},
"163": {
"label": "Last Circ Activity",
"value": "2016-11-22T19:27:26Z",
"display": null
},
"263": {
"label": "Preferred Language",
"value": "eng",
"display": null
},
"268": {
"label": "Notice Preference",
"value": "z",
"display": null
},
"269": {
"label": "Registrations on Record",
"value": 0,
"display": null
},
"270": {
"label": "Total Registrations",
"value": 0,
"display": null
},
"271": {
"label": "Total Programs Attended",
"value": 0,
"display": null
},
"297": {
"label": "Waitlists on Record",
"value": 0,
"display": null
}
},
"varFields": [
{
"fieldTag": "=",
"marcTag": null,
"ind1": null,
"ind2": null,
"content": "Menoknow",
"subFields": null
},
{
"fieldTag": "b",
"marcTag": null,
"ind1": null,
"ind2": null,
"content": "23333086712393",
"subFields": null
},
{
"fieldTag": "d",
"marcTag": null,
"ind1": null,
"ind2": null,
"content": "SCHOS619",
"subFields": null
},
{
"fieldTag": "u",
"marcTag": null,
"ind1": null,
"ind2": null,
"content": "somethinggreat",
"subFields": null
},
{
"fieldTag": "z",
"marcTag": null,
"ind1": null,
"ind2": null,
"content": "[email protected]",
"subFields": null
},
{
"fieldTag": "a",
"marcTag": null,
"ind1": null,
"ind2": null,
"content": "123 example street$BROOKLYN, NY 11222",
"subFields": null
},
{
"fieldTag": "n",
"marcTag": null,
"ind1": null,
"ind2": null,
"content": "HUGENHOLD, AMANDA",
"subFields": null
}
]
},
"count": 1,
"statusCode": 200,
"debugInfo": []
}

0 comments on commit 3e0eaac

Please sign in to comment.