@adobe/acc-js-sdk 1.0.5 → 1.0.8
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.
- package/.github/workflows/codeql-analysis.yml +70 -0
- package/.vscode/launch.json +0 -1
- package/CHANGELOG.md +40 -0
- package/README.md +199 -63
- package/compile.js +3 -0
- package/package-lock.json +2175 -3383
- package/package.json +6 -7
- package/samples/002 - basics - schemas.js +3 -3
- package/samples/020 - encryption.js +5 -5
- package/src/application.js +427 -77
- package/src/cache.js +275 -0
- package/src/campaign.js +4 -0
- package/src/client.js +108 -30
- package/src/domUtil.js +6 -3
- package/src/entityAccessor.js +5 -5
- package/src/index.js +58 -2
- package/src/methodCache.js +21 -2
- package/src/optionCache.js +5 -1
- package/src/soap.js +46 -19
- package/src/testUtil.js +47 -0
- package/src/util.js +0 -229
- package/src/xtkCaster.js +80 -6
- package/src/xtkEntityCache.js +19 -3
- package/test/application.test.js +684 -616
- package/test/caches.test.js +148 -2
- package/test/client.test.js +341 -14
- package/test/crypto.test.js +16 -12
- package/test/domUtil.test.js +150 -2
- package/test/escape.test.js +79 -47
- package/test/index.test.js +69 -1
- package/test/mock.js +59 -9
- package/test/soap.test.js +0 -6
- package/test/testUtil.test.js +64 -0
- package/test/util.test.js +2 -1
- package/test/xtkCaster.test.js +219 -1
package/test/application.test.js
CHANGED
|
@@ -16,690 +16,758 @@ governing permissions and limitations under the License.
|
|
|
16
16
|
* Unit tests for the schema data objects
|
|
17
17
|
*
|
|
18
18
|
*********************************************************************************/
|
|
19
|
-
const {
|
|
19
|
+
const { SchemaCache } = require('../src/application.js');
|
|
20
|
+
const { DomUtil, XPath } = require('../src/domUtil.js');
|
|
21
|
+
const sdk = require('../src/index.js');
|
|
20
22
|
const newSchema = require('../src/application.js').newSchema;
|
|
21
23
|
const newCurrentLogin = require('../src/application.js').newCurrentLogin;
|
|
22
24
|
const Mock = require('./mock.js').Mock;
|
|
23
25
|
|
|
24
|
-
describe('
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
describe('Application', () => {
|
|
27
|
+
describe('Schemas', function() {
|
|
28
|
+
|
|
29
|
+
describe("Root node", () => {
|
|
30
|
+
|
|
31
|
+
it("No root node", () => {
|
|
32
|
+
var xml = DomUtil.parse("<schema namespace='nms' name='recipient'></schema>");
|
|
33
|
+
var schema = newSchema(xml);
|
|
34
|
+
var root = schema.root;
|
|
35
|
+
expect(root).toBeFalsy();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("Just the root node", () => {
|
|
39
|
+
var xml = DomUtil.parse("<schema namespace='nms' name='recipient'><element name='recipient' label='Recipients'/></schema>");
|
|
40
|
+
var schema = newSchema(xml);
|
|
41
|
+
var root = schema.root;
|
|
42
|
+
expect(root).toBeTruthy();
|
|
43
|
+
expect(root.name).toBe("recipient");
|
|
44
|
+
expect(root.label).toBe("Recipients");
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("Duplicate root nodes", () => {
|
|
48
|
+
expect(() => {
|
|
49
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
50
|
+
<element name='recipient' label='Recipients'/>
|
|
51
|
+
<element name='recipient' label='Recipients2'/>
|
|
52
|
+
</schema>`);
|
|
53
|
+
newSchema(xml);
|
|
54
|
+
}).toThrow("there's a already a node");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("Should find root node", () => {
|
|
58
|
+
const schema = sdk.TestUtil.newSchema(`
|
|
59
|
+
<schema namespace="nms" name="recipient">
|
|
60
|
+
<element name="recipient">
|
|
61
|
+
<attribute name="id" type="long"/>
|
|
62
|
+
<attribute name="name" type="string"/>
|
|
63
|
+
</element>
|
|
64
|
+
</schema>`);
|
|
65
|
+
expect(schema.root).toBeTruthy();
|
|
66
|
+
});
|
|
27
67
|
|
|
28
|
-
it("No root node", () => {
|
|
29
|
-
var xml = DomUtil.parse("<schema namespace='nms' name='recipient'></schema>");
|
|
30
|
-
var schema = newSchema(xml);
|
|
31
|
-
var root = schema.root;
|
|
32
|
-
expect(root).toBeFalsy();
|
|
33
68
|
});
|
|
34
69
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
70
|
+
describe("isRoot", () => {
|
|
71
|
+
it("Shema node is not root node", () => {
|
|
72
|
+
var xml = DomUtil.parse("<schema namespace='nms' name='recipient'><element name='recipient' label='Recipients'/></schema>");
|
|
73
|
+
var schema = newSchema(xml);
|
|
74
|
+
expect(schema.isRoot).toBeFalsy();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("Should be root node", () => {
|
|
78
|
+
var xml = DomUtil.parse("<schema namespace='nms' name='recipient'><element name='recipient' label='Recipients'/></schema>");
|
|
79
|
+
var schema = newSchema(xml);
|
|
80
|
+
var root = schema.root;
|
|
81
|
+
expect(root.isRoot).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("Should not be root node", () => {
|
|
85
|
+
var xml = DomUtil.parse("<schema namespace='nms' name='recipient'><element name='lib'/><element name='recipient' label='Recipients'/></schema>");
|
|
86
|
+
var schema = newSchema(xml);
|
|
87
|
+
var lib = schema.children["lib"];
|
|
88
|
+
expect(lib.isRoot).toBeFalsy();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("Should not be root node (second level with same name", () => {
|
|
92
|
+
var xml = DomUtil.parse("<schema namespace='nms' name='recipient'><element name='recipient' label='Recipients'><element name='recipient' label='Recipients (inner)'/></element></schema>");
|
|
93
|
+
var schema = newSchema(xml);
|
|
94
|
+
var root = schema.root;
|
|
95
|
+
var inner = root.children["recipient"];
|
|
96
|
+
expect(inner.label).toBe("Recipients (inner)")
|
|
97
|
+
expect(inner.isRoot).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
})
|
|
43
100
|
|
|
44
|
-
|
|
45
|
-
|
|
101
|
+
describe("Attributes", () => {
|
|
102
|
+
|
|
103
|
+
it("Should find unique attribute", () => {
|
|
46
104
|
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
47
|
-
<element name='recipient' label='Recipients'
|
|
48
|
-
|
|
105
|
+
<element name='recipient' label='Recipients'>
|
|
106
|
+
<attribute name='email' type='string' length='3'/>
|
|
107
|
+
</element>
|
|
49
108
|
</schema>`);
|
|
50
|
-
newSchema(xml);
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
109
|
+
var schema = newSchema(xml);
|
|
110
|
+
var root = schema.root;
|
|
111
|
+
expect(root.hasChild("@email")).toBe(true);
|
|
112
|
+
var email = root.children["@email"];
|
|
113
|
+
expect(email).not.toBeNull();
|
|
114
|
+
expect(email.name).toBe("@email");
|
|
115
|
+
expect(email.type).toBe("string");
|
|
116
|
+
expect(email.length).toBe(3);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("Should not find inexistant attribute", () => {
|
|
120
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
121
|
+
<element name='recipient' label='Recipients'>
|
|
122
|
+
<attribute name='email' type='string' length='3'/>
|
|
123
|
+
</element>
|
|
124
|
+
</schema>`);
|
|
125
|
+
var schema = newSchema(xml);
|
|
126
|
+
var root = schema.root;
|
|
127
|
+
expect(root.hasChild("email")).toBe(false);
|
|
128
|
+
expect(root.hasChild("@dummy")).toBe(false);
|
|
129
|
+
});
|
|
55
130
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
131
|
+
it("Should not find inexistant attribute (@-syntax)", () => {
|
|
132
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
133
|
+
<element name='recipient' label='Recipients'>
|
|
134
|
+
<attribute name='email' type='string' length='3'/>
|
|
135
|
+
</element>
|
|
136
|
+
</schema>`);
|
|
137
|
+
var schema = newSchema(xml);
|
|
138
|
+
var root = schema.root;
|
|
139
|
+
expect(root.hasChild("@email")).toBe(true);
|
|
140
|
+
expect(root.hasChild("email")).toBe(false);
|
|
141
|
+
});
|
|
61
142
|
});
|
|
62
143
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
144
|
+
describe("Children", () => {
|
|
145
|
+
it("Should browse root children", () => {
|
|
146
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
147
|
+
<element name='recipient' label='Recipients'>
|
|
148
|
+
<attribute name='email' type='string' length='3'/>
|
|
149
|
+
</element>
|
|
150
|
+
<element name='lib'/>
|
|
151
|
+
</schema>`);
|
|
152
|
+
var schema = newSchema(xml);
|
|
153
|
+
expect(schema.childrenCount).toBe(2);
|
|
154
|
+
expect(schema.children["recipient"]).not.toBeNull();
|
|
155
|
+
expect(schema.children["lib"]).not.toBeNull();
|
|
156
|
+
expect(schema.children["dummy"]).toBeFalsy();
|
|
157
|
+
});
|
|
68
158
|
});
|
|
69
159
|
|
|
70
|
-
|
|
71
|
-
var xml = DomUtil.parse("<schema namespace='nms' name='recipient'><element name='lib'/><element name='recipient' label='Recipients'/></schema>");
|
|
72
|
-
var schema = newSchema(xml);
|
|
73
|
-
var lib = schema.children["lib"];
|
|
74
|
-
expect(lib.isRoot).toBeFalsy();
|
|
75
|
-
});
|
|
160
|
+
describe("Find node", () => {
|
|
76
161
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
162
|
+
it("Should find nodes", () => {
|
|
163
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
164
|
+
<element name='recipient' label='Recipients'>
|
|
165
|
+
<attribute name='email' label="Email" type='string' length='3'/>
|
|
166
|
+
<element name='country' label="Country">
|
|
167
|
+
<attribute name='isoA3' label="Country name" type='string' length='3'/>
|
|
168
|
+
<attribute name='country-id' label="Country id" type='string' length='3'/>
|
|
169
|
+
<element name="terminal" label="Terminal"/>
|
|
170
|
+
</element>
|
|
171
|
+
</element>
|
|
172
|
+
</schema>`);
|
|
173
|
+
var schema = newSchema(xml);
|
|
174
|
+
var root = schema.root;
|
|
175
|
+
|
|
176
|
+
// Relative path
|
|
177
|
+
expect(root.findNode("@email").label).toBe("Email");
|
|
178
|
+
expect(root.findNode("country").label).toBe("Country");
|
|
179
|
+
expect(root.findNode("country/@isoA3").label).toBe("Country name");
|
|
180
|
+
expect(root.findNode("country/@country-id").label).toBe("Country id");
|
|
181
|
+
|
|
182
|
+
// Not found (defaut behavior throws)
|
|
183
|
+
expect(() => { root.findNode("@dummy"); }).toThrow("Unknown attribute 'dummy'");
|
|
184
|
+
expect(() => { root.findNode("dummy"); }).toThrow("Unknown element 'dummy'");
|
|
185
|
+
expect(() => { root.findNode("dummy/@dummy"); }).toThrow("Unknown element 'dummy'");
|
|
186
|
+
expect(() => { root.findNode("country/@dummy"); }).toThrow("Unknown attribute 'dummy'");
|
|
187
|
+
expect(() => { root.findNode("country/dummy/@dummy"); }).toThrow("Unknown element 'dummy'");
|
|
188
|
+
|
|
189
|
+
// Not found (mustExists=false)
|
|
190
|
+
expect(root.findNode("@dummy", true, false)).toBeNull();
|
|
191
|
+
expect(root.findNode("dummy", true, false)).toBeNull();
|
|
192
|
+
expect(root.findNode("dummy/@dummy", true, false)).toBeNull();
|
|
193
|
+
expect(root.findNode("country/@dummy", true, false)).toBeNull();
|
|
194
|
+
|
|
195
|
+
// Starting from schema
|
|
196
|
+
expect(schema.findNode("recipient").label).toBe('Recipients');
|
|
197
|
+
|
|
198
|
+
// Absolute path
|
|
199
|
+
expect(root.findNode("/@email").label).toBe("Email");
|
|
200
|
+
const country = root.findNode("country");
|
|
201
|
+
expect(country.findNode("/@email").label).toBe("Email");
|
|
202
|
+
expect(country.findNode("/country").label).toBe("Country");
|
|
203
|
+
|
|
204
|
+
// Self and parent
|
|
205
|
+
expect(country.findNode("./@isoA3").label).toBe("Country name");
|
|
206
|
+
expect(country.findNode("../@email").label).toBe("Email");
|
|
207
|
+
expect(country.findNode(".././@email").label).toBe("Email");
|
|
208
|
+
expect(country.findNode("./../@email").label).toBe("Email");
|
|
209
|
+
expect(root.findNode("./country/..").label).toBe("Recipients");
|
|
210
|
+
|
|
211
|
+
// Special cases
|
|
212
|
+
expect(root.findNode("").label).toBe("Recipients");
|
|
213
|
+
expect(root.findNode(".").label).toBe("Recipients");
|
|
214
|
+
|
|
215
|
+
// Non strict
|
|
216
|
+
expect(root.findNode("country/@isoA3", false, false).label).toBe("Country name");
|
|
217
|
+
expect(root.findNode("country/isoA3", false, false).label).toBe("Country name");
|
|
218
|
+
expect(country.findNode("@isoA3", false, false).label).toBe("Country name");
|
|
219
|
+
expect(country.findNode("isoA3", false, false).label).toBe("Country name");
|
|
220
|
+
expect(country.findNode("@terminal", false, false).label).toBe("Terminal");
|
|
221
|
+
expect(country.findNode("terminal", false, false).label).toBe("Terminal");
|
|
222
|
+
expect(country.findNode("@notFound", false, false)).toBeNull();
|
|
223
|
+
expect(country.findNode("notFound", false, false)).toBeNull();
|
|
224
|
+
|
|
225
|
+
// strict
|
|
226
|
+
expect(root.findNode("country/@isoA3", true, false).label).toBe("Country name");
|
|
227
|
+
expect(root.findNode("country/isoA3", true, false)).toBeNull();
|
|
228
|
+
expect(country.findNode("@isoA3", true, false).label).toBe("Country name");
|
|
229
|
+
expect(country.findNode("isoA3", true, false)).toBeNull();
|
|
230
|
+
expect(country.findNode("@terminal", true, false)).toBeNull();
|
|
231
|
+
expect(country.findNode("terminal", true, false).label).toBe("Terminal");
|
|
232
|
+
expect(country.findNode("@notFound", true, false)).toBeNull();
|
|
233
|
+
expect(country.findNode("notFound", true, false)).toBeNull();
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
it("Empty or absolute path requires a schema and root node", () => {
|
|
238
|
+
|
|
239
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
240
|
+
<element name='profile' label='Recipients'>
|
|
241
|
+
<attribute name='email' label="Email" type='string' length='3'/>
|
|
242
|
+
<element name='country' label="Country">
|
|
243
|
+
<attribute name='isoA3' label="Country name" type='string' length='3'/>
|
|
244
|
+
<attribute name='country-id' label="Country id" type='string' length='3'/>
|
|
245
|
+
</element>
|
|
246
|
+
</element>
|
|
247
|
+
</schema>`);
|
|
248
|
+
var schemaNoRoot = newSchema(xml);
|
|
249
|
+
var root = schemaNoRoot.root;
|
|
250
|
+
expect(root).toBeUndefined();
|
|
251
|
+
expect(() => { schemaNoRoot.findNode("") }).toThrow("does not have a root node");
|
|
252
|
+
expect(() => { schemaNoRoot.findNode("/") }).toThrow("does not have a root node");
|
|
253
|
+
|
|
254
|
+
var profile = schemaNoRoot.findNode("profile");
|
|
255
|
+
expect(profile).toBeTruthy();
|
|
256
|
+
expect(profile.findNode("country/@isoA3").label).toBe("Country name");
|
|
257
|
+
expect(() => { profile.findNode("/country/@isoA3") }).toThrow("does not have a root node");
|
|
258
|
+
expect(() => { profile.findNode("") }).toThrow("does not have a root node");
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("Should find node by xpath", () => {
|
|
262
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
263
|
+
<element name='recipient' label='Recipients'>
|
|
264
|
+
<attribute name='email' label="Email" type='string' length='3'/>
|
|
265
|
+
<element name='country' label="Country">
|
|
266
|
+
<attribute name='isoA3' label="Country name" type='string' length='3'/>
|
|
267
|
+
<attribute name='country-id' label="Country id" type='string' length='3'/>
|
|
268
|
+
</element>
|
|
269
|
+
</element>
|
|
270
|
+
</schema>`);
|
|
271
|
+
var schema = newSchema(xml);
|
|
272
|
+
var root = schema.root;
|
|
273
|
+
|
|
274
|
+
expect(root.findNode(new XPath("@email")).label).toBe("Email");
|
|
275
|
+
});
|
|
84
276
|
});
|
|
85
|
-
})
|
|
86
277
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
<
|
|
93
|
-
</
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
278
|
+
describe("Enumerations", () => {
|
|
279
|
+
it("Should list enumerations", () => {
|
|
280
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
281
|
+
<enumeration name="gender" basetype="byte"/>
|
|
282
|
+
<enumeration name="status" basetype="byte"/>
|
|
283
|
+
<element name='recipient' label='Recipients'></element>
|
|
284
|
+
</schema>`);
|
|
285
|
+
var schema = newSchema(xml);
|
|
286
|
+
var enumerations = schema.enumerations;
|
|
287
|
+
expect(enumerations.gender.dummy).toBeFalsy();
|
|
288
|
+
expect(enumerations.gender.name).toBe("gender");
|
|
289
|
+
expect(enumerations.status.name).toBe("status");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
it("Should set default label", () => {
|
|
293
|
+
const xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
294
|
+
<enumeration name="gender" basetype="byte"/>
|
|
295
|
+
<enumeration name="status" basetype="byte" label="Status code"/>
|
|
296
|
+
<element name='recipient' label='Recipients'></element>
|
|
297
|
+
</schema>`);
|
|
298
|
+
const schema = newSchema(xml);
|
|
299
|
+
const enumerations = schema.enumerations;
|
|
300
|
+
expect(enumerations.gender.label).toBe("Gender");
|
|
301
|
+
expect(enumerations.status.label).toBe("Status code");
|
|
302
|
+
});
|
|
303
|
+
|
|
304
|
+
it("Should test images", () => {
|
|
305
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
306
|
+
<enumeration name="gender" basetype="byte">
|
|
307
|
+
<value name="male" value="0"/>
|
|
308
|
+
<value name="female" value="1"/>
|
|
309
|
+
</enumeration>
|
|
310
|
+
<enumeration name="status" basetype="byte">
|
|
311
|
+
<value name="prospect" label="Prospect" value="0" img="xtk:prospect"/>
|
|
312
|
+
<value name="customer" label="Client" value="1"/>
|
|
313
|
+
</enumeration>
|
|
314
|
+
<enumeration name="status2" basetype="byte">
|
|
315
|
+
<value name="prospect" label="Prospect" value="0" img=""/>
|
|
316
|
+
<value name="customer" label="Client" value="1" img=""/>
|
|
317
|
+
</enumeration>
|
|
318
|
+
<element name='recipient' label='Recipients'>
|
|
319
|
+
<attribute advanced="true" desc="Recipient sex" enum="nms:recipient:gender"
|
|
320
|
+
label="Gender" name="gender" sqlname="iGender" type="byte"/>
|
|
321
|
+
</element>
|
|
322
|
+
</schema>`);
|
|
323
|
+
var schema = newSchema(xml);
|
|
324
|
+
var enumerations = schema.enumerations;
|
|
325
|
+
// no img attribute
|
|
326
|
+
expect(enumerations.gender.name).toBe("gender");
|
|
327
|
+
expect(enumerations.gender.hasImage).toBe(false);
|
|
328
|
+
// at least one img attribute
|
|
329
|
+
expect(enumerations.status.name).toBe("status");
|
|
330
|
+
expect(enumerations.status.hasImage).toBe(true);
|
|
331
|
+
// at least one img attribute
|
|
332
|
+
expect(enumerations.status2.name).toBe("status2");
|
|
333
|
+
expect(enumerations.status2.hasImage).toBe(false);
|
|
334
|
+
expect(schema.root.children["@gender"].enum).toBe("nms:recipient:gender");
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
it("Should list enumeration values", () => {
|
|
338
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
339
|
+
<enumeration name="gender" basetype="byte"/>
|
|
340
|
+
<enumeration name="status" basetype="byte">
|
|
341
|
+
<value name="prospect" label="Prospect" value="0"/>
|
|
342
|
+
<value name="customer" label="Client" value="1"/>
|
|
343
|
+
</enumeration>
|
|
344
|
+
<element name='recipient' label='Recipients'></element>
|
|
345
|
+
</schema>`);
|
|
346
|
+
var schema = newSchema(xml);
|
|
347
|
+
var enumerations = schema.enumerations;
|
|
348
|
+
expect(enumerations.status.values.prospect.label).toBe("Prospect");
|
|
349
|
+
expect(enumerations.status.values.customer.label).toBe("Client");
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
it("Should set default label", () => {
|
|
353
|
+
const xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
354
|
+
<enumeration name="gender" basetype="byte"/>
|
|
355
|
+
<enumeration name="status" basetype="byte">
|
|
356
|
+
<value name="prospect" value="0"/>
|
|
357
|
+
<value name="customer" label="Client" value="1"/>
|
|
358
|
+
</enumeration>
|
|
359
|
+
<element name='recipient' label='Recipients'></element>
|
|
360
|
+
</schema>`);
|
|
361
|
+
const schema = newSchema(xml);
|
|
362
|
+
const enumerations = schema.enumerations;
|
|
363
|
+
const status = enumerations.status.values;
|
|
364
|
+
expect(status.prospect.label).toBe("Prospect");
|
|
365
|
+
expect(status.customer.label).toBe("Client");
|
|
366
|
+
});
|
|
367
|
+
|
|
368
|
+
it("Byte enumerations", () => {
|
|
369
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
370
|
+
<enumeration basetype="byte" name="instanceType">
|
|
371
|
+
<value label="One-off event" name="single" value="0"/>
|
|
372
|
+
<value label="Reference recurrence" name="master" value="1"/>
|
|
373
|
+
<value label="Instance of a recurrence" name="instance" value="2"/>
|
|
374
|
+
<value label="Exception to a recurrence" name="exception" value="3"/>
|
|
375
|
+
</enumeration>
|
|
376
|
+
<element name='recipient' label='Recipients'></element>
|
|
377
|
+
</schema>`);
|
|
378
|
+
var schema = newSchema(xml);
|
|
379
|
+
var enumerations = schema.enumerations;
|
|
380
|
+
expect(enumerations.instanceType.values.single.label).toBe("One-off event");
|
|
381
|
+
expect(enumerations.instanceType.values.single.value).toBe(0);
|
|
382
|
+
})
|
|
104
383
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
384
|
+
it("Should support default values", () => {
|
|
385
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
386
|
+
<enumeration basetype="byte" name="instanceType" default="1">
|
|
387
|
+
<value label="One-off event" name="single" value="0"/>
|
|
388
|
+
<value label="Reference recurrence" name="master" value="1"/>
|
|
389
|
+
<value label="Instance of a recurrence" name="instance" value="2"/>
|
|
390
|
+
<value label="Exception to a recurrence" name="exception" value="3"/>
|
|
391
|
+
</enumeration>
|
|
392
|
+
<element name='recipient' label='Recipients'></element>
|
|
393
|
+
</schema>`);
|
|
394
|
+
var schema = newSchema(xml);
|
|
395
|
+
var enumerations = schema.enumerations;
|
|
396
|
+
expect(enumerations.instanceType.default.value).toBe(1);
|
|
397
|
+
});
|
|
115
398
|
});
|
|
116
399
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
<
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
400
|
+
describe("Keys", () => {
|
|
401
|
+
it("Should have key", () => {
|
|
402
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
403
|
+
<element name='recipient' label='Recipients'>
|
|
404
|
+
<key name="test">
|
|
405
|
+
<keyfield xpath="@email"/>
|
|
406
|
+
</key>
|
|
407
|
+
<attribute name='email' type='string' length='3'/>
|
|
408
|
+
</element>
|
|
409
|
+
</schema>`);
|
|
410
|
+
var schema = newSchema(xml);
|
|
411
|
+
var root = schema.root;
|
|
412
|
+
expect(root.keys.test).toBeTruthy();
|
|
413
|
+
expect(root.keys.test.fields["email"]).toBeFalsy();
|
|
414
|
+
expect(root.keys.test.fields["@email"]).toBeTruthy();
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
it("Should fail if keyfield does not have xpath", () => {
|
|
418
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
419
|
+
<element name='recipient' label='Recipients'>
|
|
420
|
+
<key name="test">
|
|
421
|
+
<keyfield/>
|
|
422
|
+
</key>
|
|
423
|
+
<attribute name='email' type='string' length='3'/>
|
|
424
|
+
</element>
|
|
425
|
+
</schema>`);
|
|
426
|
+
expect(() => { newSchema(xml) }).toThrow("keyfield does not have an xpath attribute");
|
|
427
|
+
});
|
|
127
428
|
});
|
|
128
|
-
});
|
|
129
429
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
430
|
+
describe("Link", () => {
|
|
431
|
+
it("Should have a link element", () => {
|
|
432
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
433
|
+
<element name='recipient' label='Recipients'>
|
|
434
|
+
<element integrity="neutral" label="Info on the email" name="emailInfo"
|
|
435
|
+
target="nms:address" type="link" unbound="true">
|
|
436
|
+
<join xpath-dst="@address" xpath-src="@email"/>
|
|
437
|
+
<join xpath-dst="@dst" xpath-src="@source"/>
|
|
438
|
+
</element>
|
|
439
|
+
</element>
|
|
440
|
+
</schema>`);
|
|
441
|
+
var schema = newSchema(xml);
|
|
442
|
+
var link = schema.root.children["emailInfo"];
|
|
443
|
+
expect(link.target).toBe("nms:address");
|
|
444
|
+
expect(link.integrity).toBe("neutral");
|
|
445
|
+
expect(link.isUnbound()).toBe(true);
|
|
446
|
+
expect(link.joins.length).toBe(2);
|
|
447
|
+
expect(link.joins[0].dst).toBe("@address");
|
|
448
|
+
expect(link.joins[0].src).toBe("@email");
|
|
449
|
+
|
|
450
|
+
xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
133
451
|
<element name='recipient' label='Recipients'>
|
|
134
|
-
<
|
|
452
|
+
<element integrity="neutral" label="Info on the email" name="emailInfo"
|
|
453
|
+
target="nms:address" type="link">
|
|
454
|
+
<join xpath-dst="@address" xpath-src="@email"/>
|
|
455
|
+
<join xpath-dst="@dst" xpath-src="@source"/>
|
|
456
|
+
</element>
|
|
135
457
|
</element>
|
|
136
|
-
<element name='lib'/>
|
|
137
458
|
</schema>`);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
expect(schema.children["dummy"]).toBeFalsy();
|
|
459
|
+
schema = newSchema(xml);
|
|
460
|
+
link = schema.root.children["emailInfo"];
|
|
461
|
+
expect(link.isUnbound()).toBe(false);
|
|
462
|
+
});
|
|
143
463
|
});
|
|
144
|
-
});
|
|
145
464
|
|
|
146
|
-
|
|
465
|
+
describe("getnodepath", () => {
|
|
147
466
|
|
|
148
|
-
it("Should find nodes", () => {
|
|
149
467
|
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
</element>
|
|
158
|
-
</schema>`);
|
|
468
|
+
<element name='recipient' label='Recipients'>
|
|
469
|
+
<attribute name='email' type='string' length='3'/>
|
|
470
|
+
<element name="country">
|
|
471
|
+
<attribute name='name'/>
|
|
472
|
+
</element>
|
|
473
|
+
</element>
|
|
474
|
+
</schema>`);
|
|
159
475
|
var schema = newSchema(xml);
|
|
160
476
|
var root = schema.root;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
expect(root.findNode("./country/..").label).toBe("Recipients");
|
|
196
|
-
|
|
197
|
-
// Special cases
|
|
198
|
-
expect(root.findNode("").label).toBe("Recipients");
|
|
199
|
-
expect(root.findNode(".").label).toBe("Recipients");
|
|
200
|
-
|
|
201
|
-
// Non strict
|
|
202
|
-
expect(root.findNode("country/@isoA3", false, false).label).toBe("Country name");
|
|
203
|
-
expect(root.findNode("country/isoA3", false, false).label).toBe("Country name");
|
|
204
|
-
expect(country.findNode("@isoA3", false, false).label).toBe("Country name");
|
|
205
|
-
expect(country.findNode("isoA3", false, false).label).toBe("Country name");
|
|
206
|
-
expect(country.findNode("@terminal", false, false).label).toBe("Terminal");
|
|
207
|
-
expect(country.findNode("terminal", false, false).label).toBe("Terminal");
|
|
208
|
-
expect(country.findNode("@notFound", false, false)).toBeNull();
|
|
209
|
-
expect(country.findNode("notFound", false, false)).toBeNull();
|
|
210
|
-
|
|
211
|
-
// strict
|
|
212
|
-
expect(root.findNode("country/@isoA3", true, false).label).toBe("Country name");
|
|
213
|
-
expect(root.findNode("country/isoA3", true, false)).toBeNull();
|
|
214
|
-
expect(country.findNode("@isoA3", true, false).label).toBe("Country name");
|
|
215
|
-
expect(country.findNode("isoA3", true, false)).toBeNull();
|
|
216
|
-
expect(country.findNode("@terminal", true, false)).toBeNull();
|
|
217
|
-
expect(country.findNode("terminal", true, false).label).toBe("Terminal");
|
|
218
|
-
expect(country.findNode("@notFound", true, false)).toBeNull();
|
|
219
|
-
expect(country.findNode("notFound", true, false)).toBeNull();
|
|
477
|
+
var email = root.findNode("@email");
|
|
478
|
+
var country = root.findNode("country");
|
|
479
|
+
var name = country.findNode("@name");
|
|
480
|
+
|
|
481
|
+
it("Should support nodePath property", () => {
|
|
482
|
+
expect(schema.nodePath).toBe("/recipient");
|
|
483
|
+
expect(root.nodePath).toBe("/");
|
|
484
|
+
expect(email.nodePath).toBe("/@email");
|
|
485
|
+
expect(country.nodePath).toBe("/country");
|
|
486
|
+
expect(name.nodePath).toBe("/country/@name");
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
it("_getNodePath", () => {
|
|
490
|
+
// No parameters => absolute
|
|
491
|
+
expect(schema._getNodePath()._path).toBe("/recipient");
|
|
492
|
+
expect(root._getNodePath()._path).toBe("/");
|
|
493
|
+
expect(email._getNodePath()._path).toBe("/@email");
|
|
494
|
+
expect(country._getNodePath()._path).toBe("/country");
|
|
495
|
+
expect(name._getNodePath()._path).toBe("/country/@name");
|
|
496
|
+
|
|
497
|
+
// Absolute
|
|
498
|
+
expect(schema._getNodePath(true)._path).toBe("/recipient");
|
|
499
|
+
expect(root._getNodePath(true)._path).toBe("/");
|
|
500
|
+
expect(email._getNodePath(true)._path).toBe("/@email");
|
|
501
|
+
expect(country._getNodePath(true)._path).toBe("/country");
|
|
502
|
+
expect(name._getNodePath(true)._path).toBe("/country/@name");
|
|
503
|
+
|
|
504
|
+
// Relative
|
|
505
|
+
expect(schema._getNodePath(false)._path).toBe("recipient");
|
|
506
|
+
expect(root._getNodePath(false)._path).toBe("");
|
|
507
|
+
expect(email._getNodePath(false)._path).toBe("@email");
|
|
508
|
+
expect(country._getNodePath(false)._path).toBe("country");
|
|
509
|
+
expect(name._getNodePath(false)._path).toBe("country/@name");
|
|
510
|
+
});
|
|
220
511
|
});
|
|
221
512
|
|
|
222
513
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
<
|
|
227
|
-
|
|
228
|
-
<
|
|
229
|
-
<attribute name='isoA3' label="Country name" type='string' length='3'/>
|
|
230
|
-
<attribute name='country-id' label="Country id" type='string' length='3'/>
|
|
231
|
-
</element>
|
|
514
|
+
describe("toString", () => {
|
|
515
|
+
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient' label="Recipients" labelSingular="Recipient">
|
|
516
|
+
<element name='recipient'>
|
|
517
|
+
<attribute name='email' type='string' length='3'/>
|
|
518
|
+
<element name="country">
|
|
519
|
+
<attribute name='name'/>
|
|
232
520
|
</element>
|
|
233
|
-
</
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
521
|
+
</element>
|
|
522
|
+
</schema>`);
|
|
523
|
+
|
|
524
|
+
it("Should stringify schema or schema node", async () => {
|
|
525
|
+
var schema = newSchema(xml);
|
|
526
|
+
var root = schema.root;
|
|
527
|
+
var email = root.findNode("@email");
|
|
528
|
+
var country = root.findNode("country");
|
|
529
|
+
var name = country.findNode("@name");
|
|
530
|
+
|
|
531
|
+
expect(schema.toString()).toBe(`Recipients (recipient)
|
|
532
|
+
- Recipient (recipient)
|
|
533
|
+
- Email (@email)
|
|
534
|
+
- Country (country)
|
|
535
|
+
- Name (@name)
|
|
536
|
+
`);
|
|
537
|
+
expect(root.toString()).toBe(`Recipient (recipient)
|
|
538
|
+
Email (@email)
|
|
539
|
+
Country (country)
|
|
540
|
+
Name (@name)
|
|
541
|
+
`);
|
|
542
|
+
expect(email.toString()).toBe("Email (@email)\n");
|
|
543
|
+
expect(country.toString()).toBe("Country (country)\n Name (@name)\n");
|
|
544
|
+
expect(name.toString()).toBe("Name (@name)\n");
|
|
545
|
+
});
|
|
546
|
+
})
|
|
246
547
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
548
|
+
describe("Node properties", () => {
|
|
549
|
+
it("Should have isSQL" , async () => {
|
|
550
|
+
const xml = DomUtil.parse(`<schema namespace='nms' name='recipient' label="Recipients" labelSingular="Recipient">
|
|
551
|
+
<element name='recipient' sqltable="NmsRecipient">
|
|
552
|
+
<attribute name='email' type='string' sqlname="semail"/>
|
|
553
|
+
<attribute name='test' type='string' xml="true"/>
|
|
554
|
+
</element>
|
|
555
|
+
</schema>`);
|
|
556
|
+
const schema = newSchema(xml);
|
|
557
|
+
expect(schema.root.isSQL).toBe(true);
|
|
558
|
+
let node = schema.root.findNode("@email");
|
|
559
|
+
expect(node.isSQL).toBe(true);
|
|
560
|
+
node = schema.root.findNode("@test");
|
|
561
|
+
expect(node.isSQL).toBe(false);
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
it("Should be memo and memo data" , async () => {
|
|
565
|
+
const xml = DomUtil.parse(`<schema namespace='nms' name='recipient' label="Recipients" labelSingular="Recipient">
|
|
566
|
+
<element name='recipient' sqltable="NmsRecipient">
|
|
567
|
+
<attribute name='email' type='string' sqlname="semail"/>
|
|
568
|
+
<attribute name='test' type='string' xml="true"/>
|
|
569
|
+
<attribute name='memo' type='memo'/>
|
|
570
|
+
<element name='data' type='memo' xml="true"/>
|
|
571
|
+
</element>
|
|
572
|
+
</schema>`);
|
|
573
|
+
const schema = newSchema(xml);
|
|
574
|
+
let node = schema.root.findNode("@email");
|
|
575
|
+
expect(node.isMemo).toBe(false);
|
|
576
|
+
expect(node.isMemoData).toBe(false);
|
|
577
|
+
node = schema.root.findNode("@test");
|
|
578
|
+
expect(node.isMemo).toBe(false);
|
|
579
|
+
expect(node.isMemoData).toBe(false);
|
|
580
|
+
node = schema.root.findNode("@memo");
|
|
581
|
+
expect(node.isMemo).toBe(true);
|
|
582
|
+
expect(node.isMemoData).toBe(false);
|
|
583
|
+
node = schema.root.findNode("data");
|
|
584
|
+
expect(node.isMemo).toBe(true);
|
|
585
|
+
expect(node.isMemoData).toBe(true);
|
|
586
|
+
});
|
|
587
|
+
|
|
588
|
+
it("Should be test isNotNull" , async () => {
|
|
589
|
+
const xml = DomUtil.parse(`<schema namespace='nms' name='recipient' label="Recipients" labelSingular="Recipient">
|
|
590
|
+
<element name='recipient'>
|
|
591
|
+
<attribute name='id' type='long'/>
|
|
592
|
+
<attribute name='b' type='byte'/>
|
|
593
|
+
<attribute name='s' type='short'/>
|
|
594
|
+
<attribute name='f' type='float'/>
|
|
595
|
+
<attribute name='d' type='double'/>
|
|
596
|
+
<attribute name='i' type='int64'/>
|
|
597
|
+
<attribute name='m' type='money'/>
|
|
598
|
+
<attribute name='p' type='percent'/>
|
|
599
|
+
<attribute name='t' type='time'/>
|
|
600
|
+
<attribute name='b0' type='boolean'/>
|
|
601
|
+
<attribute name='email' type='string'/>
|
|
602
|
+
|
|
603
|
+
<attribute name='snn' type='string'/>
|
|
604
|
+
<attribute name='snnt' type='string' notNull='true'/>
|
|
605
|
+
<attribute name='snnf' type='string' notNull='false'/>
|
|
606
|
+
|
|
607
|
+
<attribute name='lnn' type='long'/>
|
|
608
|
+
<attribute name='lnnt' type='long' notNull='true'/>
|
|
609
|
+
<attribute name='lnnf' type='long' notNull='false'/>
|
|
610
|
+
</element>
|
|
611
|
+
</schema>`);
|
|
612
|
+
const schema = newSchema(xml);
|
|
613
|
+
let node = schema.root.findNode("@email"); expect(node.isNotNull).toBe(false);
|
|
614
|
+
node = schema.root.findNode("@id"); expect(node.isNotNull).toBe(true);
|
|
615
|
+
node = schema.root.findNode("@b"); expect(node.isNotNull).toBe(true);
|
|
616
|
+
node = schema.root.findNode("@s"); expect(node.isNotNull).toBe(true);
|
|
617
|
+
node = schema.root.findNode("@f"); expect(node.isNotNull).toBe(true);
|
|
618
|
+
node = schema.root.findNode("@d"); expect(node.isNotNull).toBe(true);
|
|
619
|
+
node = schema.root.findNode("@i"); expect(node.isNotNull).toBe(true);
|
|
620
|
+
node = schema.root.findNode("@m"); expect(node.isNotNull).toBe(true);
|
|
621
|
+
node = schema.root.findNode("@p"); expect(node.isNotNull).toBe(true);
|
|
622
|
+
node = schema.root.findNode("@t"); expect(node.isNotNull).toBe(true);
|
|
623
|
+
node = schema.root.findNode("@b0"); expect(node.isNotNull).toBe(true);
|
|
624
|
+
|
|
625
|
+
node = schema.root.findNode("@snn"); expect(node.isNotNull).toBe(false);
|
|
626
|
+
node = schema.root.findNode("@snnt"); expect(node.isNotNull).toBe(true);
|
|
627
|
+
node = schema.root.findNode("@snnf"); expect(node.isNotNull).toBe(false);
|
|
628
|
+
|
|
629
|
+
node = schema.root.findNode("@lnn"); expect(node.isNotNull).toBe(true);
|
|
630
|
+
node = schema.root.findNode("@lnnt"); expect(node.isNotNull).toBe(true);
|
|
631
|
+
node = schema.root.findNode("@lnnf"); expect(node.isNotNull).toBe(false);
|
|
632
|
+
});
|
|
633
|
+
|
|
634
|
+
it("Should test user description" , async () => {
|
|
635
|
+
let xml = DomUtil.parse(`<schema namespace='nms' name='recipient' label="Recipients" labelSingular="Recipient">
|
|
636
|
+
<element name='recipient'>
|
|
637
|
+
</element>
|
|
638
|
+
</schema>`);
|
|
639
|
+
let schema = newSchema(xml);
|
|
640
|
+
expect(schema.userDescription).toBe("Recipients (recipient)");
|
|
259
641
|
|
|
260
|
-
|
|
642
|
+
xml = DomUtil.parse(`<schema namespace='nms' name='recipient' label="recipient">
|
|
643
|
+
<element name='recipient'>
|
|
644
|
+
</element>
|
|
645
|
+
</schema>`);
|
|
646
|
+
schema = newSchema(xml);
|
|
647
|
+
expect(schema.userDescription).toBe("recipient");
|
|
648
|
+
});
|
|
261
649
|
});
|
|
262
|
-
|
|
263
650
|
});
|
|
264
651
|
|
|
265
|
-
describe("
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
expect(
|
|
652
|
+
describe("CurrentLogin", () => {
|
|
653
|
+
|
|
654
|
+
it("Should create with SimpleJson", () => {
|
|
655
|
+
var op = newCurrentLogin({
|
|
656
|
+
login: "alex",
|
|
657
|
+
loginId: "12",
|
|
658
|
+
loginCS: "Alex",
|
|
659
|
+
timezone: "Europe/Paris",
|
|
660
|
+
"login-right": [
|
|
661
|
+
]
|
|
662
|
+
})
|
|
663
|
+
expect(op.login).toBe("alex");
|
|
664
|
+
expect(op.id).toBe(12);
|
|
665
|
+
expect(op.computeString).toBe("Alex");
|
|
666
|
+
expect(op.timezone).toBe("Europe/Paris");
|
|
667
|
+
expect(op.rights).toEqual([]);
|
|
277
668
|
})
|
|
278
669
|
|
|
279
|
-
it("Should
|
|
280
|
-
var
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
<value name="female" value="1"/>
|
|
284
|
-
</enumeration>
|
|
285
|
-
<enumeration name="status" basetype="byte">
|
|
286
|
-
<value name="prospect" label="Prospect" value="0" img="xtk:prospect"/>
|
|
287
|
-
<value name="customer" label="Client" value="1"/>
|
|
288
|
-
</enumeration>
|
|
289
|
-
<enumeration name="status2" basetype="byte">
|
|
290
|
-
<value name="prospect" label="Prospect" value="0" img=""/>
|
|
291
|
-
<value name="customer" label="Client" value="1" img=""/>
|
|
292
|
-
</enumeration>
|
|
293
|
-
<element name='recipient' label='Recipients'></element>
|
|
294
|
-
</schema>`);
|
|
295
|
-
var schema = newSchema(xml);
|
|
296
|
-
var enumerations = schema.enumerations;
|
|
297
|
-
// no img attribute
|
|
298
|
-
expect(enumerations.gender.name).toBe("gender");
|
|
299
|
-
expect(enumerations.gender.hasImage).toBe(false);
|
|
300
|
-
// at least one img attribute
|
|
301
|
-
expect(enumerations.status.name).toBe("status");
|
|
302
|
-
expect(enumerations.status.hasImage).toBe(true);
|
|
303
|
-
// at least one img attribute
|
|
304
|
-
expect(enumerations.status2.name).toBe("status2");
|
|
305
|
-
expect(enumerations.status2.hasImage).toBe(false);
|
|
670
|
+
it("Should support missing 'login-right' node", () => {
|
|
671
|
+
var op = newCurrentLogin({ login: "alex", loginId: "12", loginCS: "Alex" })
|
|
672
|
+
expect(op.rights).toEqual([]);
|
|
673
|
+
expect(op.hasRight("admin")).toBe(false);
|
|
306
674
|
})
|
|
307
675
|
|
|
308
|
-
it("Should
|
|
309
|
-
var
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
<value name="prospect" label="Prospect" value="0"/>
|
|
313
|
-
<value name="customer" label="Client" value="1"/>
|
|
314
|
-
</enumeration>
|
|
315
|
-
<element name='recipient' label='Recipients'></element>
|
|
316
|
-
</schema>`);
|
|
317
|
-
var schema = newSchema(xml);
|
|
318
|
-
var enumerations = schema.enumerations;
|
|
319
|
-
expect(enumerations.status.values.prospect.label).toBe("Prospect");
|
|
320
|
-
expect(enumerations.status.values.customer.label).toBe("Client");
|
|
676
|
+
it("Should support 'login-right' as an object", () => {
|
|
677
|
+
var op = newCurrentLogin({ login: "alex", loginId: "12", loginCS: "Alex", "login-right": { "right": "admin" } });
|
|
678
|
+
expect(op.rights).toEqual([ "admin" ]);
|
|
679
|
+
expect(op.hasRight("admin")).toBe(true);
|
|
321
680
|
})
|
|
322
681
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
<value label="Reference recurrence" name="master" value="1"/>
|
|
329
|
-
<value label="Instance of a recurrence" name="instance" value="2"/>
|
|
330
|
-
<value label="Exception to a recurrence" name="exception" value="3"/>
|
|
331
|
-
</enumeration>
|
|
332
|
-
<element name='recipient' label='Recipients'></element>
|
|
333
|
-
</schema>`);
|
|
334
|
-
var schema = newSchema(xml);
|
|
335
|
-
var enumerations = schema.enumerations;
|
|
336
|
-
expect(enumerations.instanceType.values.single.label).toBe("One-off event");
|
|
337
|
-
expect(enumerations.instanceType.values.single.value).toBe(0);
|
|
682
|
+
it("Should support 'login-right' as an object", () => {
|
|
683
|
+
var op = newCurrentLogin({ login: "alex", loginId: "12", loginCS: "Alex", "login-right": [ { "right": "admin" }, { "right": "delivery" } ] });
|
|
684
|
+
expect(op.rights).toEqual([ "admin", "delivery" ]);
|
|
685
|
+
expect(op.hasRight("admin")).toBe(true);
|
|
686
|
+
expect(op.hasRight("delivery")).toBe(true);
|
|
338
687
|
})
|
|
339
688
|
|
|
340
|
-
it("Should support default values", () => {
|
|
341
|
-
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
342
|
-
<enumeration basetype="byte" name="instanceType" default="1">
|
|
343
|
-
<value label="One-off event" name="single" value="0"/>
|
|
344
|
-
<value label="Reference recurrence" name="master" value="1"/>
|
|
345
|
-
<value label="Instance of a recurrence" name="instance" value="2"/>
|
|
346
|
-
<value label="Exception to a recurrence" name="exception" value="3"/>
|
|
347
|
-
</enumeration>
|
|
348
|
-
<element name='recipient' label='Recipients'></element>
|
|
349
|
-
</schema>`);
|
|
350
|
-
var schema = newSchema(xml);
|
|
351
|
-
var enumerations = schema.enumerations;
|
|
352
|
-
expect(enumerations.instanceType.default.value).toBe(1);
|
|
353
|
-
});
|
|
354
|
-
})
|
|
355
|
-
|
|
356
|
-
describe("Keys", () => {
|
|
357
|
-
it("Should have key", () => {
|
|
358
|
-
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
359
|
-
<element name='recipient' label='Recipients'>
|
|
360
|
-
<key name="test">
|
|
361
|
-
<keyfield xpath="@email"/>
|
|
362
|
-
</key>
|
|
363
|
-
<attribute name='email' type='string' length='3'/>
|
|
364
|
-
</element>
|
|
365
|
-
</schema>`);
|
|
366
|
-
var schema = newSchema(xml);
|
|
367
|
-
var root = schema.root;
|
|
368
|
-
expect(root.keys.test).toBeTruthy();
|
|
369
|
-
expect(root.keys.test.fields["email"]).toBeFalsy();
|
|
370
|
-
expect(root.keys.test.fields["@email"]).toBeTruthy();
|
|
371
|
-
})
|
|
372
|
-
|
|
373
|
-
it("Should fail if keyfield does not have xpath", () => {
|
|
374
|
-
var xml = DomUtil.parse(`<schema namespace='nms' name='recipient'>
|
|
375
|
-
<element name='recipient' label='Recipients'>
|
|
376
|
-
<key name="test">
|
|
377
|
-
<keyfield/>
|
|
378
|
-
</key>
|
|
379
|
-
<attribute name='email' type='string' length='3'/>
|
|
380
|
-
</element>
|
|
381
|
-
</schema>`);
|
|
382
|
-
expect(() => { newSchema(xml) }).toThrow("keyfield does not have an xpath attribute");
|
|
383
|
-
})
|
|
384
|
-
});
|
|
385
689
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
<attribute name='name'/>
|
|
392
|
-
</element>
|
|
393
|
-
</element>
|
|
394
|
-
</schema>`);
|
|
395
|
-
var schema = newSchema(xml);
|
|
396
|
-
var root = schema.root;
|
|
397
|
-
var email = root.findNode("@email");
|
|
398
|
-
var country = root.findNode("country");
|
|
399
|
-
var name = country.findNode("@name");
|
|
400
|
-
|
|
401
|
-
it("Should support nodePath property", () => {
|
|
402
|
-
expect(schema.nodePath).toBe("/recipient");
|
|
403
|
-
expect(root.nodePath).toBe("/");
|
|
404
|
-
expect(email.nodePath).toBe("/@email");
|
|
405
|
-
expect(country.nodePath).toBe("/country");
|
|
406
|
-
expect(name.nodePath).toBe("/country/@name");
|
|
407
|
-
});
|
|
690
|
+
describe("application.getSchema", () => {
|
|
691
|
+
it("Should return a XtkSchema object", async () => {
|
|
692
|
+
const client = await Mock.makeClient();
|
|
693
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
694
|
+
await client.NLWS.xtkSession.logon();
|
|
408
695
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
expect(country._getNodePath()._path).toBe("/country");
|
|
415
|
-
expect(name._getNodePath()._path).toBe("/country/@name");
|
|
416
|
-
|
|
417
|
-
// Absolute
|
|
418
|
-
expect(schema._getNodePath(true)._path).toBe("/recipient");
|
|
419
|
-
expect(root._getNodePath(true)._path).toBe("/");
|
|
420
|
-
expect(email._getNodePath(true)._path).toBe("/@email");
|
|
421
|
-
expect(country._getNodePath(true)._path).toBe("/country");
|
|
422
|
-
expect(name._getNodePath(true)._path).toBe("/country/@name");
|
|
423
|
-
|
|
424
|
-
// Relative
|
|
425
|
-
expect(schema._getNodePath(false)._path).toBe("recipient");
|
|
426
|
-
expect(root._getNodePath(false)._path).toBe("");
|
|
427
|
-
expect(email._getNodePath(false)._path).toBe("@email");
|
|
428
|
-
expect(country._getNodePath(false)._path).toBe("country");
|
|
429
|
-
expect(name._getNodePath(false)._path).toBe("country/@name");
|
|
430
|
-
});
|
|
431
|
-
});
|
|
696
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
697
|
+
const schema = await client.application.getSchema("xtk:session");
|
|
698
|
+
expect(schema.namespace).toBe("xtk");
|
|
699
|
+
expect(schema.name).toBe("session");
|
|
700
|
+
});
|
|
432
701
|
|
|
702
|
+
it("Should handle non-existing schemas", async () => {
|
|
703
|
+
const client = await Mock.makeClient();
|
|
704
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
705
|
+
await client.NLWS.xtkSession.logon();
|
|
433
706
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
<element name="country">
|
|
439
|
-
<attribute name='name'/>
|
|
440
|
-
</element>
|
|
441
|
-
</element>
|
|
442
|
-
</schema>`);
|
|
443
|
-
var schema = newSchema(xml);
|
|
444
|
-
var root = schema.root;
|
|
445
|
-
var email = root.findNode("@email");
|
|
446
|
-
var country = root.findNode("country");
|
|
447
|
-
var name = country.findNode("@name");
|
|
448
|
-
|
|
449
|
-
it("Should stringify schema or schema node", () => {
|
|
450
|
-
expect(schema.toString()).toBe(`recipient
|
|
451
|
-
- Recipients (recipient)
|
|
452
|
-
- @email
|
|
453
|
-
- country
|
|
454
|
-
- @name
|
|
455
|
-
`);
|
|
456
|
-
expect(root.toString()).toBe(`Recipients (recipient)
|
|
457
|
-
@email
|
|
458
|
-
country
|
|
459
|
-
@name
|
|
460
|
-
`);
|
|
461
|
-
expect(email.toString()).toBe("@email\n");
|
|
462
|
-
expect(country.toString()).toBe("country\n @name\n");
|
|
463
|
-
expect(name.toString()).toBe("@name\n");
|
|
707
|
+
client._transport.mockReturnValueOnce(Mock.GET_MISSING_SCHEMA_RESPONSE);
|
|
708
|
+
const schema = await client.application.getSchema("xtk:dummy")
|
|
709
|
+
expect(schema).toBeNull();
|
|
710
|
+
})
|
|
464
711
|
});
|
|
465
|
-
})
|
|
466
|
-
|
|
467
|
-
});
|
|
468
|
-
|
|
469
712
|
|
|
470
|
-
describe("
|
|
713
|
+
describe("application.hasPackage", () => {
|
|
714
|
+
it("Should verify if a package is installed", async () => {
|
|
715
|
+
const client = await Mock.makeClient();
|
|
716
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
717
|
+
await client.NLWS.xtkSession.logon();
|
|
718
|
+
expect(client.application.hasPackage("nms:core")).toBe(true);
|
|
719
|
+
expect(client.application.hasPackage("nms:campaign")).toBe(true);
|
|
720
|
+
expect(client.application.hasPackage("nms:dummy")).toBe(false);
|
|
721
|
+
expect(client.application.hasPackage("")).toBe(false);
|
|
722
|
+
expect(client.application.hasPackage(null)).toBe(false);
|
|
723
|
+
expect(client.application.hasPackage(undefined)).toBe(false);
|
|
724
|
+
})
|
|
725
|
+
})
|
|
726
|
+
});
|
|
471
727
|
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
728
|
+
describe("Application for anonymous users", () => {
|
|
729
|
+
it("Application objet should exist but will not have user/session info", async () => {
|
|
730
|
+
const client = await Mock.makeAnonymousClient();
|
|
731
|
+
expect(client.application).toBeNull();
|
|
732
|
+
await client.logon();
|
|
733
|
+
const application = client.application;
|
|
734
|
+
expect(application).not.toBeNull();
|
|
735
|
+
expect(application.buildNumber).toBeUndefined();
|
|
736
|
+
expect(application.instanceName).toBeUndefined();
|
|
737
|
+
expect(application.operator).toBeUndefined();
|
|
738
|
+
expect(application.package).toBeUndefined();
|
|
480
739
|
})
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
expect(op.rights).toEqual([]);
|
|
486
|
-
})
|
|
487
|
-
|
|
488
|
-
it("Should support missing 'login-right' node", () => {
|
|
489
|
-
var op = newCurrentLogin({ login: "alex", loginId: "12", loginCS: "Alex" })
|
|
490
|
-
expect(op.rights).toEqual([]);
|
|
491
|
-
expect(op.hasRight("admin")).toBe(false);
|
|
492
|
-
})
|
|
493
|
-
|
|
494
|
-
it("Should support 'login-right' as an object", () => {
|
|
495
|
-
var op = newCurrentLogin({ login: "alex", loginId: "12", loginCS: "Alex", "login-right": { "right": "admin" } });
|
|
496
|
-
expect(op.rights).toEqual([ "admin" ]);
|
|
497
|
-
expect(op.hasRight("admin")).toBe(true);
|
|
498
|
-
})
|
|
499
|
-
|
|
500
|
-
it("Should support 'login-right' as an object", () => {
|
|
501
|
-
var op = newCurrentLogin({ login: "alex", loginId: "12", loginCS: "Alex", "login-right": [ { "right": "admin" }, { "right": "delivery" } ] });
|
|
502
|
-
expect(op.rights).toEqual([ "admin", "delivery" ]);
|
|
503
|
-
expect(op.hasRight("admin")).toBe(true);
|
|
504
|
-
expect(op.hasRight("delivery")).toBe(true);
|
|
505
|
-
})
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
describe("application.getSchema", () => {
|
|
509
|
-
it("Should return a XtkSchema object", async () => {
|
|
740
|
+
});
|
|
741
|
+
|
|
742
|
+
describe("Schema Cache", () => {
|
|
743
|
+
it("Should search in empty cache", async () => {
|
|
510
744
|
const client = await Mock.makeClient();
|
|
511
745
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
512
746
|
await client.NLWS.xtkSession.logon();
|
|
747
|
+
const cache = new SchemaCache(client);
|
|
748
|
+
|
|
749
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
|
|
750
|
+
const schema = await cache.getSchema("xtk:queryDef");
|
|
751
|
+
expect(schema.id).toBe("xtk:queryDef");
|
|
513
752
|
|
|
514
|
-
|
|
515
|
-
const
|
|
516
|
-
expect(
|
|
517
|
-
expect(schema.name).toBe("session");
|
|
753
|
+
// Second call should not perform any API call
|
|
754
|
+
const schema2 = await cache.getSchema("xtk:queryDef");
|
|
755
|
+
expect(schema2.id).toBe("xtk:queryDef");
|
|
518
756
|
});
|
|
519
757
|
|
|
520
|
-
it("Should
|
|
758
|
+
it("Should support not found schemas", async () => {
|
|
521
759
|
const client = await Mock.makeClient();
|
|
522
760
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
523
761
|
await client.NLWS.xtkSession.logon();
|
|
762
|
+
const cache = new SchemaCache(client);
|
|
524
763
|
|
|
525
764
|
client._transport.mockReturnValueOnce(Mock.GET_MISSING_SCHEMA_RESPONSE);
|
|
526
|
-
const schema = await
|
|
527
|
-
expect(schema).
|
|
528
|
-
})
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
describe("application.hasPackage", () => {
|
|
532
|
-
it("Should verify if a package is installed", async () => {
|
|
533
|
-
const client = await Mock.makeClient();
|
|
534
|
-
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
535
|
-
await client.NLWS.xtkSession.logon();
|
|
536
|
-
expect(client.application.hasPackage("nms:core")).toBe(true);
|
|
537
|
-
expect(client.application.hasPackage("nms:campaign")).toBe(true);
|
|
538
|
-
expect(client.application.hasPackage("nms:dummy")).toBe(false);
|
|
539
|
-
expect(client.application.hasPackage("")).toBe(false);
|
|
540
|
-
expect(client.application.hasPackage(null)).toBe(false);
|
|
541
|
-
expect(client.application.hasPackage(undefined)).toBe(false);
|
|
542
|
-
})
|
|
543
|
-
})
|
|
765
|
+
const schema = await cache.getSchema("xtk:queryDef");
|
|
766
|
+
expect(schema).toBeFalsy();
|
|
544
767
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
expect(new XPath("").asString()).toBe("");
|
|
550
|
-
expect(new XPath(" ").asString()).toBe("");
|
|
551
|
-
expect(new XPath(null).asString()).toBe("");
|
|
552
|
-
expect(new XPath(undefined).asString()).toBe("");
|
|
553
|
-
expect(new XPath("@name").asString()).toBe("@name");
|
|
554
|
-
expect(new XPath("country/@name").asString()).toBe("country/@name");
|
|
555
|
-
expect(new XPath("..").asString()).toBe("..");
|
|
556
|
-
expect(new XPath(".").asString()).toBe(".");
|
|
557
|
-
})
|
|
558
|
-
|
|
559
|
-
it("toString", () => {
|
|
560
|
-
expect(new XPath("").toString()).toBe("");
|
|
561
|
-
expect(new XPath(" ").toString()).toBe("");
|
|
562
|
-
expect(new XPath(null).toString()).toBe("");
|
|
563
|
-
expect(new XPath(undefined).toString()).toBe("");
|
|
564
|
-
expect(new XPath("@name").toString()).toBe("@name");
|
|
565
|
-
expect(new XPath("country/@name").toString()).toBe("country/@name");
|
|
566
|
-
expect(new XPath("..").toString()).toBe("..");
|
|
567
|
-
expect(new XPath(".").toString()).toBe(".");
|
|
568
|
-
})
|
|
569
|
-
|
|
570
|
-
it("Should test empty XPath", () => {
|
|
571
|
-
expect(new XPath("").isEmpty()).toBe(true);
|
|
572
|
-
expect(new XPath(" ").isEmpty()).toBe(true);
|
|
573
|
-
expect(new XPath(null).isEmpty()).toBe(true);
|
|
574
|
-
expect(new XPath(undefined).isEmpty()).toBe(true);
|
|
575
|
-
expect(new XPath("@name").isEmpty()).toBe(false);
|
|
576
|
-
expect(new XPath("country/@name").isEmpty()).toBe(false);
|
|
577
|
-
expect(new XPath("..").isEmpty()).toBe(false);
|
|
578
|
-
expect(new XPath(".").isEmpty()).toBe(false);
|
|
579
|
-
})
|
|
580
|
-
|
|
581
|
-
it("Should test absolute XPath", () => {
|
|
582
|
-
expect(new XPath("").isAbsolute()).toBe(false);
|
|
583
|
-
expect(new XPath(" ").isAbsolute()).toBe(false);
|
|
584
|
-
expect(new XPath(null).isAbsolute()).toBe(false);
|
|
585
|
-
expect(new XPath(undefined).isAbsolute()).toBe(false);
|
|
586
|
-
expect(new XPath("@name").isAbsolute()).toBe(false);
|
|
587
|
-
expect(new XPath("country/@name").isAbsolute()).toBe(false);
|
|
588
|
-
expect(new XPath("..").isAbsolute()).toBe(false);
|
|
589
|
-
expect(new XPath(".").isAbsolute()).toBe(false);
|
|
590
|
-
expect(new XPath("/").isAbsolute()).toBe(true);
|
|
591
|
-
expect(new XPath("/country/@name").isAbsolute()).toBe(true);
|
|
592
|
-
})
|
|
593
|
-
|
|
594
|
-
it("Should test self XPath", () => {
|
|
595
|
-
expect(new XPath("").isSelf()).toBe(false);
|
|
596
|
-
expect(new XPath(" ").isSelf()).toBe(false);
|
|
597
|
-
expect(new XPath(null).isSelf()).toBe(false);
|
|
598
|
-
expect(new XPath(undefined).isSelf()).toBe(false);
|
|
599
|
-
expect(new XPath("@name").isSelf()).toBe(false);
|
|
600
|
-
expect(new XPath("country/@name").isSelf()).toBe(false);
|
|
601
|
-
expect(new XPath("..").isSelf()).toBe(false);
|
|
602
|
-
expect(new XPath(".").isSelf()).toBe(true);
|
|
603
|
-
expect(new XPath("/").isSelf()).toBe(false);
|
|
604
|
-
expect(new XPath("/country/@name").isSelf()).toBe(false);
|
|
605
|
-
})
|
|
606
|
-
|
|
607
|
-
it("Should test root XPath", () => {
|
|
608
|
-
expect(new XPath("").isRootPath()).toBe(false);
|
|
609
|
-
expect(new XPath(" ").isRootPath()).toBe(false);
|
|
610
|
-
expect(new XPath(null).isRootPath()).toBe(false);
|
|
611
|
-
expect(new XPath(undefined).isRootPath()).toBe(false);
|
|
612
|
-
expect(new XPath("@name").isRootPath()).toBe(false);
|
|
613
|
-
expect(new XPath("country/@name").isRootPath()).toBe(false);
|
|
614
|
-
expect(new XPath("..").isRootPath()).toBe(false);
|
|
615
|
-
expect(new XPath(".").isRootPath()).toBe(false);
|
|
616
|
-
expect(new XPath("/").isRootPath()).toBe(true);
|
|
617
|
-
expect(new XPath("/country/@name").isRootPath()).toBe(false);
|
|
618
|
-
})
|
|
619
|
-
|
|
620
|
-
it("Should return XPath elements", () => {
|
|
621
|
-
|
|
622
|
-
function elements(xpath) {
|
|
623
|
-
const result = [];
|
|
624
|
-
const list = xpath.getElements();
|
|
625
|
-
for (const e of list) {
|
|
626
|
-
result.push(e._pathElement);
|
|
627
|
-
}
|
|
628
|
-
return result;
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
expect(elements(new XPath(""))).toEqual([ ]);
|
|
632
|
-
expect(elements(new XPath(" "))).toEqual([ ]);
|
|
633
|
-
expect(elements(new XPath(null))).toEqual([ ]);
|
|
634
|
-
expect(elements(new XPath(undefined))).toEqual([ ]);
|
|
635
|
-
expect(elements(new XPath("@name"))).toEqual([ "@name" ]);
|
|
636
|
-
expect(elements(new XPath("country/@name"))).toEqual([ "country", "@name" ]);
|
|
637
|
-
expect(elements(new XPath(".."))).toEqual([ ".." ]);
|
|
638
|
-
expect(elements(new XPath("."))).toEqual([ "." ]);
|
|
639
|
-
expect(elements(new XPath("/"))).toEqual([ ]);
|
|
640
|
-
expect(elements(new XPath("/country/@name"))).toEqual([ "country", "@name" ]);
|
|
641
|
-
})
|
|
642
|
-
|
|
643
|
-
it("Should get relative path", () => {
|
|
644
|
-
expect(new XPath("").getRelativePath().asString()).toBe("");
|
|
645
|
-
expect(new XPath(" ").getRelativePath().asString()).toBe("");
|
|
646
|
-
expect(new XPath(null).getRelativePath().asString()).toBe("");
|
|
647
|
-
expect(new XPath(undefined).getRelativePath().asString()).toBe("");
|
|
648
|
-
expect(new XPath("@name").getRelativePath().asString()).toBe("@name");
|
|
649
|
-
expect(new XPath("country/@name").getRelativePath().asString()).toBe("country/@name");
|
|
650
|
-
expect(new XPath("..").getRelativePath().asString()).toBe("..");
|
|
651
|
-
expect(new XPath(".").getRelativePath().asString()).toBe(".");
|
|
652
|
-
expect(new XPath("/").getRelativePath().asString()).toBe("");
|
|
653
|
-
expect(new XPath("/country/@name").getRelativePath().asString()).toBe("country/@name");
|
|
654
|
-
})
|
|
768
|
+
// Second call should not perform any API call
|
|
769
|
+
const schema2 = await cache.getSchema("xtk:queryDef");
|
|
770
|
+
expect(schema2).toBeNull();
|
|
771
|
+
});
|
|
655
772
|
});
|
|
656
|
-
|
|
657
|
-
describe("XPathElement", () => {
|
|
658
|
-
it("Should create XPathElement", () => {
|
|
659
|
-
expect(() => { new XPathElement(""); }).toThrow("Invalid empty xpath element");
|
|
660
|
-
expect(() => { new XPathElement(" "); }).toThrow("Invalid empty xpath element");
|
|
661
|
-
expect(() => { new XPathElement(null); }).toThrow("Invalid empty xpath element");
|
|
662
|
-
expect(() => { new XPathElement(undefined); }).toThrow("Invalid empty xpath element");
|
|
663
|
-
expect(new XPathElement("@name").asString()).toBe("@name");
|
|
664
|
-
expect(new XPathElement("country").asString()).toBe("country");
|
|
665
|
-
expect(new XPathElement("..").asString()).toBe("..");
|
|
666
|
-
expect(new XPathElement(".").asString()).toBe(".");
|
|
667
|
-
})
|
|
668
|
-
|
|
669
|
-
it("toString", () => {
|
|
670
|
-
expect(new XPathElement("@name").toString()).toBe("@name");
|
|
671
|
-
expect(new XPathElement("country").toString()).toBe("country");
|
|
672
|
-
expect(new XPathElement("..").toString()).toBe("..");
|
|
673
|
-
expect(new XPathElement(".").toString()).toBe(".");
|
|
674
|
-
})
|
|
675
|
-
|
|
676
|
-
it("Should test if path element is self", () => {
|
|
677
|
-
expect(new XPathElement("@name").isSelf()).toBe(false);
|
|
678
|
-
expect(new XPathElement("country").isSelf()).toBe(false);
|
|
679
|
-
expect(new XPathElement("..").isSelf()).toBe(false);
|
|
680
|
-
expect(new XPathElement(".").isSelf()).toBe(true);
|
|
681
|
-
})
|
|
682
|
-
|
|
683
|
-
it("Should test if path element is the parent path (..)", () => {
|
|
684
|
-
expect(new XPathElement("@name").isParent()).toBe(false);
|
|
685
|
-
expect(new XPathElement("country").isParent()).toBe(false);
|
|
686
|
-
expect(new XPathElement("..").isParent()).toBe(true);
|
|
687
|
-
expect(new XPathElement(".").isParent()).toBe(false);
|
|
688
|
-
})
|
|
689
|
-
})
|
|
690
|
-
});
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
describe("Application for anonymous users", () => {
|
|
694
|
-
it("Application objet should exist but will not have user/session info", async () => {
|
|
695
|
-
const client = await Mock.makeAnonymousClient();
|
|
696
|
-
expect(client.application).toBeNull();
|
|
697
|
-
await client.logon();
|
|
698
|
-
const application = client.application;
|
|
699
|
-
expect(application).not.toBeNull();
|
|
700
|
-
expect(application.buildNumber).toBeUndefined();
|
|
701
|
-
expect(application.instanceName).toBeUndefined();
|
|
702
|
-
expect(application.operator).toBeUndefined();
|
|
703
|
-
expect(application.package).toBeUndefined();
|
|
704
|
-
})
|
|
705
773
|
});
|