@adobe/acc-js-sdk 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -23,6 +23,7 @@ const DomUtil = require('../src/domUtil.js').DomUtil;
23
23
  const Mock = require('./mock.js').Mock;
24
24
  const { HttpError } = require('../src/transport.js');
25
25
  const { Cipher } = require('../src/crypto.js');
26
+ const { EntityAccessor } = require('../src/entityAccessor.js');
26
27
 
27
28
 
28
29
  describe('ACC Client', function () {
@@ -1958,7 +1959,7 @@ describe('ACC Client', function () {
1958
1959
  });
1959
1960
 
1960
1961
  it("Expired session refresh client callback", async () => {
1961
- let refreshClient = async (client) => {
1962
+ let refreshClient = async () => {
1962
1963
  const connectionParameters = sdk.ConnectionParameters.ofSecurityToken("http://acc-sdk:8080",
1963
1964
  "$security_token$", {refreshClient: refreshClient});
1964
1965
  const newClient = await sdk.init(connectionParameters);
@@ -2011,12 +2012,12 @@ describe('ACC Client', function () {
2011
2012
  </SOAP-ENV:Envelope>`));
2012
2013
  client.traceAPICalls(false);
2013
2014
  var query1 = client.NLWS.xtkQueryDef.create(queryDef);
2014
- extAccount1 = await query1.executeQuery();
2015
+ const extAccount1 = await query1.executeQuery();
2015
2016
  expect(extAccount1).toEqual({ extAccount: [] });
2016
2017
  });
2017
2018
 
2018
2019
  it("Expired session refresh client callback for code coverage", async () => {
2019
- let refreshClient = async (client) => {
2020
+ let refreshClient = async () => {
2020
2021
  const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "$session_token$");
2021
2022
  const newClient = await sdk.init(connectionParameters);
2022
2023
  newClient._transport = jest.fn();
@@ -2058,7 +2059,7 @@ describe('ACC Client', function () {
2058
2059
  });
2059
2060
 
2060
2061
  it("Expired session refresh client callback retry failure", async () => {
2061
- let refreshClient = async (client) => {
2062
+ let refreshClient = async () => {
2062
2063
  const connectionParameters = sdk.ConnectionParameters.ofBearerToken("http://acc-sdk:8080",
2063
2064
  "$token$", {refreshClient: refreshClient});
2064
2065
  const newClient = await sdk.init(connectionParameters);
@@ -2282,15 +2283,15 @@ describe('ACC Client', function () {
2282
2283
  it("Should ignore protocol for local storage root key", async () => {
2283
2284
  var connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("http://acc-sdk:8080", "admin", "admin", {});
2284
2285
  var client = await sdk.init(connectionParameters);
2285
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.7.acc-sdk:8080.cache.OptionCache$");
2286
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.0.acc-sdk:8080.cache.OptionCache$");
2286
2287
 
2287
2288
  connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("https://acc-sdk:8080", "admin", "admin", {});
2288
2289
  client = await sdk.init(connectionParameters);
2289
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.7.acc-sdk:8080.cache.OptionCache$");
2290
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.0.acc-sdk:8080.cache.OptionCache$");
2290
2291
 
2291
2292
  connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("acc-sdk:8080", "admin", "admin", {});
2292
2293
  client = await sdk.init(connectionParameters);
2293
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.7.acc-sdk:8080.cache.OptionCache$");
2294
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.0.acc-sdk:8080.cache.OptionCache$");
2294
2295
  })
2295
2296
 
2296
2297
  it("Should support no storage", async () => {
@@ -2349,6 +2350,76 @@ describe('ACC Client', function () {
2349
2350
  expect(schema["namespace"]).toBe("nms");
2350
2351
  expect(schema["name"]).toBe("extAccount");
2351
2352
  });
2353
+ });
2354
+
2355
+ describe("Calling SOAP method with parameters as a function", () => {
2356
+ it("Should make SOAP call", async () => {
2357
+ const client = await Mock.makeClient();
2358
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
2359
+ await client.NLWS.xtkSession.logon();
2360
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
2361
+ client._transport.mockReturnValueOnce(Mock.GET_DATABASEID_RESPONSE);
2362
+ const scope = client.NLWS["xtkSession"];
2363
+ const fn = scope["getOption"];
2364
+ const result = await fn.call(scope, "XtkDatabaseId");
2365
+ expect(result).toMatchObject([ "uFE80000000000000F1FA913DD7CC7C480041161C", 6 ]);
2366
+ });
2352
2367
 
2368
+ it("Should make static SOAP call with functional parameters", async () => {
2369
+ const client = await Mock.makeClient();
2370
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
2371
+ await client.NLWS.xtkSession.logon();
2372
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
2373
+ const scope = client.NLWS["xtkSession"];
2374
+ const method = scope["staticP1"]; // SOAP method to call
2375
+ const paramsFn = jest.fn(); // function returning SOAP call parameters
2376
+ paramsFn.mockReturnValueOnce(["XtkDatabaseId"]);
2377
+
2378
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
2379
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:session' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
2380
+ <SOAP-ENV:Body>
2381
+ <StaticP1Response xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
2382
+ </StaticP1Response>
2383
+ </SOAP-ENV:Body>
2384
+ </SOAP-ENV:Envelope>`));
2385
+
2386
+ const result = await method.call(scope, paramsFn);
2387
+ expect(result).toBeNull();
2388
+ expect(paramsFn.mock.calls.length).toBe(1);
2389
+ // first parameter is the XML method
2390
+ const xmlMethod = paramsFn.mock.calls[0][0];
2391
+ expect(EntityAccessor.getAttributeAsString(xmlMethod, "name")).toBe("StaticP1");
2392
+ // second parameter is the call context
2393
+ expect(paramsFn.mock.calls[0][1]).toMatchObject({ schemaId: "xtk:session", namespace: "xtkSession" });
2394
+ });
2395
+
2396
+ it("Should make non static SOAP call with functional parameters", async () => {
2397
+ const client = await Mock.makeClient();
2398
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
2399
+ await client.NLWS.xtkSession.logon();
2400
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
2401
+ const scope = client.NLWS["xtkSession"];
2402
+ const method = scope["nonStaticP1"]; // SOAP method to call
2403
+ const paramsFn = jest.fn(); // function returning SOAP call parameters
2404
+ paramsFn.mockReturnValueOnce(["XtkDatabaseId"]);
2405
+
2406
+ client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
2407
+ <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:session' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
2408
+ <SOAP-ENV:Body>
2409
+ <StaticP1Response xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
2410
+ </StaticP1Response>
2411
+ </SOAP-ENV:Body>
2412
+ </SOAP-ENV:Envelope>`));
2413
+
2414
+ const object = scope.create({ dummy: true }); // "this" object for the non-static SOAP call
2415
+ const result = await method.call(object, paramsFn);
2416
+ expect(result).toBeNull();
2417
+ expect(paramsFn.mock.calls.length).toBe(1);
2418
+ // first parameter is the XML method
2419
+ const xmlMethod = paramsFn.mock.calls[0][0];
2420
+ expect(EntityAccessor.getAttributeAsString(xmlMethod, "name")).toBe("NonStaticP1");
2421
+ // second parameter is the call context
2422
+ expect(paramsFn.mock.calls[0][1]).toMatchObject({ schemaId: "xtk:session", namespace: "xtkSession" });
2423
+ });
2353
2424
  });
2354
2425
  });
@@ -18,8 +18,7 @@ governing permissions and limitations under the License.
18
18
  *********************************************************************************/
19
19
 
20
20
  const assert = require('assert');
21
- const { DomUtil } = require('../src/domUtil.js');
22
- const { Util } = require('../src/util.js');
21
+ const { DomUtil, XPath, XPathElement } = require('../src/domUtil.js');
23
22
 
24
23
 
25
24
  describe('DomUtil', function() {
@@ -546,4 +545,153 @@ describe('DomUtil', function() {
546
545
  });
547
546
  });
548
547
 
548
+ describe("XPath", () => {
549
+
550
+ it("Should create XPath", () => {
551
+ expect(new XPath("").asString()).toBe("");
552
+ expect(new XPath(" ").asString()).toBe("");
553
+ expect(new XPath(null).asString()).toBe("");
554
+ expect(new XPath(undefined).asString()).toBe("");
555
+ expect(new XPath("@name").asString()).toBe("@name");
556
+ expect(new XPath("country/@name").asString()).toBe("country/@name");
557
+ expect(new XPath("..").asString()).toBe("..");
558
+ expect(new XPath(".").asString()).toBe(".");
559
+ })
560
+
561
+ it("Should create expanded XPath", () => {
562
+ expect(new XPath("[@name]").asString()).toBe("@name");
563
+ expect(new XPath("[country/@name]").asString()).toBe("country/@name");
564
+ })
565
+
566
+ it("toString", () => {
567
+ expect(new XPath("").toString()).toBe("");
568
+ expect(new XPath(" ").toString()).toBe("");
569
+ expect(new XPath(null).toString()).toBe("");
570
+ expect(new XPath(undefined).toString()).toBe("");
571
+ expect(new XPath("@name").toString()).toBe("@name");
572
+ expect(new XPath("country/@name").toString()).toBe("country/@name");
573
+ expect(new XPath("..").toString()).toBe("..");
574
+ expect(new XPath(".").toString()).toBe(".");
575
+ })
576
+
577
+ it("Should test empty XPath", () => {
578
+ expect(new XPath("").isEmpty()).toBe(true);
579
+ expect(new XPath(" ").isEmpty()).toBe(true);
580
+ expect(new XPath(null).isEmpty()).toBe(true);
581
+ expect(new XPath(undefined).isEmpty()).toBe(true);
582
+ expect(new XPath("@name").isEmpty()).toBe(false);
583
+ expect(new XPath("country/@name").isEmpty()).toBe(false);
584
+ expect(new XPath("..").isEmpty()).toBe(false);
585
+ expect(new XPath(".").isEmpty()).toBe(false);
586
+ })
587
+
588
+ it("Should test absolute XPath", () => {
589
+ expect(new XPath("").isAbsolute()).toBe(false);
590
+ expect(new XPath(" ").isAbsolute()).toBe(false);
591
+ expect(new XPath(null).isAbsolute()).toBe(false);
592
+ expect(new XPath(undefined).isAbsolute()).toBe(false);
593
+ expect(new XPath("@name").isAbsolute()).toBe(false);
594
+ expect(new XPath("country/@name").isAbsolute()).toBe(false);
595
+ expect(new XPath("..").isAbsolute()).toBe(false);
596
+ expect(new XPath(".").isAbsolute()).toBe(false);
597
+ expect(new XPath("/").isAbsolute()).toBe(true);
598
+ expect(new XPath("/country/@name").isAbsolute()).toBe(true);
599
+ })
600
+
601
+ it("Should test self XPath", () => {
602
+ expect(new XPath("").isSelf()).toBe(false);
603
+ expect(new XPath(" ").isSelf()).toBe(false);
604
+ expect(new XPath(null).isSelf()).toBe(false);
605
+ expect(new XPath(undefined).isSelf()).toBe(false);
606
+ expect(new XPath("@name").isSelf()).toBe(false);
607
+ expect(new XPath("country/@name").isSelf()).toBe(false);
608
+ expect(new XPath("..").isSelf()).toBe(false);
609
+ expect(new XPath(".").isSelf()).toBe(true);
610
+ expect(new XPath("/").isSelf()).toBe(false);
611
+ expect(new XPath("/country/@name").isSelf()).toBe(false);
612
+ })
613
+
614
+ it("Should test root XPath", () => {
615
+ expect(new XPath("").isRootPath()).toBe(false);
616
+ expect(new XPath(" ").isRootPath()).toBe(false);
617
+ expect(new XPath(null).isRootPath()).toBe(false);
618
+ expect(new XPath(undefined).isRootPath()).toBe(false);
619
+ expect(new XPath("@name").isRootPath()).toBe(false);
620
+ expect(new XPath("country/@name").isRootPath()).toBe(false);
621
+ expect(new XPath("..").isRootPath()).toBe(false);
622
+ expect(new XPath(".").isRootPath()).toBe(false);
623
+ expect(new XPath("/").isRootPath()).toBe(true);
624
+ expect(new XPath("/country/@name").isRootPath()).toBe(false);
625
+ })
626
+
627
+ it("Should return XPath elements", () => {
628
+
629
+ function elements(xpath) {
630
+ const result = [];
631
+ const list = xpath.getElements();
632
+ for (const e of list) {
633
+ result.push(e._pathElement);
634
+ }
635
+ return result;
636
+ }
637
+
638
+ expect(elements(new XPath(""))).toEqual([ ]);
639
+ expect(elements(new XPath(" "))).toEqual([ ]);
640
+ expect(elements(new XPath(null))).toEqual([ ]);
641
+ expect(elements(new XPath(undefined))).toEqual([ ]);
642
+ expect(elements(new XPath("@name"))).toEqual([ "@name" ]);
643
+ expect(elements(new XPath("country/@name"))).toEqual([ "country", "@name" ]);
644
+ expect(elements(new XPath(".."))).toEqual([ ".." ]);
645
+ expect(elements(new XPath("."))).toEqual([ "." ]);
646
+ expect(elements(new XPath("/"))).toEqual([ ]);
647
+ expect(elements(new XPath("/country/@name"))).toEqual([ "country", "@name" ]);
648
+ })
649
+
650
+ it("Should get relative path", () => {
651
+ expect(new XPath("").getRelativePath().asString()).toBe("");
652
+ expect(new XPath(" ").getRelativePath().asString()).toBe("");
653
+ expect(new XPath(null).getRelativePath().asString()).toBe("");
654
+ expect(new XPath(undefined).getRelativePath().asString()).toBe("");
655
+ expect(new XPath("@name").getRelativePath().asString()).toBe("@name");
656
+ expect(new XPath("country/@name").getRelativePath().asString()).toBe("country/@name");
657
+ expect(new XPath("..").getRelativePath().asString()).toBe("..");
658
+ expect(new XPath(".").getRelativePath().asString()).toBe(".");
659
+ expect(new XPath("/").getRelativePath().asString()).toBe("");
660
+ expect(new XPath("/country/@name").getRelativePath().asString()).toBe("country/@name");
661
+ })
662
+ });
663
+
664
+ describe("XPathElement", () => {
665
+ it("Should create XPathElement", () => {
666
+ expect(() => { new XPathElement(""); }).toThrow("Invalid empty xpath element");
667
+ expect(() => { new XPathElement(" "); }).toThrow("Invalid empty xpath element");
668
+ expect(() => { new XPathElement(null); }).toThrow("Invalid empty xpath element");
669
+ expect(() => { new XPathElement(undefined); }).toThrow("Invalid empty xpath element");
670
+ expect(new XPathElement("@name").asString()).toBe("@name");
671
+ expect(new XPathElement("country").asString()).toBe("country");
672
+ expect(new XPathElement("..").asString()).toBe("..");
673
+ expect(new XPathElement(".").asString()).toBe(".");
674
+ })
675
+
676
+ it("toString", () => {
677
+ expect(new XPathElement("@name").toString()).toBe("@name");
678
+ expect(new XPathElement("country").toString()).toBe("country");
679
+ expect(new XPathElement("..").toString()).toBe("..");
680
+ expect(new XPathElement(".").toString()).toBe(".");
681
+ })
682
+
683
+ it("Should test if path element is self", () => {
684
+ expect(new XPathElement("@name").isSelf()).toBe(false);
685
+ expect(new XPathElement("country").isSelf()).toBe(false);
686
+ expect(new XPathElement("..").isSelf()).toBe(false);
687
+ expect(new XPathElement(".").isSelf()).toBe(true);
688
+ })
689
+
690
+ it("Should test if path element is the parent path (..)", () => {
691
+ expect(new XPathElement("@name").isParent()).toBe(false);
692
+ expect(new XPathElement("country").isParent()).toBe(false);
693
+ expect(new XPathElement("..").isParent()).toBe(true);
694
+ expect(new XPathElement(".").isParent()).toBe(false);
695
+ })
696
+ })
549
697
  });
@@ -18,65 +18,97 @@ governing permissions and limitations under the License.
18
18
  *********************************************************************************/
19
19
  const sdk = require('../src/index.js');
20
20
 
21
- describe('escapeXtk', function() {
22
-
23
- describe('Escaping strings', function() {
24
- it("Should escape null strings", () => {
25
- expect(sdk.escapeXtk(null)).toBe("''");
26
- });
27
-
28
- it("Should escape undefined strings", () => {
29
- expect(sdk.escapeXtk(undefined)).toBe("''");
30
- });
31
-
32
- it("Should escape empty strings", () => {
33
- expect(sdk.escapeXtk("")).toBe("''");
34
- });
21
+ describe('escaping', function() {
35
22
 
36
- it("Should escape empty simple strings", () => {
37
- expect(sdk.escapeXtk("Hello")).toBe("'Hello'");
38
- expect(sdk.escapeXtk("Hello world")).toBe("'Hello world'");
39
- expect(sdk.escapeXtk(" ")).toBe("' '");
40
- });
23
+ describe('escapeXtk', function() {
24
+
25
+ describe('Escaping strings', function() {
26
+ it("Should escape null strings", () => {
27
+ expect(sdk.escapeXtk(null)).toBe("''");
28
+ });
29
+
30
+ it("Should escape undefined strings", () => {
31
+ expect(sdk.escapeXtk(undefined)).toBe("''");
32
+ });
33
+
34
+ it("Should escape empty strings", () => {
35
+ expect(sdk.escapeXtk("")).toBe("''");
36
+ });
37
+
38
+ it("Should escape empty simple strings", () => {
39
+ expect(sdk.escapeXtk("Hello")).toBe("'Hello'");
40
+ expect(sdk.escapeXtk("Hello world")).toBe("'Hello world'");
41
+ expect(sdk.escapeXtk(" ")).toBe("' '");
42
+ });
43
+
44
+ it("Should escape simple quotes", () => {
45
+ expect(sdk.escapeXtk("Hello 'world'")).toBe("'Hello \\'world\\''");
46
+ });
47
+ })
41
48
 
42
- it("Should escape simple quotes", () => {
43
- expect(sdk.escapeXtk("Hello 'world'")).toBe("'Hello \\'world\\''");
44
- });
45
- })
49
+ describe('Tagged template litteral', function() {
46
50
 
47
- describe('Tagged template litteral', function() {
51
+ it("Should escape in template litteral", () => {
52
+ expect(sdk.escapeXtk`Hello world`).toBe("Hello world");
53
+ expect(sdk.escapeXtk`Hello 'world'`).toBe("Hello 'world'"); // only variables are escaped
48
54
 
49
- it("Should escape in template litteral", () => {
50
- expect(sdk.escapeXtk`Hello world`).toBe("Hello world");
51
- expect(sdk.escapeXtk`Hello 'world'`).toBe("Hello 'world'"); // only variables are escaped
55
+ const empty = "";
56
+ expect(sdk.escapeXtk``).toBe("");
57
+ expect(sdk.escapeXtk`${empty}`).toBe("''");
52
58
 
53
- const empty = "";
54
- expect(sdk.escapeXtk``).toBe("");
55
- expect(sdk.escapeXtk`${empty}`).toBe("''");
59
+ const name = "Joe's";
60
+ expect(sdk.escapeXtk`Hello ${name}`).toBe("Hello 'Joe\\'s'"); // variable value is quoted and escaped
56
61
 
57
- const name = "Joe's";
58
- expect(sdk.escapeXtk`Hello ${name}`).toBe("Hello 'Joe\\'s'"); // variable value is quoted and escaped
62
+ // A more relevant test
63
+ const userName = 'Alex';
64
+ expect({ expr: sdk.escapeXtk`@name = ${userName}` }).toEqual({ expr: "@name = 'Alex'" });
59
65
 
60
- // A more relevant test
61
- const userName = 'Alex';
62
- expect({ expr: sdk.escapeXtk`@name = ${userName}` }).toEqual({ expr: "@name = 'Alex'" });
66
+ // Should support multiple variables
67
+ expect({ expr: sdk.escapeXtk`@name = ${userName} or @name = ${name}` }).toEqual({ expr: "@name = 'Alex' or @name = 'Joe\\'s'" });
68
+ })
63
69
 
64
- // Should support multiple variables
65
- expect({ expr: sdk.escapeXtk`@name = ${userName} or @name = ${name}` }).toEqual({ expr: "@name = 'Alex' or @name = 'Joe\\'s'" });
70
+ it("Should support constants", () => {
71
+ expect(sdk.escapeXtk([],[])).toBe("''");
72
+ })
66
73
  })
67
74
 
68
- it("Should support constants", () => {
69
- expect(sdk.escapeXtk([],[])).toBe("''");
75
+ it("examples in jsdoc", () => {
76
+ expect(sdk.escapeXtk("Rock 'n' Roll")).toBe("'Rock \\'n\\' Roll'");
77
+ expect(sdk.escapeXtk`@name=${"Rock 'n' Roll"}`).toBe("@name='Rock \\'n\\' Roll'");
78
+ });
79
+
80
+ describe('QueryDef & template litteral', () => {
81
+
70
82
  })
71
- })
72
83
 
73
- it("examples in jsdoc", () => {
74
- expect(sdk.escapeXtk("Rock 'n' Roll")).toBe("'Rock \\'n\\' Roll'");
75
- expect(sdk.escapeXtk`@name=${"Rock 'n' Roll"}`).toBe("@name='Rock \\'n\\' Roll'");
76
84
  });
77
85
 
78
- describe('QueryDef & template litteral', () => {
79
-
80
- })
86
+ describe('escapeForLike', function() {
87
+ it('Should support null and undefined', () => {
88
+ expect(sdk.escapeForLike(null)).toBe('');
89
+ expect(sdk.escapeForLike(undefined)).toBe('');
90
+ expect(sdk.escapeForLike('')).toBe('');
91
+ });
92
+
93
+ it('Should escape simple strings', () => {
94
+ expect(sdk.escapeForLike('Hello')).toBe('Hello');
95
+ expect(sdk.escapeForLike('Hello world')).toBe('Hello world');
96
+ expect(sdk.escapeForLike('1234')).toBe('1234');
97
+ });
98
+
99
+ it('Should escape special chars', () => {
100
+ expect(sdk.escapeForLike('99.9%')).toBe('99.9\\%');
101
+ expect(sdk.escapeForLike("John 'Rusty' Toe")).toBe("John \\'Rusty\\' Toe");
102
+ expect(sdk.escapeForLike("Hello_Cruel_World")).toBe("Hello\\_Cruel\\_World");
103
+ expect(sdk.escapeForLike("John \\Rusty\\ Toe")).toBe("John \\\\Rusty\\\\ Toe");
104
+ // $ is not a special char
105
+ expect(sdk.escapeForLike('$99.9')).toBe('$99.9');
106
+ });
107
+
108
+ it('Should escape Xtk Variables', () => {
109
+ expect(sdk.escapeForLike('$99.9', false)).toBe('$99.9');
110
+ expect(sdk.escapeForLike('1+$id', true)).toBe("1+' + Char('36') + 'id");
111
+ });
112
+ });
81
113
 
82
- });
114
+ });
@@ -73,6 +73,74 @@ describe('ACC SDK', function() {
73
73
  sdk._transport(old);
74
74
  }
75
75
  });
76
- })
76
+ });
77
+
78
+ describe("expandXPath", () => {
79
+ it("Should support empty paths", () => {
80
+ expect(sdk.expandXPath(null)).toBe(null);
81
+ expect(sdk.expandXPath(undefined)).toBe(undefined);
82
+ expect(sdk.expandXPath("")).toBe("");
83
+ });
84
+
85
+ it("Should preserve already expanded xpath", () => {
86
+ expect(sdk.expandXPath("[@email]")).toBe("[@email]");
87
+ expect(sdk.expandXPath("[@recipient-id]")).toBe("[@recipient-id]");
88
+ expect(sdk.expandXPath("[recipient/@id]")).toBe("[recipient/@id]");
89
+ });
90
+
91
+ it("Should not add brackets if not necessary", () => {
92
+ expect(sdk.expandXPath("@email")).toBe("@email");
93
+ expect(sdk.expandXPath("@email_address")).toBe("@email_address");
94
+ });
95
+
96
+ it("Should add brackets if necessary", () => {
97
+ expect(sdk.expandXPath("@recipient-id")).toBe("[@recipient-id]");
98
+ expect(sdk.expandXPath("email/@address")).toBe("[email/@address]");
99
+ expect(sdk.expandXPath("nms:recipient")).toBe("[nms:recipient]");
100
+ });
101
+ });
102
+
103
+ describe("unexpandXPath", () => {
104
+ it("Should support empty paths", () => {
105
+ expect(sdk.unexpandXPath(null)).toBe(null);
106
+ expect(sdk.unexpandXPath(undefined)).toBe(undefined);
107
+ expect(sdk.unexpandXPath("")).toBe("");
108
+ });
109
+
110
+ it("Should remove brackets", () => {
111
+ expect(sdk.unexpandXPath("[@email]")).toBe("@email");
112
+ expect(sdk.unexpandXPath("[@recipient-id]")).toBe("@recipient-id");
113
+ expect(sdk.unexpandXPath("[recipient/@id]")).toBe("recipient/@id");
114
+ });
115
+
116
+ it("Should preseve already unexpanded pathx", () => {
117
+ expect(sdk.unexpandXPath("@email")).toBe("@email");
118
+ expect(sdk.unexpandXPath("@email_address")).toBe("@email_address");
119
+ });
120
+
121
+ it("Should support array-paths", () => {
122
+ expect(sdk.unexpandXPath("coll[0]")).toBe("coll[0]");
123
+ expect(sdk.unexpandXPath("[coll[0]]")).toBe("coll[0]");
124
+ });
125
+ });
126
+
127
+ describe("xtkConstText", () => {
128
+ it("Should handle various types", () => {
129
+ // Strings are quoted and escaped
130
+ expect(sdk.xtkConstText("Hello", "string")).toBe("'Hello'");
131
+ expect(sdk.xtkConstText("", "string")).toBe("''");
132
+ expect(sdk.xtkConstText(123, "string")).toBe("'123'");
133
+ expect(sdk.xtkConstText("Hello'World", "memo")).toBe("'Hello\\'World'");
134
+ // Numbers are unchanged
135
+ expect(sdk.xtkConstText(123, "long")).toBe("123");
136
+ expect(sdk.xtkConstText(-42.3, "double")).toBe("-42.3");
137
+ expect(sdk.xtkConstText("", "long")).toBe("0");
138
+ expect(sdk.xtkConstText(undefined, "short")).toBe("0");
139
+ // Timestamps are surrounded by ##
140
+ expect(sdk.xtkConstText("2022-02-15T09:49:04.000Z", "datetime")).toBe("#2022-02-15T09:49:04.000Z#");
141
+ expect(sdk.xtkConstText("", "datetime")).toBe("##");
142
+ expect(sdk.xtkConstText(undefined, "date")).toBe("##");
143
+ });
144
+ });
77
145
 
78
146
  });
package/test/mock.js CHANGED
@@ -230,7 +230,17 @@ const GET_XTK_SESSION_SCHEMA_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
230
230
  </method>
231
231
  <method name="NonStatic"></method>
232
232
  <method name="TestCnx" static="true"></method>
233
- </methods>
233
+ <method name="NonStaticP1">
234
+ <parameters>
235
+ <param name="name" type="string"/>
236
+ </parameters>
237
+ </method>
238
+ <method name="StaticP1" static="true">
239
+ <parameters>
240
+ <param name="name" type="string"/>
241
+ </parameters>
242
+ </method>
243
+ </methods>
234
244
  </schema>
235
245
  </pdomDoc>
236
246
  </GetEntityIfMoreRecentResponse>
@@ -0,0 +1,64 @@
1
+ /*
2
+ Copyright 2020 Adobe. All rights reserved.
3
+ This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License. You may obtain a copy
5
+ of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software distributed under
8
+ the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ OF ANY KIND, either express or implied. See the License for the specific language
10
+ governing permissions and limitations under the License.
11
+ */
12
+
13
+ const sdk = require("../src");
14
+ const { DomUtil } = require("../src/domUtil");
15
+
16
+ describe('TestUtil', function() {
17
+
18
+ describe('Creating test schema', () => {
19
+ it ('Should create schema from string', () => {
20
+ const schema = sdk.TestUtil.newSchema(`
21
+ <schema namespace="nms" name="recipient">
22
+ <enumeration name="gender" basetype="byte">
23
+ <value name="unknown" label="None specified" value="0"/>
24
+ <value name="male" label="Male" value="1"/>
25
+ <value name="female" label="Female" value="2"/>
26
+ </enumeration>
27
+ <element name="recipient">
28
+ <attribute name="id" type="long"/>
29
+ <attribute name="email" type="string"/>
30
+ <attribute name="age" type="long"/>
31
+ <attribute name="gender" type="long" enum="nms:recipient:gender"/>
32
+ </element>
33
+ </schema>
34
+ `);
35
+ expect(schema.id).toBe("nms:recipient");
36
+ });
37
+
38
+ it ('Should create schema from XML', () => {
39
+ const xml = DomUtil.parse(`
40
+ <schema namespace="nms" name="recipient">
41
+ <enumeration name="gender" basetype="byte">
42
+ <value name="unknown" label="None specified" value="0"/>
43
+ <value name="male" label="Male" value="1"/>
44
+ <value name="female" label="Female" value="2"/>
45
+ </enumeration>
46
+ <element name="recipient">
47
+ <attribute name="id" type="long"/>
48
+ <attribute name="email" type="string"/>
49
+ <attribute name="age" type="long"/>
50
+ <attribute name="gender" type="long" enum="nms:recipient:gender"/>
51
+ </element>
52
+ </schema>
53
+ `);
54
+ // From DOM document
55
+ let schema = sdk.TestUtil.newSchema(xml);
56
+ expect(schema.id).toBe("nms:recipient");
57
+ // From DOM element
58
+ schema = sdk.TestUtil.newSchema(xml.documentElement);
59
+ expect(schema.id).toBe("nms:recipient");
60
+ });
61
+ });
62
+
63
+ });
64
+