From 06949aab650d191f2888b3012e3e09ca9d2aaade Mon Sep 17 00:00:00 2001
From: Muhammed-Ali Demir <muhammed.demir@ptb.de>
Date: Wed, 5 Apr 2023 09:45:25 +0200
Subject: [PATCH] test: updated tests for ad customer and ad software list

---
 tests/DCC/AdministrativeData.Customer.test.ts | 49 ++++++++++---------
 ...dministrativeData.SoftwareListType.test.ts | 36 ++++++++------
 2 files changed, 47 insertions(+), 38 deletions(-)

diff --git a/tests/DCC/AdministrativeData.Customer.test.ts b/tests/DCC/AdministrativeData.Customer.test.ts
index 51640da..bcd4a3d 100644
--- a/tests/DCC/AdministrativeData.Customer.test.ts
+++ b/tests/DCC/AdministrativeData.Customer.test.ts
@@ -8,22 +8,27 @@ import { ContactType, DCCDocument, LocationType } from "../../src";
 
 const base = "//dcc:administrativeData/dcc:customer";
 const xpath = {
-  customerNameContent: `${base}/dcc:name/dcc:content`,
-  customerEmail: `string(${base}/dcc:eMail)`,
-  customerPhone: `${base}/dcc:phone)`,
-  customerFax: `${base}/dcc:fax)`,
-  customerLocation: `${base}/dcc:location`,
-  customerLocationCity: `${base}/dcc:location/dcc:city[1]`,
-  customerLocationCountryCode: `${base}/dcc:location/dcc:countryCode[1]`,
-  customerLocationPostCode: `${base}/dcc:location/dcc:postCode[1]`,
-  customerLocationPostBoxOffice: `${base}/dcc:location/dcc:postBoxOffice[1]`,
-  customerLocationState: `${base}/dcc:location/dcc:state[1]`,
-  customerLocationStreet: `${base}/dcc:location/dcc:street[1]`,
-  customerLocationStreetNo: `${base}/dcc:location/dcc:streetNo[1]`,
-  customerLocationFurther: `${base}/dcc:location/dcc:further[1]/dcc:content`,
-  customerLocationPositionCoordinates: `${base}/dcc:location/dcc:positionCoordinates[1]`,
-  customerDescriptionData: `${base}/dcc:descriptionData`,
-  customerId: `${base}/@id`,
+  customer: {
+    name: {
+      content: `${base}/dcc:name/dcc:content`,
+    },
+    email: `string(${base}/dcc:eMail)`,
+    phone: `${base}/dcc:phone)`,
+    fax: `${base}/dcc:fax)`,
+    location: {
+      city: `${base}/dcc:location/dcc:city[1]`,
+      countryCode: `${base}/dcc:location/dcc:countryCode[1]`,
+      postCode: `${base}/dcc:location/dcc:postCode[1]`,
+      postBoxOffice: `${base}/dcc:location/dcc:postBoxOffice[1]`,
+      state: `${base}/dcc:location/dcc:state[1]`,
+      street: `${base}/dcc:location/dcc:street[1]`,
+      streetNo: `${base}/dcc:location/dcc:streetNo[1]`,
+      further: `${base}/dcc:location/dcc:further[1]/dcc:content`,
+      positionCoordinates: `${base}/dcc:location/dcc:positionCoordinates[1]`,
+    },
+    descriptionData: `${base}/dcc:descriptionData`,
+    _id: `${base}/@id`,
+  },
 };
 
 describe("ContactType", () => {
@@ -37,31 +42,31 @@ describe("ContactType", () => {
 
   test("should get correct customer name content from XML", () => {
     // get expected list from example xml
-    const expected = <Element[]>select(xpath.customerNameContent, dom);
+    const expected = <Element[]>select(xpath.customer.name.content, dom);
     expect(toTextArr(customer.name.content)).toEqual(toTextContentArr(expected));
   });
 
   test("should get correct customer email address from XML", () => {
-    expect(customer.eMail._text).toBe(select(xpath.customerEmail, dom));
+    expect(customer.eMail._text).toBe(select(xpath.customer.email, dom));
   });
 
   test("should get correct customer location city from XML", () => {
-    const expected = <Element[]>select(xpath.customerLocationCity, dom);
+    const expected = <Element[]>select(xpath.customer.location.city, dom);
     expect(customer.location.city[0]._text).toEqual(toTextContentArr(expected).pop());
   });
 
   test("should get correct customer location county code from XML", () => {
-    const expected = <Element[]>select(xpath.customerLocationCountryCode, dom);
+    const expected = <Element[]>select(xpath.customer.location.countryCode, dom);
     expect(customer.location.countryCode[0]._text).toEqual(toTextContentArr(expected).pop());
   });
 
   test("should get correct customer location post code from XML", () => {
-    const expected = <Element[]>select(xpath.customerLocationPostCode, dom);
+    const expected = <Element[]>select(xpath.customer.location.postCode, dom);
     expect(customer.location.postCode[0]._text).toEqual(toTextContentArr(expected).pop());
   });
 
   test("should get correct customer location further from XML", () => {
-    const expected = <Element[]>select(xpath.customerLocationFurther, dom);
+    const expected = <Element[]>select(xpath.customer.location.further, dom);
 
     for (var i = 0; i < expected.length; i++) {
       expect(customer.location.further[0].content[i]._text).toBe(expected[i].textContent);
diff --git a/tests/DCC/AdministrativeData.SoftwareListType.test.ts b/tests/DCC/AdministrativeData.SoftwareListType.test.ts
index 9d959d3..a996a84 100644
--- a/tests/DCC/AdministrativeData.SoftwareListType.test.ts
+++ b/tests/DCC/AdministrativeData.SoftwareListType.test.ts
@@ -8,12 +8,16 @@ import { SoftwareListType, DCCDocument, SoftwareType } from "../../src";
 
 const base = "//dcc:administrativeData/dcc:dccSoftware/dcc:software";
 const xpath = {
-  softwareNameContent: `${base}/dcc:name/dcc:content`,
-  softwareRelease: `string(${base}/dcc:release)`,
-  softwareType: `string(${base}/dcc:type)`,
-  softwareDescription: `${base}/dcc:description`,
-  softwareTypeId: `${base}/@id`,
-  softwareTypeRefType: `${base}/@refType`,
+  software: {
+    name: {
+      content: `${base}/dcc:name/dcc:content`,
+    },
+    release: `string(${base}/dcc:release)`,
+    type: `string(${base}/dcc:type)`,
+    description: `${base}/dcc:description`,
+    _id: `${base}/@id`,
+    _refType: `${base}/@refType`,
+  },
 };
 
 describe("DccSoftwareType", () => {
@@ -27,19 +31,19 @@ describe("DccSoftwareType", () => {
 
   test("should get correct software name content from XML", () => {
     // get expected list from example xml
-    const expected = <Element[]>select(xpath.softwareNameContent, dom);
+    const expected = <Element[]>select(xpath.software.name.content, dom);
     expect(toTextArr(software.name.content)).toEqual(toTextContentArr(expected));
   });
 
   test("should get correct software release version of software from XML", () => {
-    expect(software.release._text).toBe(select(xpath.softwareRelease, dom));
+    expect(software.release._text).toBe(select(xpath.software.release, dom));
   });
 
   /*
   test("should get correct software type of software from XML", () => {
     console.log(software);
-    if (select(xpath.softwareType, dom)) {
-      expect(software.type._text).toBe(select(xpath.softwareType, dom));
+    if (select(xpath.software.type, dom)) {
+      expect(software.type._text).toBe(select(xpath.software.type, dom));
     }
   });
   */
@@ -48,16 +52,16 @@ describe("DccSoftwareType", () => {
 
   /*
   test("should get correct software reftype ...", () => {
-    console.log(select(xpath.softwareTypeRefType, dom));
-    if (select(xpath.softwareTypeRefType, dom) != "") {
-      expect(software._attr.refType).toBe(select(xpath.softwareTypeRefType, dom));
+    console.log(select(xpath.software._refType, dom));
+    if (select(xpath.software._refType, dom) != "") {
+      expect(software._attr.refType).toBe(select(xpath.software._refType, dom));
     }
   });
 
   test("should get correct software id ...", () => {
-    console.log(select(xpath.softwareTypeId, dom));
-    if (select(xpath.softwareTypeId, dom) != "") {
-      expect(software._attr.id).toBe(select(xpath.softwareTypeId, dom));
+    console.log(select(xpath.software._id, dom));
+    if (select(xpath.software._id, dom) != "") {
+      expect(software._attr.id).toBe(select(xpath.software._id, dom));
     }
   });*/
 });
-- 
GitLab