2023-12-22 20:35:38 +01:00
|
|
|
const chai = require('chai')
|
|
|
|
const expect = chai.expect
|
|
|
|
const { parseOpfMetadataXML } = require('../../../../server/utils/parsers/parseOpfMetadata')
|
|
|
|
|
2023-12-24 18:41:27 +01:00
|
|
|
describe('parseOpfMetadata - test series', async () => {
|
|
|
|
it('test one series', async () => {
|
2023-12-22 20:35:38 +01:00
|
|
|
const opf = `
|
|
|
|
<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
2023-12-24 18:41:27 +01:00
|
|
|
<metadata>
|
2023-12-22 20:35:38 +01:00
|
|
|
<meta name="calibre:series" content="Serie"/>
|
|
|
|
<meta name="calibre:series_index" content="1"/>
|
|
|
|
</metadata>
|
2023-12-24 18:41:27 +01:00
|
|
|
</package>
|
2023-12-22 20:35:38 +01:00
|
|
|
`
|
|
|
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
2023-12-24 18:41:27 +01:00
|
|
|
expect(parsedOpf.series).to.deep.equal([{ "name": "Serie", "sequence": "1" }])
|
2023-12-22 20:35:38 +01:00
|
|
|
})
|
|
|
|
|
2023-12-24 18:41:27 +01:00
|
|
|
it('test more then 1 series - in correct order', async () => {
|
2023-12-22 20:35:38 +01:00
|
|
|
const opf = `
|
|
|
|
<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
2023-12-24 18:41:27 +01:00
|
|
|
<metadata>
|
2023-12-22 20:35:38 +01:00
|
|
|
<meta name="calibre:series" content="Serie 1"/>
|
|
|
|
<meta name="calibre:series_index" content="1"/>
|
|
|
|
<meta name="calibre:series" content="Serie 2"/>
|
|
|
|
<meta name="calibre:series_index" content="2"/>
|
|
|
|
<meta name="calibre:series" content="Serie 3"/>
|
|
|
|
<meta name="calibre:series_index" content="3"/>
|
|
|
|
</metadata>
|
2023-12-24 18:41:27 +01:00
|
|
|
</package>
|
2023-12-22 20:35:38 +01:00
|
|
|
`
|
|
|
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
|
|
|
expect(parsedOpf.series).to.deep.equal([
|
2023-12-24 18:41:27 +01:00
|
|
|
{ "name": "Serie 1", "sequence": "1" },
|
|
|
|
{ "name": "Serie 2", "sequence": "2" },
|
|
|
|
{ "name": "Serie 3", "sequence": "3" },
|
2023-12-22 20:35:38 +01:00
|
|
|
])
|
|
|
|
})
|
|
|
|
|
2023-12-24 18:41:27 +01:00
|
|
|
it('test messed order of series content and index', async () => {
|
2023-12-22 20:35:38 +01:00
|
|
|
const opf = `
|
|
|
|
<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
2023-12-24 18:41:27 +01:00
|
|
|
<metadata>
|
2023-12-22 20:35:38 +01:00
|
|
|
<meta name="calibre:series" content="Serie 1"/>
|
|
|
|
<meta name="calibre:series_index" content="1"/>
|
|
|
|
<meta name="calibre:series_index" content="2"/>
|
|
|
|
<meta name="calibre:series_index" content="3"/>
|
|
|
|
<meta name="calibre:series" content="Serie 3"/>
|
|
|
|
</metadata>
|
2023-12-24 18:41:27 +01:00
|
|
|
</package>
|
2023-12-22 20:35:38 +01:00
|
|
|
`
|
|
|
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
|
|
|
expect(parsedOpf.series).to.deep.equal([
|
2023-12-24 18:41:27 +01:00
|
|
|
{ "name": "Serie 1", "sequence": "1" },
|
|
|
|
{ "name": "Serie 3", "sequence": null },
|
2023-12-22 20:35:38 +01:00
|
|
|
])
|
|
|
|
})
|
|
|
|
|
2023-12-24 18:41:27 +01:00
|
|
|
it('test different values of series content and index', async () => {
|
2023-12-22 20:35:38 +01:00
|
|
|
const opf = `
|
|
|
|
<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
2023-12-24 18:41:27 +01:00
|
|
|
<metadata>
|
2023-12-22 20:35:38 +01:00
|
|
|
<meta name="calibre:series" content="Serie 1"/>
|
|
|
|
<meta name="calibre:series_index"/>
|
|
|
|
<meta name="calibre:series" content="Serie 2"/>
|
|
|
|
<meta name="calibre:series_index" content="abc"/>
|
|
|
|
<meta name="calibre:series" content="Serie 3"/>
|
|
|
|
<meta name="calibre:series_index" content=""/>
|
|
|
|
</metadata>
|
2023-12-24 18:41:27 +01:00
|
|
|
</package>
|
|
|
|
`
|
|
|
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
|
|
|
expect(parsedOpf.series).to.deep.equal([
|
|
|
|
{ "name": "Serie 1", "sequence": null },
|
|
|
|
{ "name": "Serie 2", "sequence": "abc" },
|
|
|
|
{ "name": "Serie 3", "sequence": null },
|
|
|
|
])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('test empty series content', async () => {
|
|
|
|
const opf = `
|
|
|
|
<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
|
|
|
<metadata>
|
|
|
|
<meta name="calibre:series" content=""/>
|
|
|
|
<meta name="calibre:series_index" content=""/>
|
|
|
|
</metadata>
|
|
|
|
</package>
|
|
|
|
`
|
|
|
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
|
|
|
expect(parsedOpf.series).to.deep.equal([])
|
|
|
|
})
|
|
|
|
|
|
|
|
it('test series and index using an xml namespace', async () => {
|
|
|
|
const opf = `
|
|
|
|
<?xml version='1.0' encoding='UTF-8'?>
|
|
|
|
<ns0:package xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:opf="http://www.idpf.org/2007/opf" xml:lang="en" version="3.0" unique-identifier="bookid">
|
|
|
|
<ns0:metadata>
|
|
|
|
<ns0:meta name="calibre:series" content="Serie 1"/>
|
|
|
|
<ns0:meta name="calibre:series_index" content=""/>
|
|
|
|
</ns0:metadata>
|
|
|
|
</ns0:package>
|
2023-12-22 20:35:38 +01:00
|
|
|
`
|
|
|
|
const parsedOpf = await parseOpfMetadataXML(opf)
|
|
|
|
expect(parsedOpf.series).to.deep.equal([
|
2023-12-24 18:41:27 +01:00
|
|
|
{ "name": "Serie 1", "sequence": null }
|
2023-12-22 20:35:38 +01:00
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|