Skip to content

Commit ee30c02

Browse files
test: Add integration tests for OPDS library lending extensions
1 parent 37a4754 commit ee30c02

3 files changed

Lines changed: 132 additions & 0 deletions

File tree

src/feeds/atom/generate/index.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,6 +1453,56 @@ describe('generate with lenient mode', () => {
14531453
expect(generate(value)).toEqual(expected)
14541454
})
14551455

1456+
it('should generate Atom feed with OPDS library lending extensions', () => {
1457+
const value = {
1458+
id: 'urn:uuid:library-catalog',
1459+
title: 'Library Catalog',
1460+
updated: new Date('2024-01-15T12:00:00Z'),
1461+
entries: [
1462+
{
1463+
id: 'urn:isbn:9780000000003',
1464+
title: 'Borrowable Book',
1465+
updated: new Date('2024-01-15T12:00:00Z'),
1466+
links: [
1467+
{
1468+
href: 'https://example.com/borrow',
1469+
rel: 'http://opds-spec.org/acquisition/borrow',
1470+
type: 'application/atom+xml;type=entry;profile=opds-catalog',
1471+
opds: {
1472+
availability: {
1473+
status: 'unavailable',
1474+
since: new Date('2024-01-01T00:00:00Z'),
1475+
until: new Date('2024-06-30T23:59:59Z'),
1476+
},
1477+
holds: { total: 5, position: 2 },
1478+
copies: { total: 3, available: 1 },
1479+
},
1480+
},
1481+
],
1482+
},
1483+
],
1484+
}
1485+
const expected = `<?xml version="1.0" encoding="utf-8"?>
1486+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:opds="http://opds-spec.org/2010/catalog">
1487+
<id>urn:uuid:library-catalog</id>
1488+
<title>Library Catalog</title>
1489+
<updated>2024-01-15T12:00:00.000Z</updated>
1490+
<entry>
1491+
<id>urn:isbn:9780000000003</id>
1492+
<link href="https://example.com/borrow" rel="http://opds-spec.org/acquisition/borrow" type="application/atom+xml;type=entry;profile=opds-catalog">
1493+
<opds:availability status="unavailable" since="2024-01-01T00:00:00.000Z" until="2024-06-30T23:59:59.000Z"/>
1494+
<opds:holds total="5" position="2"/>
1495+
<opds:copies total="3" available="1"/>
1496+
</link>
1497+
<title>Borrowable Book</title>
1498+
<updated>2024-01-15T12:00:00.000Z</updated>
1499+
</entry>
1500+
</feed>
1501+
`
1502+
1503+
expect(generate(value)).toEqual(expected)
1504+
})
1505+
14561506
it('should generate Atom feed with OPDS indirect acquisition', () => {
14571507
const value = {
14581508
id: 'urn:uuid:catalog-indirect',

src/feeds/atom/generate/utils.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,37 @@ describe('generateLink', () => {
192192
expect(generateLink(value)).toEqual(expected)
193193
})
194194

195+
it('should generate link with OPDS library lending extensions', () => {
196+
const value = {
197+
href: 'https://example.com/borrow',
198+
rel: 'http://opds-spec.org/acquisition/borrow',
199+
type: 'application/atom+xml;type=entry;profile=opds-catalog',
200+
opds: {
201+
availability: {
202+
status: 'unavailable',
203+
since: '2024-01-01T00:00:00Z',
204+
until: '2024-06-30T23:59:59Z',
205+
},
206+
holds: { total: 5, position: 2 },
207+
copies: { total: 3, available: 1 },
208+
},
209+
}
210+
const expected = {
211+
'@href': 'https://example.com/borrow',
212+
'@rel': 'http://opds-spec.org/acquisition/borrow',
213+
'@type': 'application/atom+xml;type=entry;profile=opds-catalog',
214+
'opds:availability': {
215+
'@status': 'unavailable',
216+
'@since': '2024-01-01T00:00:00.000Z',
217+
'@until': '2024-06-30T23:59:59.000Z',
218+
},
219+
'opds:holds': { '@total': 5, '@position': 2 },
220+
'opds:copies': { '@total': 3, '@available': 1 },
221+
}
222+
223+
expect(generateLink(value)).toEqual(expected)
224+
})
225+
195226
it('should generate link with OPDS facet attributes', () => {
196227
const value = {
197228
href: 'https://example.com/catalog?sort=author',

src/feeds/atom/parse/index.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1318,6 +1318,57 @@ describe('parse', () => {
13181318
expect(parse(value)).toEqual(expected)
13191319
})
13201320

1321+
it('should correctly parse Atom feed with OPDS library lending extensions', () => {
1322+
const value = `
1323+
<?xml version="1.0" encoding="UTF-8"?>
1324+
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:opds="http://opds-spec.org/2010/catalog">
1325+
<title>Library Catalog</title>
1326+
<id>urn:uuid:library-catalog</id>
1327+
<updated>2024-01-15T12:00:00Z</updated>
1328+
<entry>
1329+
<title>Borrowable Book</title>
1330+
<id>urn:isbn:9780000000003</id>
1331+
<updated>2024-01-15T12:00:00Z</updated>
1332+
<link href="https://example.com/borrow" rel="http://opds-spec.org/acquisition/borrow" type="application/atom+xml;type=entry;profile=opds-catalog">
1333+
<opds:availability status="unavailable" since="2024-01-01T00:00:00Z" until="2024-06-30T23:59:59Z"/>
1334+
<opds:holds total="5" position="2"/>
1335+
<opds:copies total="3" available="1"/>
1336+
</link>
1337+
</entry>
1338+
</feed>
1339+
`
1340+
const expected = {
1341+
title: 'Library Catalog',
1342+
id: 'urn:uuid:library-catalog',
1343+
updated: '2024-01-15T12:00:00Z',
1344+
entries: [
1345+
{
1346+
title: 'Borrowable Book',
1347+
id: 'urn:isbn:9780000000003',
1348+
updated: '2024-01-15T12:00:00Z',
1349+
links: [
1350+
{
1351+
href: 'https://example.com/borrow',
1352+
rel: 'http://opds-spec.org/acquisition/borrow',
1353+
type: 'application/atom+xml;type=entry;profile=opds-catalog',
1354+
opds: {
1355+
availability: {
1356+
status: 'unavailable',
1357+
since: '2024-01-01T00:00:00Z',
1358+
until: '2024-06-30T23:59:59Z',
1359+
},
1360+
holds: { total: 5, position: 2 },
1361+
copies: { total: 3, available: 1 },
1362+
},
1363+
},
1364+
],
1365+
},
1366+
],
1367+
}
1368+
1369+
expect(parse(value)).toEqual(expected)
1370+
})
1371+
13211372
// Edge cases and quirks observed in feeds found in the wild.
13221373
describe('real world feeds', () => {
13231374
describe('character encoding', () => {

0 commit comments

Comments
 (0)