Skip to content
Snippets Groups Projects
Commit 870d23e8 authored by Muhammed-Ali Demir's avatar Muhammed-Ali Demir :speech_balloon:
Browse files

test: added tests for ad items, extended tests for respPerson

parent 7dfdfd32
No related branches found
No related tags found
3 merge requests!10Refactor Test Resources,!6Adaptations for new DCC V3.2.1,!5Add tests
Pipeline #19248 passed
This commit is part of merge request !5. Comments created here will be created in the context of that merge request.
/**
* @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 */
});
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment