Skip to content
Snippets Groups Projects

Add tests

Merged Jan Loewe requested to merge feat-jest-tests into master
Compare and Show latest version
2 files
+ 125
5
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -10,8 +10,25 @@ import { string_ISO639_1 } from "../Arbitraries";
const base = "/dcc:digitalCalibrationCertificate/dcc:administrativeData/dcc:coreData";
const xpath = {
countryCodeISO3166_1: `string(${base}/dcc:countryCodeISO3166_1)`,
usedLangCodeISO639_1: `${base}/dcc:usedLangCodeISO639_1`,
coreData: {
countryCodeISO3166_1: `string(${base}/dcc:countryCodeISO3166_1)`,
usedLangCodeISO639_1: `${base}/dcc:usedLangCodeISO639_1`,
mandatoryLangCodeISO639_1: `${base}/dcc:mandatoryLangCodeISO639_1`,
uniqueIdentifier: `string(${base}/dcc:uniqueIdentifier)`,
identifications: {
identification: {
issuer: `string(${base}/dcc:identifications/dcc:identification[1]/dcc:issuer)`,
value: `string(${base}/dcc:identifications/dcc:identification[1]/dcc:value)`,
name: {
content: `${base}/dcc:identifications/dcc:identification[1]/dcc:name/dcc:content`,
},
},
},
receiptDate: `string(${base}/dcc:receiptDate)`,
beginPerformanceDate: `string(${base}/dcc:beginPerformanceDate)`,
endPerformanceDate: `string(${base}/dcc:endPerformanceDate)`,
performanceLocation: `string(${base}/dcc:performanceLocation)`,
},
};
describe("CoreDataType", () => {
@@ -23,15 +40,52 @@ describe("CoreDataType", () => {
});
test("should get correct countryCodeISO3166_1 from XML", () => {
expect(coreData.countryCodeISO3166_1._text).toBe(select(xpath.countryCodeISO3166_1, dom));
expect(coreData.countryCodeISO3166_1._text).toBe(select(xpath.coreData.countryCodeISO3166_1, dom));
});
test("should get correct usedLangCodeISO639_1 from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.usedLangCodeISO639_1, dom);
const expected = <Element[]>select(xpath.coreData.usedLangCodeISO639_1, dom);
expect(toTextArr(coreData.usedLangCodeISO639_1)).toEqual(toTextContentArr(expected));
});
test("should get correct mandatoryLangCodeISO639_1 from XML", () => {
// get expected list from example xml
const expected = <Element[]>select(xpath.coreData.mandatoryLangCodeISO639_1, dom);
expect(toTextArr(coreData.mandatoryLangCodeISO639_1)).toEqual(toTextContentArr(expected));
});
test("should get correct unique identifier from XML", () => {
expect(coreData.uniqueIdentifier._text).toBe(select(xpath.coreData.uniqueIdentifier, dom));
});
test("should get correct identification issuer from XML", () => {
expect(coreData.identifications.identification[0].issuer._text).toBe(select(xpath.coreData.identifications.identification.issuer, dom));
});
test("should get correct identification value from XML", () => {
expect(coreData.identifications.identification[0].value._text).toBe(select(xpath.coreData.identifications.identification.value, dom));
});
test("should get correct identification name content from XML", () => {
const expected = <Element[]>select(xpath.coreData.identifications.identification.name.content, dom);
expect(toTextArr(coreData.identifications.identification[0].name.content)).toEqual(toTextContentArr(expected));
});
test("should get correct receipt date from XML", () => {
expect(coreData.receiptDate._text).toBe(select(xpath.coreData.receiptDate, dom));
});
test("should get correct begin performance date from XML", () => {
expect(coreData.beginPerformanceDate._text).toBe(select(xpath.coreData.beginPerformanceDate, dom));
});
test("should get correct end performance date from XML", () => {
expect(coreData.endPerformanceDate._text).toBe(select(xpath.coreData.endPerformanceDate, dom));
});
test("should get correct performance location from XML", () => {
expect(coreData.performanceLocation._text).toBe(select(xpath.coreData.performanceLocation, dom));
});
/* test for setters */
test("should set usedLangCodeISO639_1 correctly", () => {
fc.assert(
fc.property(string_ISO639_1(), (str) => {
@@ -39,7 +93,7 @@ describe("CoreDataType", () => {
coreData.usedLangCodeISO639_1.push(new DCCXMLElement({ _text: str }));
// get actual list from xml
const actual = <Element[]>select(xpath.usedLangCodeISO639_1, dcc);
const actual = <Element[]>select(xpath.coreData.usedLangCodeISO639_1, dcc);
expect(toTextArr(coreData.usedLangCodeISO639_1)).toContain(str);
expect(toTextContentArr(actual)).toContain(str);
@@ -48,7 +102,7 @@ describe("CoreDataType", () => {
});
test("should delete usedLangCodeISO639_1 correctly", () => {
const selection = toTextContentArr(<Element[]>select(xpath.usedLangCodeISO639_1, dom));
const selection = toTextContentArr(<Element[]>select(xpath.coreData.usedLangCodeISO639_1, dom));
fc.assert(
fc.property(fc.constantFrom(...selection), (str) => {
// get index and remove element from array
@@ -56,7 +110,7 @@ describe("CoreDataType", () => {
coreData.usedLangCodeISO639_1.splice(index, 1);
// get actual list from xml
const actual = <Element[]>select(xpath.usedLangCodeISO639_1, dcc);
const actual = <Element[]>select(xpath.coreData.usedLangCodeISO639_1, dcc);
expect(toTextArr(coreData.usedLangCodeISO639_1)).not.toContain(str);
expect(toTextContentArr(actual)).not.toContain(str);
Loading