From 870d23e8fc587f6c5846ed8be3b96c00b9d09963 Mon Sep 17 00:00:00 2001 From: Muhammed-Ali Demir <muhammed.demir@ptb.de> Date: Wed, 5 Apr 2023 11:58:33 +0200 Subject: [PATCH] test: added tests for ad items, extended tests for respPerson --- tests/DCC/AdministrativeData.Items.test.ts | 117 ++++++++++++++++++ .../AdministrativeData.RespPersons.test.ts | 30 +++-- 2 files changed, 139 insertions(+), 8 deletions(-) create mode 100644 tests/DCC/AdministrativeData.Items.test.ts diff --git a/tests/DCC/AdministrativeData.Items.test.ts b/tests/DCC/AdministrativeData.Items.test.ts new file mode 100644 index 0000000..6ac37f8 --- /dev/null +++ b/tests/DCC/AdministrativeData.Items.test.ts @@ -0,0 +1,117 @@ +/** + * @jest-environment ./tests/XMLEnvironment.ts + * @xml ./tests/resources/example.xml + */ + +import { select, toTextArr, toTextContentArr } from "../util"; +import { ItemType, DCCDocument, DCCXMLElement, IdentificationType } from "../../src"; + +const base = "//dcc:administrativeData/dcc:items"; +const xpath = { + items: { + item: { + name: { + content: `${base}/dcc:item[1]/dcc:name/dcc:content`, + }, + manufacturer: { + name: { + content: `${base}/dcc:item[1]/dcc:manufacturer/dcc:name/dcc:content`, + }, + }, + model: `string(${base}/dcc:item[1]/dcc:model)`, + + identifications: { + identification1: { + issuer: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[1]/dcc:issuer)`, + value: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[1]/dcc:value)`, + name: { + content: `${base}/dcc:item[1]/dcc:identifications/dcc:identification[1]/dcc:name/dcc:content`, + }, + }, + identification2: { + issuer: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[2]/dcc:issuer)`, + value: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[2]/dcc:value)`, + name: { + content: `${base}/dcc:item[1]/dcc:identifications/dcc:identification[2]/dcc:name/dcc:content`, + }, + }, + identification3: { + issuer: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[3]/dcc:issuer)`, + value: `string(${base}/dcc:item[1]/dcc:identifications/dcc:identification[3]/dcc:value)`, + name: { + content: `${base}/dcc:item[1]/dcc:identifications/dcc:identification[3]/dcc:name/dcc:content`, + }, + }, + }, + }, + }, +}; + +describe("ItemType", () => { + let dcc: DCCDocument, item: ItemType, identification1, identification2, identification3: IdentificationType, dom; + + beforeEach(async () => { + ({ dcc, dom } = await xmlEnv.recreateEnv()); + item = dcc.digitalCalibrationCertificate.administrativeData.items.item[0]; + identification1 = item.identifications.identification[0]; + identification2 = item.identifications.identification[1]; + identification3 = item.identifications.identification[2]; + }); + + test("should get correct item name content from XML", () => { + // get expected list from example xml + const expected = <Element[]>select(xpath.items.item.name.content, dom); + expect(toTextArr(item.name.content)).toEqual(toTextContentArr(expected)); + }); + + test("should get correct item manufacturer name content from XML", () => { + // get expected list from example xml + const expected = <Element[]>select(xpath.items.item.manufacturer.name.content, dom); + expect(toTextArr(item.manufacturer.name.content)).toEqual(toTextContentArr(expected)); + }); + + test("should get correct item model from XML", () => { + expect(item.model._text).toBe(select(xpath.items.item.model, dom)); + }); + + test("should get correct identification 1 issuer from XML", () => { + expect(identification1.issuer._text).toBe(select(xpath.items.item.identifications.identification1.issuer, dom)); + }); + + test("should get correct identification 1 value from XML", () => { + expect(identification1.value._text).toBe(select(xpath.items.item.identifications.identification1.value, dom)); + }); + + test("should get correct identification 1 name content from XML", () => { + const expected = <Element[]>select(xpath.items.item.identifications.identification1.name.content, dom); + expect(toTextArr(identification1.name.content)).toEqual(toTextContentArr(expected)); + }); + + test("should get correct identification 2 issuer from XML", () => { + expect(identification2.issuer._text).toBe(select(xpath.items.item.identifications.identification2.issuer, dom)); + }); + + test("should get correct identification 2 value from XML", () => { + expect(identification2.value._text).toBe(select(xpath.items.item.identifications.identification2.value, dom)); + }); + + test("should get correct identification 2 name content from XML", () => { + const expected = <Element[]>select(xpath.items.item.identifications.identification2.name.content, dom); + expect(toTextArr(identification2.name.content)).toEqual(toTextContentArr(expected)); + }); + + test("should get correct identification 3 issuer from XML", () => { + expect(identification3.issuer._text).toBe(select(xpath.items.item.identifications.identification3.issuer, dom)); + }); + + test("should get correct identification 3 value from XML", () => { + expect(identification3.value._text).toBe(select(xpath.items.item.identifications.identification3.value, dom)); + }); + + test("should get correct identification 3 name content from XML", () => { + const expected = <Element[]>select(xpath.items.item.identifications.identification3.name.content, dom); + expect(toTextArr(identification3.name.content)).toEqual(toTextContentArr(expected)); + }); + + /* TODO: setters */ +}); diff --git a/tests/DCC/AdministrativeData.RespPersons.test.ts b/tests/DCC/AdministrativeData.RespPersons.test.ts index 9d3139f..a03e1c5 100644 --- a/tests/DCC/AdministrativeData.RespPersons.test.ts +++ b/tests/DCC/AdministrativeData.RespPersons.test.ts @@ -9,7 +9,7 @@ import { RespPersonType, DCCDocument } from "../../src"; const base = "//dcc:administrativeData/dcc:respPersons"; const xpath = { respPersons: { - respPerson: { + respPerson1: { person: { name: { content: `${base}/dcc:respPerson[1]/dcc:person/dcc:name/dcc:content`, @@ -17,25 +17,39 @@ const xpath = { }, mainSigner: `string(${base}/dcc:respPerson[1]/dcc:mainSigner)`, }, + respPerson2: { + person: { + name: { + content: `${base}/dcc:respPerson[2]/dcc:person/dcc:name/dcc:content`, + }, + }, + }, }, }; describe("ContactType", () => { - let dcc: DCCDocument, respPerson: RespPersonType, dom; + let dcc: DCCDocument, respPerson1, respPerson2: RespPersonType, dom; beforeEach(async () => { ({ dcc, dom } = await xmlEnv.recreateEnv()); - respPerson = dcc.digitalCalibrationCertificate.administrativeData.respPersons.respPerson[0]; + respPerson1 = dcc.digitalCalibrationCertificate.administrativeData.respPersons.respPerson[0]; + respPerson2 = dcc.digitalCalibrationCertificate.administrativeData.respPersons.respPerson[1]; }); - test("should get correct res name content from XML", () => { + test("should get correct responsible person 1 name content from XML", () => { // get expected list from example xml - const expected = <Element[]>select(xpath.respPersons.respPerson.person.name.content, dom); - expect(toTextArr(respPerson.person.name.content)).toEqual(toTextContentArr(expected)); + const expected = <Element[]>select(xpath.respPersons.respPerson1.person.name.content, dom); + expect(toTextArr(respPerson1.person.name.content)).toEqual(toTextContentArr(expected)); + }); + + test("should get correct responsible person 1 main signer flag from XML", () => { + expect(respPerson1.mainSigner._text).toBe(select(xpath.respPersons.respPerson1.mainSigner, dom)); }); - test("should get correct responsible person main signer flag from XML", () => { - expect(respPerson.mainSigner._text).toBe(select(xpath.respPersons.respPerson.mainSigner, dom)); + test("should get correct responsible person 2 name content from XML", () => { + // get expected list from example xml + const expected = <Element[]>select(xpath.respPersons.respPerson2.person.name.content, dom); + expect(toTextArr(respPerson2.person.name.content)).toEqual(toTextContentArr(expected)); }); /* TODO: setters */ -- GitLab