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

test: updated tests for ad customer and ad coreData

parent 52c3bd3d
No related branches found
No related tags found
3 merge requests!10Refactor Test Resources,!6Adaptations for new DCC V3.2.1,!5Add tests
Pipeline #19245 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 * as fc from "fast-check";
import { indexOf, select, toTextArr, toTextContentArr } from "../util";
import { CoreDataType, DCCDocument, DCCXMLElement } from "../../src";
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`,
};
describe("CoreDataType", () => {
let dcc: DCCDocument, coreData: CoreDataType, dom;
beforeEach(async () => {
({ dcc, dom } = await xmlEnv.recreateEnv());
coreData = dcc.digitalCalibrationCertificate.administrativeData.coreData;
});
test("should get correct countryCodeISO3166_1 from XML", () => {
expect(coreData.countryCodeISO3166_1._text).toBe(select(xpath.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);
expect(toTextArr(coreData.usedLangCodeISO639_1)).toEqual(toTextContentArr(expected));
});
test("should set usedLangCodeISO639_1 correctly", () => {
fc.assert(
fc.property(string_ISO639_1(), (str) => {
// add new element to array
coreData.usedLangCodeISO639_1.push(new DCCXMLElement({ _text: str }));
// get actual list from xml
const actual = <Element[]>select(xpath.usedLangCodeISO639_1, dcc);
expect(toTextArr(coreData.usedLangCodeISO639_1)).toContain(str);
expect(toTextContentArr(actual)).toContain(str);
}),
);
});
test("should delete usedLangCodeISO639_1 correctly", () => {
const selection = toTextContentArr(<Element[]>select(xpath.usedLangCodeISO639_1, dom));
fc.assert(
fc.property(fc.constantFrom(...selection), (str) => {
// get index and remove element from array
const index = indexOf(coreData.usedLangCodeISO639_1, str);
coreData.usedLangCodeISO639_1.splice(index, 1);
// get actual list from xml
const actual = <Element[]>select(xpath.usedLangCodeISO639_1, dcc);
expect(toTextArr(coreData.usedLangCodeISO639_1)).not.toContain(str);
expect(toTextContentArr(actual)).not.toContain(str);
}),
);
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment