From b576567eddde9cf9c5337af9089f75b879a1f3c7 Mon Sep 17 00:00:00 2001
From: Moritz Jordan <moritz.jordan@ptb.de>
Date: Wed, 5 Apr 2023 10:18:49 +0200
Subject: [PATCH] test: add AdministrativeData Calibration Laboratory

---
 ...strativeData.CalibrationLaboratory.test.ts | 80 +++++++++++++++++++
 tests/DCC/AdministrativeData.Customer.test.ts |  2 +-
 2 files changed, 81 insertions(+), 1 deletion(-)
 create mode 100644 tests/DCC/AdministrativeData.CalibrationLaboratory.test.ts

diff --git a/tests/DCC/AdministrativeData.CalibrationLaboratory.test.ts b/tests/DCC/AdministrativeData.CalibrationLaboratory.test.ts
new file mode 100644
index 0000000..251b284
--- /dev/null
+++ b/tests/DCC/AdministrativeData.CalibrationLaboratory.test.ts
@@ -0,0 +1,80 @@
+/**
+ * @jest-environment ./tests/XMLEnvironment.ts
+ * @xml ./tests/resources/example.xml
+ */
+
+import { select, toTextArr, toTextContentArr } from "../util";
+import { CalibrationLaboratoryType, DCCDocument } from "../../src";
+
+const base = "/dcc:digitalCalibrationCertificate/dcc:administrativeData/dcc:calibrationLaboratory/dcc:contact";
+const xpath = {
+  name: `string(${base}/dcc:name/dcc:content)`,
+  eMail: `string(${base}/dcc:eMail)`,
+  phone: `string(${base}/dcc:phone)`,
+  fax: `string(${base}/dcc:fax)`,
+  location: {
+    city: `${base}/dcc:location/dcc:city`,
+    countryCode: `${base}/dcc:location/dcc:countryCode`,
+    postCode: `${base}/dcc:location/dcc:postCode`,
+    street: `${base}/dcc:location/dcc:street`,
+    streetNo: `${base}/dcc:location/dcc:streetNo`,
+    further: `${base}/dcc:location/dcc:further/dcc:content`,
+  },
+};
+
+describe("CalibrationLaboratoryType", () => {
+  let dcc: DCCDocument, calibrationLaboratory: CalibrationLaboratoryType, dom;
+
+  beforeEach(async () => {
+    ({ dcc, dom } = await xmlEnv.recreateEnv());
+    calibrationLaboratory = dcc.digitalCalibrationCertificate.administrativeData.calibrationLaboratory;
+  });
+
+  test("should get correct name from XML", () => {
+    expect(calibrationLaboratory.contact.name.content[0]._text).toBe(select(xpath.name, dom));
+  });
+
+  test("should get correct eMail from XML", () => {
+    expect(calibrationLaboratory.contact.eMail._text).toBe(select(xpath.eMail, dom));
+  });
+
+  test("should get correct phone from XML", () => {
+    expect(calibrationLaboratory.contact.phone._text).toBe(select(xpath.phone, dom));
+  });
+
+  test("should get correct city from XML", () => {
+    // get expected list from example xml
+    const expected = <Element[]>select(xpath.location.city, dom);
+    expect(toTextArr(calibrationLaboratory.contact.location.city)).toEqual(toTextContentArr(expected));
+  });
+
+  test("should get correct countryCode from XML", () => {
+    // get expected list from example xml
+    const expected = <Element[]>select(xpath.location.countryCode, dom);
+    expect(toTextArr(calibrationLaboratory.contact.location.countryCode)).toEqual(toTextContentArr(expected));
+  });
+
+  test("should get correct postCode from XML", () => {
+    // get expected list from example xml
+    const expected = <Element[]>select(xpath.location.postCode, dom);
+    expect(toTextArr(calibrationLaboratory.contact.location.postCode)).toEqual(toTextContentArr(expected));
+  });
+
+  test("should get correct street from XML", () => {
+    // get expected list from example xml
+    const expected = <Element[]>select(xpath.location.street, dom);
+    expect(toTextArr(calibrationLaboratory.contact.location.street)).toEqual(toTextContentArr(expected));
+  });
+
+  test("should get correct streetNo from XML", () => {
+    // get expected list from example xml
+    const expected = <Element[]>select(xpath.location.streetNo, dom);
+    expect(toTextArr(calibrationLaboratory.contact.location.streetNo)).toEqual(toTextContentArr(expected));
+  });
+
+  test("should get correct further element from XML", () => {
+    // get expected list from example xml
+    const expected = <Element[]>select(xpath.location.further, dom);
+    expect(toTextArr(calibrationLaboratory.contact.location.further[0].content)).toEqual(toTextContentArr(expected));
+  });
+});
diff --git a/tests/DCC/AdministrativeData.Customer.test.ts b/tests/DCC/AdministrativeData.Customer.test.ts
index 377bf6e..52388be 100644
--- a/tests/DCC/AdministrativeData.Customer.test.ts
+++ b/tests/DCC/AdministrativeData.Customer.test.ts
@@ -68,7 +68,7 @@ describe("ContactType", () => {
   test("should get correct customer location further from XML", () => {
     const expected = <Element[]>select(xpath.customer.location.further, dom);
 
-    for (var i = 0; i < expected.length; i++) {
+    for (let i = 0; i < expected.length; i++) {
       expect(customer.location.further[0].content[i]._text).toBe(expected[i].textContent);
     }
   });
-- 
GitLab