From 804dafdfcb8acaa635de1d4949d0eefd3727e286 Mon Sep 17 00:00:00 2001 From: advplyr Date: Fri, 14 Mar 2025 17:32:32 -0500 Subject: [PATCH] Add test for parseOpfMetadata OPF v3 author --- .../utils/parsers/parseOpfMetadata.test.js | 110 ++++++++++-------- 1 file changed, 60 insertions(+), 50 deletions(-) diff --git a/test/server/utils/parsers/parseOpfMetadata.test.js b/test/server/utils/parsers/parseOpfMetadata.test.js index ca033cca..32dae922 100644 --- a/test/server/utils/parsers/parseOpfMetadata.test.js +++ b/test/server/utils/parsers/parseOpfMetadata.test.js @@ -3,8 +3,8 @@ const expect = chai.expect const { parseOpfMetadataXML } = require('../../../../server/utils/parsers/parseOpfMetadata') describe('parseOpfMetadata - test series', async () => { - it('test one series', async () => { - const opf = ` + it('test one series', async () => { + const opf = ` @@ -13,12 +13,12 @@ describe('parseOpfMetadata - test series', async () => { ` - const parsedOpf = await parseOpfMetadataXML(opf) - expect(parsedOpf.series).to.deep.equal([{ "name": "Serie", "sequence": "1" }]) - }) + const parsedOpf = await parseOpfMetadataXML(opf) + expect(parsedOpf.series).to.deep.equal([{ name: 'Serie', sequence: '1' }]) + }) - it('test more then 1 series - in correct order', async () => { - const opf = ` + it('test more then 1 series - in correct order', async () => { + const opf = ` @@ -31,16 +31,16 @@ describe('parseOpfMetadata - test series', async () => { ` - const parsedOpf = await parseOpfMetadataXML(opf) - expect(parsedOpf.series).to.deep.equal([ - { "name": "Serie 1", "sequence": "1" }, - { "name": "Serie 2", "sequence": "2" }, - { "name": "Serie 3", "sequence": "3" }, - ]) - }) + const parsedOpf = await parseOpfMetadataXML(opf) + expect(parsedOpf.series).to.deep.equal([ + { name: 'Serie 1', sequence: '1' }, + { name: 'Serie 2', sequence: '2' }, + { name: 'Serie 3', sequence: '3' } + ]) + }) - it('test messed order of series content and index', async () => { - const opf = ` + it('test messed order of series content and index', async () => { + const opf = ` @@ -52,15 +52,15 @@ describe('parseOpfMetadata - test series', async () => { ` - const parsedOpf = await parseOpfMetadataXML(opf) - expect(parsedOpf.series).to.deep.equal([ - { "name": "Serie 1", "sequence": "1" }, - { "name": "Serie 3", "sequence": null }, - ]) - }) + const parsedOpf = await parseOpfMetadataXML(opf) + expect(parsedOpf.series).to.deep.equal([ + { name: 'Serie 1', sequence: '1' }, + { name: 'Serie 3', sequence: null } + ]) + }) - it('test different values of series content and index', async () => { - const opf = ` + it('test different values of series content and index', async () => { + const opf = ` @@ -73,16 +73,16 @@ describe('parseOpfMetadata - test series', async () => { ` - 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 }, - ]) - }) + 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 = ` + it('test empty series content', async () => { + const opf = ` @@ -91,12 +91,12 @@ describe('parseOpfMetadata - test series', async () => { ` - const parsedOpf = await parseOpfMetadataXML(opf) - expect(parsedOpf.series).to.deep.equal([]) - }) + const parsedOpf = await parseOpfMetadataXML(opf) + expect(parsedOpf.series).to.deep.equal([]) + }) - it('test series and index using an xml namespace', async () => { - const opf = ` + it('test series and index using an xml namespace', async () => { + const opf = ` @@ -105,14 +105,12 @@ describe('parseOpfMetadata - test series', async () => { ` - const parsedOpf = await parseOpfMetadataXML(opf) - expect(parsedOpf.series).to.deep.equal([ - { "name": "Serie 1", "sequence": null } - ]) - }) + const parsedOpf = await parseOpfMetadataXML(opf) + expect(parsedOpf.series).to.deep.equal([{ name: 'Serie 1', sequence: null }]) + }) - it('test series and series index not directly underneath', async () => { - const opf = ` + it('test series and series index not directly underneath', async () => { + const opf = ` @@ -122,9 +120,21 @@ describe('parseOpfMetadata - test series', async () => { ` - const parsedOpf = await parseOpfMetadataXML(opf) - expect(parsedOpf.series).to.deep.equal([ - { "name": "Serie 1", "sequence": "1" } - ]) - }) + const parsedOpf = await parseOpfMetadataXML(opf) + expect(parsedOpf.series).to.deep.equal([{ name: 'Serie 1', sequence: '1' }]) + }) + + it('test author is parsed from refines meta', async () => { + const opf = ` + + + Nevil Shute + aut + Shute, Nevil + + + ` + const parsedOpf = await parseOpfMetadataXML(opf) + expect(parsedOpf.authors).to.deep.equal(['Nevil Shute']) + }) })