@adobe/acc-js-sdk 1.1.16 → 1.1.18
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/docs/caches.html +25 -10
- package/docs/changeLog.html +15 -0
- package/docs/observability.html +115 -58
- package/package-lock.json +785 -922
- package/package.json +8 -8
- package/src/application.js +1 -1
- package/src/cacheRefresher.js +2 -1
- package/src/campaign.js +1 -1
- package/src/client.js +345 -181
- package/src/soap.js +3 -2
- package/test/application.test.js +28 -0
- package/test/client.test.js +84 -5
- package/test/mock.js +5 -0
- package/test/observability.test.js +149 -0
- package/test/soap.test.js +4 -4
package/src/soap.js
CHANGED
|
@@ -92,6 +92,7 @@ class SoapMethodCall {
|
|
|
92
92
|
// Current URN and method (for error reporting)
|
|
93
93
|
this.urn = urn;
|
|
94
94
|
this.methodName = methodName;
|
|
95
|
+
this.isStatic = false;
|
|
95
96
|
|
|
96
97
|
// Soap calls marked as internal are calls performed by the framework internally
|
|
97
98
|
// (such as GetEntityIfMoreRecent calls needed to lookup schemas)
|
|
@@ -341,7 +342,7 @@ class SoapMethodCall {
|
|
|
341
342
|
getEntity() {
|
|
342
343
|
if (!this.elemCurrent)
|
|
343
344
|
return null;
|
|
344
|
-
|
|
345
|
+
if (this.elemCurrent.getAttribute("xsi:type") != "ns:Element")
|
|
345
346
|
return null;
|
|
346
347
|
if (this.elemCurrent.tagName != "entity")
|
|
347
348
|
return null;
|
|
@@ -612,7 +613,7 @@ class SoapMethodCall {
|
|
|
612
613
|
this._method.prepend(sessionTokenElem);
|
|
613
614
|
}
|
|
614
615
|
const noMethodInURL = !!this._pushDownOptions.noMethodInURL;
|
|
615
|
-
const actualUrl = noMethodInURL ? url : `${url}
|
|
616
|
+
const actualUrl = noMethodInURL ? url : `${url}?soapAction=${encodeURIComponent(this.urn + "#" + this.methodName)}`;
|
|
616
617
|
|
|
617
618
|
// Prepare request and empty response objects
|
|
618
619
|
[this.request, this.requestOptions] = this._createHTTPRequest(actualUrl);
|
package/test/application.test.js
CHANGED
|
@@ -1704,6 +1704,34 @@ describe('Application', () => {
|
|
|
1704
1704
|
expect(node.isCalculated).toBe(true);
|
|
1705
1705
|
});
|
|
1706
1706
|
|
|
1707
|
+
it("Should get node edit type", async () => {
|
|
1708
|
+
const client = await Mock.makeClient();
|
|
1709
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
1710
|
+
await client.NLWS.xtkSession.logon();
|
|
1711
|
+
client._transport.mockReturnValueOnce(Promise.resolve(`<?xml version='1.0'?>
|
|
1712
|
+
<SOAP-ENV:Envelope xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns='urn:wpp:default' xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/'>
|
|
1713
|
+
<SOAP-ENV:Body>
|
|
1714
|
+
<GetEntityIfMoreRecentResponse xmlns='urn:wpp:default' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
1715
|
+
<pdomDoc xsi:type='ns:Element' SOAP-ENV:encodingStyle='http://xml.apache.org/xml-soap/literalxml'>
|
|
1716
|
+
<schema name="profile" namespace="nms" xtkschema="xtk:schema">
|
|
1717
|
+
<element name="profile">
|
|
1718
|
+
<compute-string expr="@lastName + ' ' + @firstName +' (' + @email + ')'"/>
|
|
1719
|
+
<attribute name="firstName"/>
|
|
1720
|
+
<attribute name="lastName"/>
|
|
1721
|
+
<attribute name="email" edit="memo"/>
|
|
1722
|
+
</element>
|
|
1723
|
+
</schema>
|
|
1724
|
+
</pdomDoc>
|
|
1725
|
+
</GetEntityIfMoreRecentResponse>
|
|
1726
|
+
</SOAP-ENV:Body>
|
|
1727
|
+
</SOAP-ENV:Envelope>`));
|
|
1728
|
+
const schema = await client.application.getSchema("nms:profile");
|
|
1729
|
+
|
|
1730
|
+
const node = schema.root.children.get("@email");
|
|
1731
|
+
const editType = node.editType;
|
|
1732
|
+
expect(editType).toBe("memo");
|
|
1733
|
+
});
|
|
1734
|
+
|
|
1707
1735
|
it("Should get compute string for ref nodes", async () => {
|
|
1708
1736
|
const client = await Mock.makeClient();
|
|
1709
1737
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
package/test/client.test.js
CHANGED
|
@@ -842,6 +842,18 @@ describe('ACC Client', function () {
|
|
|
842
842
|
await client.NLWS.xtkSession.logoff();
|
|
843
843
|
});
|
|
844
844
|
|
|
845
|
+
it("Should fail if method parameter inout attribute is not correct", async () => {
|
|
846
|
+
const client = await Mock.makeClient();
|
|
847
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
848
|
+
await client.NLWS.xtkSession.logon();
|
|
849
|
+
|
|
850
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
851
|
+
await expect(client.NLWS.xtkSession.badParam()).rejects.toMatchObject({ errorCode: "SDK-000006" });
|
|
852
|
+
|
|
853
|
+
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
854
|
+
await client.NLWS.xtkSession.logoff();
|
|
855
|
+
});
|
|
856
|
+
|
|
845
857
|
it("Should fail if calling non static function without object", async () => {
|
|
846
858
|
const client = await Mock.makeClient();
|
|
847
859
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
@@ -2304,7 +2316,7 @@ describe('ACC Client', function () {
|
|
|
2304
2316
|
expect(JSON.parse(call[1])).toMatchObject({
|
|
2305
2317
|
value: { value: "World", type: 6 }
|
|
2306
2318
|
})
|
|
2307
|
-
})
|
|
2319
|
+
})
|
|
2308
2320
|
|
|
2309
2321
|
it("Should ignore protocol for local storage root key", async () => {
|
|
2310
2322
|
const version = sdk.getSDKVersion().version; // "${version}" or similar
|
|
@@ -2347,7 +2359,7 @@ describe('ACC Client', function () {
|
|
|
2347
2359
|
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
2348
2360
|
await client.NLWS.xtkSession.logon();
|
|
2349
2361
|
client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
|
|
2350
|
-
|
|
2362
|
+
await client.getSchema("nms:extAccount");
|
|
2351
2363
|
// Schema should have been cached to local storage
|
|
2352
2364
|
expect(storage.setItem.mock.calls.length).toBe(1);
|
|
2353
2365
|
expect(storage.setItem.mock.calls[0][0]).toMatch("cache.XtkEntityCache$xtk:schema|nms:extAccount");
|
|
@@ -2363,6 +2375,73 @@ describe('ACC Client', function () {
|
|
|
2363
2375
|
await client.NLWS.xtkSession.logon();
|
|
2364
2376
|
client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
|
|
2365
2377
|
await client.getSchema("nms:extAccount");
|
|
2378
|
+
// Here we can't simply check the length of mock calls since there're for "lastCleared"
|
|
2379
|
+
// We check inside the new calls, since the creation of the second client, if there's
|
|
2380
|
+
// one for the schema "nms:extAccount"
|
|
2381
|
+
let callLength = storage.getItem.mock.calls.length;
|
|
2382
|
+
expect(storage.getItem.mock.calls[callLength-1][0]).toMatch("cache.XtkEntityCache$xtk:schema|nms:extAccount");
|
|
2383
|
+
})
|
|
2384
|
+
|
|
2385
|
+
it("Should clear storage if necessary", async () => {
|
|
2386
|
+
const sdkVersion = sdk.getSDKVersion().version;
|
|
2387
|
+
const mockSdkVersionItemKey = "acc.js.sdk.0.0.0.acc-sdk:8080.cache.Hello";
|
|
2388
|
+
const otherItemKey = "other.Hello";
|
|
2389
|
+
const map = {};
|
|
2390
|
+
const storage = {
|
|
2391
|
+
"acc.js.sdk.0.0.0.acc-sdk:8080.cache.Hello": "0.0.0.World",
|
|
2392
|
+
"other.Hello": "other.World",
|
|
2393
|
+
getItem: jest.fn((key) => map[key]),
|
|
2394
|
+
setItem: jest.fn((key, value) => map[key] = value),
|
|
2395
|
+
removeItem: jest.fn((key) => { delete map[key] })
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
let client = await Mock.makeClient({ storage: storage });
|
|
2399
|
+
|
|
2400
|
+
// Remove item not matches to the current sdk version and begins with "acc.js.sdk"
|
|
2401
|
+
expect(storage.removeItem.mock.calls.length).toBe(1);
|
|
2402
|
+
expect(storage.removeItem.mock.calls[0][0]).toMatch(mockSdkVersionItemKey);
|
|
2403
|
+
|
|
2404
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
2405
|
+
await client.NLWS.xtkSession.logon();
|
|
2406
|
+
client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
|
|
2407
|
+
await client.getSchema("nms:extAccount");
|
|
2408
|
+
const currentSdkVersionItemKey = "acc.js.sdk."+sdkVersion+".acc-sdk:8080.cache.XtkEntityCache$xtk:schema|nms:extAccount";
|
|
2409
|
+
expect(storage.setItem.mock.calls[0][0]).toMatch(currentSdkVersionItemKey);
|
|
2410
|
+
|
|
2411
|
+
// Remove ONLY the item not matches to the current sdk version but not the one matches
|
|
2412
|
+
// Now simulate reusing the local storage to make sure that we remove ONLY the item
|
|
2413
|
+
// not matches to the current sdk version.
|
|
2414
|
+
// We need a new client to make sure we do not reuse the in-memory cache of the client.
|
|
2415
|
+
// We use the same test method as the one we use in the previous test "Should cache XML in storage"
|
|
2416
|
+
client = await Mock.makeClient({ storage: storage });
|
|
2417
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
2418
|
+
await client.NLWS.xtkSession.logon();
|
|
2419
|
+
client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
|
|
2420
|
+
await client.getSchema("nms:extAccount");
|
|
2421
|
+
let callLength = storage.getItem.mock.calls.length;
|
|
2422
|
+
expect(storage.getItem.mock.calls[callLength-1][0]).toMatch("cache.XtkEntityCache$xtk:schema|nms:extAccount");
|
|
2423
|
+
})
|
|
2424
|
+
|
|
2425
|
+
it("Should support 'storage.removeItem' not defined", async () => {
|
|
2426
|
+
const mockSdkVersionItemKey = "acc.js.sdk.0.0.0.acc-sdk:8080.cache.Hello";
|
|
2427
|
+
const map = {};
|
|
2428
|
+
const storage = {
|
|
2429
|
+
"acc.js.sdk.0.0.0.acc-sdk:8080.cache.Hello": "0.0.0.World",
|
|
2430
|
+
getItem: jest.fn((key) => map[key]),
|
|
2431
|
+
setItem: jest.fn((key, value) => map[key] = value)
|
|
2432
|
+
}
|
|
2433
|
+
let client = await Mock.makeClient({ storage: storage });
|
|
2434
|
+
// storage.removeItem not defined. Cache should not be removed.
|
|
2435
|
+
expect(storage[mockSdkVersionItemKey]).toStrictEqual("0.0.0.World");
|
|
2436
|
+
})
|
|
2437
|
+
|
|
2438
|
+
it("Should support 'storage' not defined", async () => {
|
|
2439
|
+
const storage = undefined
|
|
2440
|
+
let client = await Mock.makeClient({ storage: storage });
|
|
2441
|
+
// Create a client with "storage" undefined
|
|
2442
|
+
const NLWS = client.NLWS;
|
|
2443
|
+
expect(NLWS).toBeTruthy();
|
|
2444
|
+
expect(client.isLogged()).toBe(false);
|
|
2366
2445
|
})
|
|
2367
2446
|
})
|
|
2368
2447
|
|
|
@@ -2987,7 +3066,7 @@ describe('ACC Client', function () {
|
|
|
2987
3066
|
const query = client.NLWS.pushDown({'foo': 'bar'}).xtkQueryDef.create(queryDef);
|
|
2988
3067
|
await query.executeQuery();
|
|
2989
3068
|
const lastCall = client._transport.mock.calls[client._transport.mock.calls.length-1];
|
|
2990
|
-
expect(lastCall[0].url).toBe("http://acc-sdk:8080/nl/jsp/soaprouter.jsp?xtk
|
|
3069
|
+
expect(lastCall[0].url).toBe("http://acc-sdk:8080/nl/jsp/soaprouter.jsp?soapAction=xtk%3AqueryDef%23ExecuteQuery");
|
|
2991
3070
|
expect(lastCall[1].charset).toBe("UTF-8");
|
|
2992
3071
|
expect(lastCall[1].foo).toBe("bar");
|
|
2993
3072
|
});
|
|
@@ -3012,7 +3091,7 @@ describe('ACC Client', function () {
|
|
|
3012
3091
|
const query = client.NLWS.pushDown({'foo': 'bar'}).xtkQueryDef.create(queryDef);
|
|
3013
3092
|
await query.executeQuery();
|
|
3014
3093
|
const lastCall = client._transport.mock.calls[client._transport.mock.calls.length-1];
|
|
3015
|
-
expect(lastCall[0].url).toBe("http://acc-sdk:8080/nl/jsp/soaprouter.jsp?xtk
|
|
3094
|
+
expect(lastCall[0].url).toBe("http://acc-sdk:8080/nl/jsp/soaprouter.jsp?soapAction=xtk%3AqueryDef%23ExecuteQuery");
|
|
3016
3095
|
expect(lastCall[1].charset).toBe("UTF-8");
|
|
3017
3096
|
expect(lastCall[1].foo).toBe("bar");
|
|
3018
3097
|
expect(lastCall[1].cnxDefault).toBe(3);
|
|
@@ -3039,7 +3118,7 @@ describe('ACC Client', function () {
|
|
|
3039
3118
|
const query = client.NLWS.pushDown({'foo': 'bar'}).pushDown().pushDown({'foo': 'fu', x: 2 }).xtkQueryDef.create(queryDef);
|
|
3040
3119
|
await query.executeQuery();
|
|
3041
3120
|
const lastCall = client._transport.mock.calls[client._transport.mock.calls.length-1];
|
|
3042
|
-
expect(lastCall[0].url).toBe("http://acc-sdk:8080/nl/jsp/soaprouter.jsp?xtk
|
|
3121
|
+
expect(lastCall[0].url).toBe("http://acc-sdk:8080/nl/jsp/soaprouter.jsp?soapAction=xtk%3AqueryDef%23ExecuteQuery");
|
|
3043
3122
|
expect(lastCall[1].charset).toBe("UTF-8");
|
|
3044
3123
|
expect(lastCall[1].foo).toBe("fu");
|
|
3045
3124
|
expect(lastCall[1].cnxDefault).toBe(3);
|
package/test/mock.js
CHANGED
|
@@ -280,6 +280,11 @@ const GET_XTK_SESSION_SCHEMA_RESPONSE = Promise.resolve(`<?xml version='1.0'?>
|
|
|
280
280
|
<param name="result" type="long" inout="out"/>
|
|
281
281
|
</parameters>
|
|
282
282
|
</method>
|
|
283
|
+
<method name="badParam" static="true">
|
|
284
|
+
<parameters>
|
|
285
|
+
<param name="bad" type="long" inout="zz"/>
|
|
286
|
+
</parameters>
|
|
287
|
+
</method>
|
|
283
288
|
</methods>
|
|
284
289
|
</schema>
|
|
285
290
|
</pdomDoc>
|
|
@@ -263,5 +263,154 @@ describe('ACC Client Observability', function () {
|
|
|
263
263
|
jest.useRealTimers();
|
|
264
264
|
});
|
|
265
265
|
|
|
266
|
+
describe("SOAP method intercept", () => {
|
|
267
|
+
it("Should intercept SOAP call", async () => {
|
|
268
|
+
const [client, assertion] = await makeObservableClient();
|
|
269
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
270
|
+
await client.NLWS.xtkSession.logon();
|
|
271
|
+
|
|
272
|
+
const observer = { beforeSoapCall: jest.fn(), afterSoapCall: jest.fn() };
|
|
273
|
+
client.registerObserver(observer);
|
|
274
|
+
|
|
275
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
276
|
+
client._transport.mockReturnValueOnce(Mock.GET_DATABASEID_RESPONSE);
|
|
277
|
+
await client.getOption("XtkDatabaseId");
|
|
278
|
+
|
|
279
|
+
// Only one call is intercepted: xtk:session#GetOption. The internal call to get the xtk:session schema is internal
|
|
280
|
+
// and hence not interceptable
|
|
281
|
+
expect(observer.beforeSoapCall).toHaveBeenCalledTimes(1);
|
|
282
|
+
expect(observer.beforeSoapCall.mock.calls[0]).toEqual([ { urn:"xtk:session", name: "GetOption" }, [ { name:"name", type:"string", value:"XtkDatabaseId" } ], "SimpleJson" ]);
|
|
283
|
+
expect(observer.afterSoapCall).toHaveBeenCalledTimes(1);
|
|
284
|
+
expect(observer.afterSoapCall.mock.calls[0]).toEqual([ { urn:"xtk:session", name: "GetOption" }, [ { name:"name", type:"string", value:"XtkDatabaseId" } ], "SimpleJson", [ { name:"value", type:"string", value:"uFE80000000000000F1FA913DD7CC7C480041161C" }, { name:"type", type:"byte", value:6 }] ]);
|
|
285
|
+
|
|
286
|
+
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
287
|
+
await client.NLWS.xtkSession.logoff();
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("Should support intercept callback to get schemas", async () => {
|
|
291
|
+
const [client, assertion] = await makeObservableClient();
|
|
292
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
293
|
+
await client.NLWS.xtkSession.logon();
|
|
294
|
+
|
|
295
|
+
const observer = { beforeSoapCall: jest.fn(), afterSoapCall: jest.fn() };
|
|
296
|
+
client.registerObserver(observer);
|
|
297
|
+
|
|
298
|
+
var extAccountSchema;
|
|
299
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
300
|
+
client._transport.mockReturnValueOnce(Mock.GET_NMS_EXTACCOUNT_SCHEMA_RESPONSE);
|
|
301
|
+
client._transport.mockReturnValueOnce(Mock.GET_DATABASEID_RESPONSE);
|
|
302
|
+
observer.beforeSoapCall.mockImplementationOnce(async (method, inputParameters, representation) => {
|
|
303
|
+
extAccountSchema = await client.getSchema("nms:extAccount");
|
|
304
|
+
});
|
|
305
|
+
var databaseId = await client.getOption("XtkDatabaseId");
|
|
306
|
+
expect(databaseId).toBe("uFE80000000000000F1FA913DD7CC7C480041161C");
|
|
307
|
+
expect(extAccountSchema.name).toBe("extAccount");
|
|
308
|
+
|
|
309
|
+
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
310
|
+
await client.NLWS.xtkSession.logoff();
|
|
311
|
+
});
|
|
312
|
+
|
|
313
|
+
it("Should allow to rewrite method call parameters", async () => {
|
|
314
|
+
const [client, assertion] = await makeObservableClient();
|
|
315
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
316
|
+
await client.NLWS.xtkSession.logon();
|
|
317
|
+
|
|
318
|
+
const observer = { beforeSoapCall: jest.fn(), afterSoapCall: jest.fn() };
|
|
319
|
+
client.registerObserver(observer);
|
|
320
|
+
|
|
321
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
322
|
+
const getOption = (options) => {
|
|
323
|
+
// SOAP request contains the option name as <name xsi:type="xsd:string">Dummy</name>
|
|
324
|
+
const index = options.data.indexOf('<name xsi:type="xsd:string">');
|
|
325
|
+
const index2 = options.data.indexOf('</name>', index);
|
|
326
|
+
const name = options.data.substring(index + 28, index2);
|
|
327
|
+
// Option value is the option name followed by a "ZZ"
|
|
328
|
+
return Promise.resolve(`<?xml version='1.0'?>
|
|
329
|
+
<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/'>
|
|
330
|
+
<SOAP-ENV:Body>
|
|
331
|
+
<GetOptionResponse xmlns='urn:xtk:session' SOAP-ENV:encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'>
|
|
332
|
+
<pstrValue xsi:type='xsd:string'>${name}ZZ</pstrValue>
|
|
333
|
+
<pbtType xsi:type='xsd:byte'>6</pbtType>
|
|
334
|
+
</GetOptionResponse>
|
|
335
|
+
</SOAP-ENV:Body>
|
|
336
|
+
</SOAP-ENV:Envelope>`);
|
|
337
|
+
};
|
|
338
|
+
client._transport.mockImplementationOnce(getOption);
|
|
339
|
+
client.clearOptionCache();
|
|
340
|
+
var value = await client.getOption("Dummy");
|
|
341
|
+
expect(value).toBe("DummyZZ");
|
|
342
|
+
|
|
343
|
+
jest.clearAllMocks();
|
|
344
|
+
observer.beforeSoapCall.mockImplementationOnce(async (method, inputParameters, representation) => {
|
|
345
|
+
if (inputParameters[0].value === "Dummy") inputParameters[0].value = "XtkDatabaseId";
|
|
346
|
+
});
|
|
347
|
+
client._transport.mockImplementationOnce(getOption);
|
|
348
|
+
client.clearOptionCache();
|
|
349
|
+
var value = await client.getOption("Dummy");
|
|
350
|
+
expect(value).toBe("XtkDatabaseIdZZ");
|
|
351
|
+
|
|
352
|
+
// Only one call is intercepted: xtk:session#GetOption. The internal call to get the xtk:session schema is internal
|
|
353
|
+
// and hence not interceptable
|
|
354
|
+
expect(observer.beforeSoapCall).toHaveBeenCalledTimes(1);
|
|
355
|
+
expect(observer.beforeSoapCall.mock.calls[0]).toEqual([ { urn:"xtk:session", name: "GetOption" }, [ { name:"name", type:"string", value:"XtkDatabaseId" } ], "SimpleJson" ]);
|
|
356
|
+
expect(observer.afterSoapCall).toHaveBeenCalledTimes(1);
|
|
357
|
+
expect(observer.afterSoapCall.mock.calls[0]).toEqual([ { urn:"xtk:session", name: "GetOption" }, [ { name:"name", type:"string", value:"XtkDatabaseId" } ], "SimpleJson", [ { name:"value", type:"string", value:"XtkDatabaseIdZZ" }, { name:"type", type:"byte", value:6 }] ]);
|
|
358
|
+
|
|
359
|
+
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
360
|
+
await client.NLWS.xtkSession.logoff();
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
it("Should allow to rewrite method return parameters", async () => {
|
|
364
|
+
const [client, assertion] = await makeObservableClient();
|
|
365
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
366
|
+
await client.NLWS.xtkSession.logon();
|
|
367
|
+
|
|
368
|
+
const observer = { beforeSoapCall: jest.fn(), afterSoapCall: jest.fn() };
|
|
369
|
+
client.registerObserver(observer);
|
|
370
|
+
|
|
371
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
372
|
+
client._transport.mockReturnValueOnce(Mock.GET_DATABASEID_RESPONSE);
|
|
373
|
+
|
|
374
|
+
observer.afterSoapCall.mockImplementationOnce(async (method, inputParameters, representation, outputParameters) => {
|
|
375
|
+
outputParameters[0].value = "Patched";
|
|
376
|
+
});
|
|
377
|
+
var value = await client.getOption("XtkDatabaseId");
|
|
378
|
+
expect(value).toBe("Patched");
|
|
379
|
+
|
|
380
|
+
// Only one call is intercepted: xtk:session#GetOption. The internal call to get the xtk:session schema is internal
|
|
381
|
+
// and hence not interceptable
|
|
382
|
+
expect(observer.beforeSoapCall).toHaveBeenCalledTimes(1);
|
|
383
|
+
expect(observer.beforeSoapCall.mock.calls[0]).toEqual([ { urn:"xtk:session", name: "GetOption" }, [ { name:"name", type:"string", value:"XtkDatabaseId" } ], "SimpleJson" ]);
|
|
384
|
+
expect(observer.afterSoapCall).toHaveBeenCalledTimes(1);
|
|
385
|
+
|
|
386
|
+
expect(observer.afterSoapCall.mock.calls[0]).toEqual([ { urn:"xtk:session", name: "GetOption" }, [ { name:"name", type:"string", value:"XtkDatabaseId" } ], "SimpleJson", [ { name:"value", type:"string", value:"Patched" }, { name:"type", type:"byte", value:6 }] ]);
|
|
387
|
+
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
388
|
+
await client.NLWS.xtkSession.logoff();
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it("Should not intercept internal calls", async () => {
|
|
392
|
+
const [client, assertion] = await makeObservableClient();
|
|
393
|
+
client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
|
|
394
|
+
await client.NLWS.xtkSession.logon();
|
|
395
|
+
|
|
396
|
+
const observer = { beforeSoapCall: jest.fn(), afterSoapCall: jest.fn() };
|
|
397
|
+
client.registerObserver(observer);
|
|
398
|
+
|
|
399
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
400
|
+
var schema = await client.getEntityIfMoreRecent("xtk:schema", "xtk:session", undefined, true);
|
|
401
|
+
expect(schema.name).toBe("session");
|
|
402
|
+
expect(observer.beforeSoapCall).not.toHaveBeenCalled();
|
|
403
|
+
expect(observer.afterSoapCall).not.toHaveBeenCalled();
|
|
404
|
+
|
|
405
|
+
client._transport.mockReturnValueOnce(Mock.GET_XTK_SESSION_SCHEMA_RESPONSE);
|
|
406
|
+
schema = await client.getEntityIfMoreRecent("xtk:schema", "xtk:session", undefined, false);
|
|
407
|
+
expect(schema.name).toBe("session");
|
|
408
|
+
expect(observer.beforeSoapCall).toHaveBeenCalledTimes(1);
|
|
409
|
+
expect(observer.afterSoapCall).toHaveBeenCalledTimes(1);
|
|
410
|
+
|
|
411
|
+
client._transport.mockReturnValueOnce(Mock.LOGOFF_RESPONSE);
|
|
412
|
+
await client.NLWS.xtkSession.logoff();
|
|
413
|
+
});
|
|
414
|
+
});
|
|
266
415
|
});
|
|
267
416
|
|
package/test/soap.test.js
CHANGED
|
@@ -734,7 +734,7 @@ describe('SOAP', function() {
|
|
|
734
734
|
const client = await sdk.init(connectionParameters);
|
|
735
735
|
client._transport = jest.fn();
|
|
736
736
|
expect(client._connectionParameters._options.charset).toBe('UTF-8');
|
|
737
|
-
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
|
|
737
|
+
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true, true);
|
|
738
738
|
expect (soapCall._charset).toBe('UTF-8');
|
|
739
739
|
const [ request ] = soapCall._createHTTPRequest(URL);
|
|
740
740
|
assert.equal(request.headers["Content-type"], "application/soap+xml;charset=UTF-8");
|
|
@@ -745,7 +745,7 @@ describe('SOAP', function() {
|
|
|
745
745
|
const client = await sdk.init(connectionParameters);
|
|
746
746
|
client._transport = jest.fn();
|
|
747
747
|
expect(client._connectionParameters._options.charset).toBe('');
|
|
748
|
-
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
|
|
748
|
+
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true, true);
|
|
749
749
|
expect (soapCall._charset).toBe('');
|
|
750
750
|
const [ request ] = soapCall._createHTTPRequest(URL);
|
|
751
751
|
assert.equal(request.headers["Content-type"], "application/soap+xml");
|
|
@@ -756,7 +756,7 @@ describe('SOAP', function() {
|
|
|
756
756
|
const client = await sdk.init(connectionParameters);
|
|
757
757
|
client._transport = jest.fn();
|
|
758
758
|
expect(client._connectionParameters._options.charset).toBe('ISO-8859-1');
|
|
759
|
-
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
|
|
759
|
+
const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true, true);
|
|
760
760
|
expect (soapCall._charset).toBe('ISO-8859-1');
|
|
761
761
|
const [ request ] = soapCall._createHTTPRequest(URL);
|
|
762
762
|
assert.equal(request.headers["Content-type"], "application/soap+xml;charset=ISO-8859-1");
|
|
@@ -901,7 +901,7 @@ describe("Campaign exception", () => {
|
|
|
901
901
|
it("Should add the method name by default in the URL", () => {
|
|
902
902
|
const call = makeSoapMethodCall(undefined, "xtk:session", "Empty", "$session$", "$security$");
|
|
903
903
|
call.finalize(URL);
|
|
904
|
-
expect(call.request.url).toBe("https://soap-test/nl/jsp/soaprouter.jsp?xtk
|
|
904
|
+
expect(call.request.url).toBe("https://soap-test/nl/jsp/soaprouter.jsp?soapAction=xtk%3Asession%23Empty");
|
|
905
905
|
});
|
|
906
906
|
|
|
907
907
|
it("Should be able to disable adding the method name by default in the URL", () => {
|