@adobe/acc-js-sdk 1.0.6 → 1.0.9

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.
@@ -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
@@ -17,6 +17,17 @@ governing permissions and limitations under the License.
17
17
  *
18
18
  *********************************************************************************/
19
19
  const sdk = require('../src/index.js');
20
+ const crypto = require("crypto");
21
+
22
+ const makeKey = () => {
23
+ const a = [];
24
+ for (let i=0; i<32; i++) {
25
+ a.push(Math.floor(crypto.randomInt(0, 256)));
26
+ }
27
+ const buffer = Buffer.from(a);
28
+ const s = buffer.toString('base64');
29
+ return s;
30
+ }
20
31
 
21
32
  async function makeAnonymousClient(options) {
22
33
  const connectionParameters = sdk.ConnectionParameters.ofAnonymousUser("http://acc-sdk:8080", options);
@@ -219,7 +230,17 @@ const GET_XTK_SESSION_SCHEMA_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
219
230
  </method>
220
231
  <method name="NonStatic"></method>
221
232
  <method name="TestCnx" static="true"></method>
222
- </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>
223
244
  </schema>
224
245
  </pdomDoc>
225
246
  </GetEntityIfMoreRecentResponse>
@@ -280,37 +301,43 @@ const GET_XTK_QUERY_SCHEMA_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
280
301
  </SOAP-ENV:Body>
281
302
  </SOAP-ENV:Envelope>`);
282
303
 
283
- const GET_MID_EXT_ACCOUNT_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
304
+ const GET_MID_EXT_ACCOUNT_RESPONSE = (encryptedPassword) => {
305
+ return Promise.resolve(`<?xml version='1.0'?>
284
306
  <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
285
307
  <SOAP-ENV:Body>
286
308
  <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
287
309
  <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
288
- <extAccount account="mid" id="2088" name="defaultEmailMid" password="@57QS5VHMb9BCsojLVrKI/Q==" server="http://ffdamid:8080" type="3"/>
310
+ <extAccount account="mid" id="2088" name="defaultEmailMid" password="${encryptedPassword}" server="http://ffdamid:8080" type="3"/>
289
311
  </pdomOutput>
290
312
  </ExecuteQueryResponse>
291
313
  </SOAP-ENV:Body>
292
314
  </SOAP-ENV:Envelope>`);
315
+ }
293
316
 
294
- const GET_BAD_EXT_ACCOUNT_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
317
+ const GET_BAD_EXT_ACCOUNT_RESPONSE = (encryptedPassword) => {
318
+ return Promise.resolve(`<?xml version='1.0'?>
295
319
  <SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:xtk:queryDef' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
296
320
  <SOAP-ENV:Body>
297
321
  <ExecuteQueryResponse xmlns='urn:xtk:queryDef' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
298
322
  <pdomOutput xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
299
- <extAccount account="bad" id="2088" name="bad" password="@57QS5VHMb9BCsojLVrKI/Q==" server="http://zz:8080" type="999"/>
323
+ <extAccount account="bad" id="2088" name="bad" password="${encryptedPassword}" server="http://zz:8080" type="999"/>
300
324
  </pdomOutput>
301
325
  </ExecuteQueryResponse>
302
326
  </SOAP-ENV:Body>
303
327
  </SOAP-ENV:Envelope>`);
328
+ }
304
329
 
305
- const GET_SECRET_KEY_OPTION_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
330
+ const GET_SECRET_KEY_OPTION_RESPONSE = (key) => {
331
+ return Promise.resolve(`<?xml version='1.0'?>
306
332
  <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/'>
307
333
  <SOAP-ENV:Body>
308
334
  <GetOptionResponse xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
309
- <pstrValue xsi:type='xsd:string'>HMLmn6uvWr8wu1Akt8UORr07YbC64u1FVW7ENAxNjpo=</pstrValue>
335
+ <pstrValue xsi:type='xsd:string'>${key}</pstrValue>
310
336
  <pbtType xsi:type='xsd:byte'>6</pbtType>
311
337
  </GetOptionResponse>
312
338
  </SOAP-ENV:Body>
313
339
  </SOAP-ENV:Envelope>`);
340
+ }
314
341
 
315
342
  const GET_LOGON_MID_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
316
343
  <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/'>
@@ -594,6 +621,7 @@ exports.Mock = {
594
621
  makeClient: makeClient,
595
622
  makeAnonymousClient: makeAnonymousClient,
596
623
  withMockConsole: withMockConsole,
624
+ makeKey: makeKey,
597
625
  R_TEST: R_TEST,
598
626
  PING: PING,
599
627
  MC_PING: MC_PING,
package/test/soap.test.js CHANGED
@@ -154,11 +154,8 @@ describe('SOAP', function() {
154
154
  const env = DomUtil.parse(request.data).documentElement;
155
155
  const header = hasChildElement(env, "SOAP-ENV:Header");
156
156
  expect(DomUtil.findElement(header, "Cookie")).toBeFalsy();
157
- hasChildElement(header, "X-Security-Token");
158
157
  const body = hasChildElement(env, "SOAP-ENV:Body");
159
158
  const method = hasChildElement(body, "m:Empty", undefined, "xmlns:m", "urn:xtk:session", "SOAP-ENV:encodingStyle", "http://schemas.xmlsoap.org/soap/encoding/");
160
- // sessiontoken is always required as first parameter, even if not set
161
- expect(DomUtil.findElement(method, "sessiontoken")).toBeTruthy();
162
159
  });
163
160
 
164
161
  it('Should have set authentication tokens', function() {
@@ -168,11 +165,8 @@ describe('SOAP', function() {
168
165
  assert.equal(request.headers["Cookie"], "__sessiontoken=$session$", "Session token matches");
169
166
  const env = DomUtil.parse(request.data).documentElement;
170
167
  const header = hasChildElement(env, "SOAP-ENV:Header");
171
- hasChildElement(header, "Cookie", "__sessiontoken=$session$");
172
- hasChildElement(header, "X-Security-Token", "$security$");
173
168
  const body = hasChildElement(env, "SOAP-ENV:Body");
174
169
  const method = hasChildElement(body, "m:Empty");
175
- hasChildElement(method, "sessiontoken", "$session$", "xsi:type", "xsd:string");
176
170
  });
177
171
 
178
172
  it('Should set boolean parameters', function() {
@@ -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
+
@@ -428,7 +428,9 @@ describe('XtkCaster', function() {
428
428
  const value = expected[0];
429
429
  const expectedResult = expected[1];
430
430
  it('Should return the value casted as a timestamp ("' + value + '")', function() {
431
- const actual = XtkCaster.asTimestamp(value);
431
+ let actual = XtkCaster.asTimestamp(value);
432
+ assert.myEquals(actual, expectedResult);
433
+ actual = XtkCaster.asDatetime(value);
432
434
  assert.myEquals(actual, expectedResult);
433
435
  });
434
436
  it('Should return the value casted as type datetime', function() {
@@ -696,14 +698,22 @@ describe('XtkCaster', function() {
696
698
  expect(XtkCaster._variantStorageAttribute(6)).toBe("stringValue");
697
699
  expect(XtkCaster._variantStorageAttribute("string")).toBe("stringValue");
698
700
  expect(XtkCaster._variantStorageAttribute("int64")).toBe("stringValue");
701
+ expect(XtkCaster._variantStorageAttribute("uuid")).toBe("stringValue");
699
702
  expect(XtkCaster._variantStorageAttribute(12)).toBe("memoValue");
700
703
  expect(XtkCaster._variantStorageAttribute(13)).toBe("memoValue");
701
704
  expect(XtkCaster._variantStorageAttribute("memo")).toBe("memoValue");
702
705
  expect(XtkCaster._variantStorageAttribute("CDATA")).toBe("memoValue");
706
+ expect(XtkCaster._variantStorageAttribute("blob")).toBe("memoValue");
707
+ expect(XtkCaster._variantStorageAttribute("html")).toBe("memoValue");
703
708
  expect(XtkCaster._variantStorageAttribute(1)).toBe("longValue");
704
709
  expect(XtkCaster._variantStorageAttribute(2)).toBe("longValue");
705
710
  expect(XtkCaster._variantStorageAttribute(3)).toBe("longValue");
706
711
  expect(XtkCaster._variantStorageAttribute(15)).toBe("longValue");
712
+ expect(XtkCaster._variantStorageAttribute("byte")).toBe("longValue");
713
+ expect(XtkCaster._variantStorageAttribute("short")).toBe("longValue");
714
+ expect(XtkCaster._variantStorageAttribute("long")).toBe("longValue");
715
+ expect(XtkCaster._variantStorageAttribute("int")).toBe("longValue");
716
+ expect(XtkCaster._variantStorageAttribute("boolean")).toBe("longValue");
707
717
  expect(XtkCaster._variantStorageAttribute(4)).toBe("doubleValue");
708
718
  expect(XtkCaster._variantStorageAttribute(5)).toBe("doubleValue");
709
719
  expect(XtkCaster._variantStorageAttribute("float")).toBe("doubleValue");
@@ -716,4 +726,212 @@ describe('XtkCaster', function() {
716
726
  expect(XtkCaster._variantStorageAttribute("date")).toBe("timeStampValue");
717
727
  expect(() => { XtkCaster._variantStorageAttribute(777); }).toThrow("Cannot get variant storage");
718
728
  });
729
+
730
+ describe("Array tests", () => {
731
+ it("Should return array", () => {
732
+ expect(XtkCaster.asArray(null)).toStrictEqual([]);
733
+ expect(XtkCaster.asArray(undefined)).toStrictEqual([]);
734
+ expect(XtkCaster.asArray(false)).toStrictEqual([false]);
735
+ expect(XtkCaster.asArray("Hello")).toStrictEqual(["Hello"]);
736
+ expect(XtkCaster.asArray([])).toStrictEqual([]);
737
+ expect(XtkCaster.asArray([null])).toStrictEqual([null]);
738
+ })
739
+
740
+ it("Should support arrays", () => {
741
+ expect(XtkCaster.as(null, "array")).toStrictEqual([]);
742
+ expect(XtkCaster.as(undefined, "array")).toStrictEqual([]);
743
+ expect(XtkCaster.as(false, "array")).toStrictEqual([false]);
744
+ expect(XtkCaster.as("Hello", "array")).toStrictEqual(["Hello"]);
745
+ expect(XtkCaster.as([], "array")).toStrictEqual([]);
746
+ expect(XtkCaster.as([null], "array")).toStrictEqual([null]);
747
+ });
748
+ });
749
+
750
+ describe("Timespan test", () => {
751
+ it("Should return timespan", () => {
752
+ expect(XtkCaster.asTimespan(null)).toStrictEqual(0);
753
+ expect(XtkCaster.asTimespan(undefined)).toStrictEqual(0);
754
+ expect(XtkCaster.asTimespan(false)).toStrictEqual(0);
755
+ expect(XtkCaster.asTimespan("Hello")).toStrictEqual(0);
756
+ expect(XtkCaster.asTimespan([])).toStrictEqual(0);
757
+ expect(XtkCaster.asTimespan([null])).toStrictEqual(0);
758
+ expect(XtkCaster.asTimespan(NaN)).toStrictEqual(0);
759
+ expect(XtkCaster.asTimespan(Number.POSITIVE_INFINITY)).toStrictEqual(0);
760
+ expect(XtkCaster.asTimespan(Number.NEGATIVE_INFINITY)).toStrictEqual(0);
761
+ expect(XtkCaster.asTimespan("86400")).toStrictEqual(86400);
762
+ expect(XtkCaster.asTimespan(86400)).toStrictEqual(86400);
763
+ })
764
+
765
+ it("As should support 'timspan'", () => {
766
+ expect(XtkCaster.as(null, "timespan")).toStrictEqual(0);
767
+ expect(XtkCaster.as(undefined, "timespan")).toStrictEqual(0);
768
+ expect(XtkCaster.as(false, "timespan")).toStrictEqual(0);
769
+ expect(XtkCaster.as("Hello", "timespan")).toStrictEqual(0);
770
+ expect(XtkCaster.as([], "timespan")).toStrictEqual(0);
771
+ expect(XtkCaster.as([null], "timespan")).toStrictEqual(0);
772
+ expect(XtkCaster.as("86400", "timespan")).toStrictEqual(86400);
773
+ expect(XtkCaster.as(86400, "timespan")).toStrictEqual(86400);
774
+ });
775
+
776
+ it("As should support type 14", () => {
777
+ expect(XtkCaster.as(null, 14)).toStrictEqual(0);
778
+ expect(XtkCaster.as(undefined, 14)).toStrictEqual(0);
779
+ expect(XtkCaster.as(false, 14)).toStrictEqual(0);
780
+ expect(XtkCaster.as("Hello", 14)).toStrictEqual(0);
781
+ expect(XtkCaster.as([], 14)).toStrictEqual(0);
782
+ expect(XtkCaster.as([null], 14)).toStrictEqual(0);
783
+ expect(XtkCaster.as("86400", 14)).toStrictEqual(86400);
784
+ expect(XtkCaster.as(86400, 14)).toStrictEqual(86400);
785
+ });
786
+ })
787
+
788
+ describe("Other string types", () => {
789
+ it("Type 'html'", () => {
790
+ expect(XtkCaster.as(null, "html")).toStrictEqual("");
791
+ expect(XtkCaster.as(undefined, "html")).toStrictEqual("");
792
+ expect(XtkCaster.as("Hello", "html")).toStrictEqual("Hello");
793
+ expect(XtkCaster.as("0", "html")).toStrictEqual("0");
794
+ });
795
+
796
+ it("Type 'uuid'", () => {
797
+ expect(XtkCaster.as(null, "uuid")).toStrictEqual("");
798
+ expect(XtkCaster.as(undefined, "uuid")).toStrictEqual("");
799
+ expect(XtkCaster.as("Hello", "uuid")).toStrictEqual("Hello");
800
+ expect(XtkCaster.as("0", "uuid")).toStrictEqual("0");
801
+ });
802
+
803
+ it("Type 'blob'", () => {
804
+ expect(XtkCaster.as(null, "blob")).toStrictEqual("");
805
+ expect(XtkCaster.as(undefined, "blob")).toStrictEqual("");
806
+ expect(XtkCaster.as("Hello", "blob")).toStrictEqual("Hello");
807
+ expect(XtkCaster.as("0", "blob")).toStrictEqual("0");
808
+ });
809
+
810
+ it("Type 'int'", () => {
811
+ expect(XtkCaster.as(null, "int")).toStrictEqual(0);
812
+ expect(XtkCaster.as(undefined, "int")).toStrictEqual(0);
813
+ expect(XtkCaster.as("42", "int")).toStrictEqual(42);
814
+ expect(XtkCaster.as("0", "int")).toStrictEqual(0);
815
+ });
816
+ })
817
+
818
+ it("Should check time type", () => {
819
+ expect(XtkCaster.isTimeType(null)).toBe(false);
820
+ expect(XtkCaster.isTimeType(undefined)).toBe(false);
821
+ expect(XtkCaster.isTimeType(0)).toBe(false);
822
+ expect(XtkCaster.isTimeType("")).toBe(false);
823
+ expect(XtkCaster.isTimeType(6)).toBe(false);
824
+ expect(XtkCaster.isTimeType("string")).toBe(false);
825
+ expect(XtkCaster.isTimeType("int64")).toBe(false);
826
+ expect(XtkCaster.isTimeType("uuid")).toBe(false);
827
+ expect(XtkCaster.isTimeType(12)).toBe(false);
828
+ expect(XtkCaster.isTimeType(13)).toBe(false);
829
+ expect(XtkCaster.isTimeType("memo")).toBe(false);
830
+ expect(XtkCaster.isTimeType("CDATA")).toBe(false);
831
+ expect(XtkCaster.isTimeType("blob")).toBe(false);
832
+ expect(XtkCaster.isTimeType("html")).toBe(false);
833
+ expect(XtkCaster.isTimeType(1)).toBe(false);
834
+ expect(XtkCaster.isTimeType(2)).toBe(false);
835
+ expect(XtkCaster.isTimeType(3)).toBe(false);
836
+ expect(XtkCaster.isTimeType(15)).toBe(false);
837
+ expect(XtkCaster.isTimeType("byte")).toBe(false);
838
+ expect(XtkCaster.isTimeType("short")).toBe(false);
839
+ expect(XtkCaster.isTimeType("long")).toBe(false);
840
+ expect(XtkCaster.isTimeType("int")).toBe(false);
841
+ expect(XtkCaster.isTimeType("boolean")).toBe(false);
842
+ expect(XtkCaster.isTimeType(4)).toBe(false);
843
+ expect(XtkCaster.isTimeType(5)).toBe(false);
844
+ expect(XtkCaster.isTimeType("float")).toBe(false);
845
+ expect(XtkCaster.isTimeType("double")).toBe(false);
846
+ expect(XtkCaster.isTimeType(7)).toBe(true);
847
+ expect(XtkCaster.isTimeType(10)).toBe(true);
848
+ expect(XtkCaster.isTimeType("datetime")).toBe(true);
849
+ expect(XtkCaster.isTimeType("timestamp")).toBe(true);
850
+ expect(XtkCaster.isTimeType("datetimetz")).toBe(true);
851
+ expect(XtkCaster.isTimeType("datetimenotz")).toBe(true);
852
+ expect(XtkCaster.isTimeType("date")).toBe(true);
853
+ expect(XtkCaster.isTimeType(14)).toBe(true);
854
+ expect(XtkCaster.isTimeType("time")).toBe(true);
855
+ expect(XtkCaster.isTimeType("timespan")).toBe(true);
856
+ });
857
+
858
+ it("Should check string type", () => {
859
+ expect(XtkCaster.isStringType(null)).toBe(false);
860
+ expect(XtkCaster.isStringType(undefined)).toBe(false);
861
+ expect(XtkCaster.isStringType(0)).toBe(false);
862
+ expect(XtkCaster.isStringType("")).toBe(false);
863
+ expect(XtkCaster.isStringType(6)).toBe(true);
864
+ expect(XtkCaster.isStringType("string")).toBe(true);
865
+ expect(XtkCaster.isStringType("int64")).toBe(false);
866
+ expect(XtkCaster.isStringType("uuid")).toBe(false);
867
+ expect(XtkCaster.isStringType(12)).toBe(true);
868
+ expect(XtkCaster.isStringType(13)).toBe(true);
869
+ expect(XtkCaster.isStringType("memo")).toBe(true);
870
+ expect(XtkCaster.isStringType("CDATA")).toBe(true);
871
+ expect(XtkCaster.isStringType("blob")).toBe(true);
872
+ expect(XtkCaster.isStringType("html")).toBe(true);
873
+ expect(XtkCaster.isStringType(1)).toBe(false);
874
+ expect(XtkCaster.isStringType(2)).toBe(false);
875
+ expect(XtkCaster.isStringType(3)).toBe(false);
876
+ expect(XtkCaster.isStringType(15)).toBe(false);
877
+ expect(XtkCaster.isStringType("byte")).toBe(false);
878
+ expect(XtkCaster.isStringType("short")).toBe(false);
879
+ expect(XtkCaster.isStringType("long")).toBe(false);
880
+ expect(XtkCaster.isStringType("int")).toBe(false);
881
+ expect(XtkCaster.isStringType("boolean")).toBe(false);
882
+ expect(XtkCaster.isStringType(4)).toBe(false);
883
+ expect(XtkCaster.isStringType(5)).toBe(false);
884
+ expect(XtkCaster.isStringType("float")).toBe(false);
885
+ expect(XtkCaster.isStringType("double")).toBe(false);
886
+ expect(XtkCaster.isStringType(7)).toBe(false);
887
+ expect(XtkCaster.isStringType(10)).toBe(false);
888
+ expect(XtkCaster.isStringType("datetime")).toBe(false);
889
+ expect(XtkCaster.isStringType("timestamp")).toBe(false);
890
+ expect(XtkCaster.isStringType("datetimetz")).toBe(false);
891
+ expect(XtkCaster.isStringType("datetimenotz")).toBe(false);
892
+ expect(XtkCaster.isStringType("date")).toBe(false);
893
+ expect(XtkCaster.isStringType(14)).toBe(false);
894
+ expect(XtkCaster.isStringType("time")).toBe(false);
895
+ expect(XtkCaster.isStringType("timespan")).toBe(false);
896
+ });
897
+
898
+ it("Should check number type", () => {
899
+ expect(XtkCaster.isNumericType(null)).toBe(false);
900
+ expect(XtkCaster.isNumericType(undefined)).toBe(false);
901
+ expect(XtkCaster.isNumericType(0)).toBe(false);
902
+ expect(XtkCaster.isNumericType("")).toBe(false);
903
+ expect(XtkCaster.isNumericType(6)).toBe(false);
904
+ expect(XtkCaster.isNumericType("string")).toBe(false);
905
+ expect(XtkCaster.isNumericType("int64")).toBe(false);
906
+ expect(XtkCaster.isNumericType("uuid")).toBe(false);
907
+ expect(XtkCaster.isNumericType(12)).toBe(false);
908
+ expect(XtkCaster.isNumericType(13)).toBe(false);
909
+ expect(XtkCaster.isNumericType("memo")).toBe(false);
910
+ expect(XtkCaster.isNumericType("CDATA")).toBe(false);
911
+ expect(XtkCaster.isNumericType("blob")).toBe(false);
912
+ expect(XtkCaster.isNumericType("html")).toBe(false);
913
+ expect(XtkCaster.isNumericType(1)).toBe(true);
914
+ expect(XtkCaster.isNumericType(2)).toBe(true);
915
+ expect(XtkCaster.isNumericType(3)).toBe(true);
916
+ expect(XtkCaster.isNumericType(15)).toBe(false);
917
+ expect(XtkCaster.isNumericType("byte")).toBe(true);
918
+ expect(XtkCaster.isNumericType("short")).toBe(true);
919
+ expect(XtkCaster.isNumericType("long")).toBe(true);
920
+ expect(XtkCaster.isNumericType("int")).toBe(true);
921
+ expect(XtkCaster.isNumericType("boolean")).toBe(false);
922
+ expect(XtkCaster.isNumericType(4)).toBe(true);
923
+ expect(XtkCaster.isNumericType(5)).toBe(true);
924
+ expect(XtkCaster.isNumericType("float")).toBe(true);
925
+ expect(XtkCaster.isNumericType("double")).toBe(true);
926
+ expect(XtkCaster.isNumericType(7)).toBe(false);
927
+ expect(XtkCaster.isNumericType(10)).toBe(false);
928
+ expect(XtkCaster.isNumericType("datetime")).toBe(false);
929
+ expect(XtkCaster.isNumericType("timestamp")).toBe(false);
930
+ expect(XtkCaster.isNumericType("datetimetz")).toBe(false);
931
+ expect(XtkCaster.isNumericType("datetimenotz")).toBe(false);
932
+ expect(XtkCaster.isNumericType("date")).toBe(false);
933
+ expect(XtkCaster.isNumericType(14)).toBe(true);
934
+ expect(XtkCaster.isNumericType("time")).toBe(false);
935
+ expect(XtkCaster.isNumericType("timespan")).toBe(true);
936
+ });
719
937
  });