@adobe/acc-js-sdk 1.1.15 → 1.1.17

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.
@@ -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:session:Empty");
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", () => {
package/test/util.test.js CHANGED
@@ -37,6 +37,15 @@ describe('Util', function() {
37
37
  expect(Util.isArray([ 1 ])).toBe(true);
38
38
  });
39
39
 
40
+ describe("util.schemaIdFromNamespace", () => {
41
+ it("Should should extract schema id for simple namespaces", () => {
42
+ expect(Util.schemaIdFromNamespace("")).toBe("");
43
+ expect(Util.schemaIdFromNamespace("nmsRecipient")).toBe("nms:recipient");
44
+ expect(Util.schemaIdFromNamespace("000Recipient")).toBe("000:recipient");
45
+ expect(Util.schemaIdFromNamespace("Recipient")).toBe(":recipient");
46
+ });
47
+ });
48
+
40
49
  describe("Util.trim", () => {
41
50
  it("Should remove trailing spaces", () => {
42
51
  expect(Util.trim("Hello \n \r \t ")).toBe("Hello");