Skip to content

Commit

Permalink
Merge pull request #416 from NYPL/NOREF-fix-delivery-locations-endpoint
Browse files Browse the repository at this point in the history
Fix broken delivery-locations serialization
  • Loading branch information
nonword authored Nov 4, 2024
2 parents 62a9812 + 0246794 commit e184e5d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/jsonld_serializers.js
Original file line number Diff line number Diff line change
Expand Up @@ -395,8 +395,10 @@ class ItemResultsSerializer extends JsonLdListSerializer {
return `resources:${result.uri}`
}

static serialize (items, opts) {
const results = items.map((i) => ItemResourceSerializer.serialize(i))
static async serialize (items, opts) {
const results = await Promise.all(
items.map((i) => ItemResourceSerializer.serialize(i))
)
return (new ItemResultsSerializer(results, opts)).format()
}
}
Expand Down
51 changes: 50 additions & 1 deletion test/jsonld-serializers.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { expect } = require('chai')

const { ResourceSerializer } = require('../lib/jsonld_serializers')
const {
ResourceSerializer,
ItemResultsSerializer
} = require('../lib/jsonld_serializers')

describe('JSONLD Serializers', () => {
describe('ResourceSerializer', () => {
Expand Down Expand Up @@ -68,4 +71,50 @@ describe('JSONLD Serializers', () => {
)
})
})

describe('ItemResultsSerializer', () => {
const esItems = [
{
accessMessage: [{ id: 'accessMessage:2', label: 'Request in advance' }],
catalogItemType: [{ id: 'catalogItemType:55', label: 'book, limited circ, MaRLI' }],
holdingLocation: [{ id: 'loc:rc2ma', label: 'Offsite' }],
identifier: [
'urn:bnum:b10807029',
'urn:shelfmark:JLE 83-2799',
'urn:barcode:33433056867710'
],
status: [{ id: 'status:a', label: 'Available' }],
type: ['bf:Item'],
uri: 'i12606717',
recapCustomerCode: ['NA'],
eddRequestable: true,
deliveryLocation: [
{
id: 'loc:mal23',
label: 'Schwarzman Building - Scholar Room 223',
sortPosition: 0
},
{
id: 'loc:mal',
label: 'Schwarzman Building - Main Reading Room 315',
sortPosition: 1
},
{
id: 'loc:mab',
label: 'Schwarzman Building - Art & Architecture Room 300',
sortPosition: 2
}
]
}
]

it('serializes delivery-lcoations-by-barcode response', async () => {
const serialized = await ItemResultsSerializer.serialize(esItems)
expect(serialized).to.nested.include({
'itemListElement[0].@id': 'res:i12606717',
'itemListElement[0].deliveryLocation[0].@id': 'loc:mal23',
'itemListElement[0].deliveryLocation[0].prefLabel': 'Schwarzman Building - Scholar Room 223'
})
})
})
})

0 comments on commit e184e5d

Please sign in to comment.