Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix broken delivery-locations serialization #416

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
})
})
})
})
Loading