@adobe/acc-js-sdk 1.0.9 → 1.1.2

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.
@@ -2283,15 +2283,15 @@ describe('ACC Client', function () {
2283
2283
  it("Should ignore protocol for local storage root key", async () => {
2284
2284
  var connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("http://acc-sdk:8080", "admin", "admin", {});
2285
2285
  var client = await sdk.init(connectionParameters);
2286
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.9.acc-sdk:8080.cache.OptionCache$");
2286
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.2.acc-sdk:8080.cache.OptionCache$");
2287
2287
 
2288
2288
  connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("https://acc-sdk:8080", "admin", "admin", {});
2289
2289
  client = await sdk.init(connectionParameters);
2290
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.9.acc-sdk:8080.cache.OptionCache$");
2290
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.2.acc-sdk:8080.cache.OptionCache$");
2291
2291
 
2292
2292
  connectionParameters = sdk.ConnectionParameters.ofUserAndPassword("acc-sdk:8080", "admin", "admin", {});
2293
2293
  client = await sdk.init(connectionParameters);
2294
- expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.0.9.acc-sdk:8080.cache.OptionCache$");
2294
+ expect(client._optionCache._storage._rootKey).toBe("acc.js.sdk.1.1.2.acc-sdk:8080.cache.OptionCache$");
2295
2295
  })
2296
2296
 
2297
2297
  it("Should support no storage", async () => {
@@ -2422,4 +2422,56 @@ describe('ACC Client', function () {
2422
2422
  expect(paramsFn.mock.calls[0][1]).toMatchObject({ schemaId: "xtk:session", namespace: "xtkSession" });
2423
2423
  });
2424
2424
  });
2425
+
2426
+ describe("Method-level representation", () => {
2427
+ it("Should force an xml representation", async () => {
2428
+ const client = await Mock.makeClient();
2429
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
2430
+ await client.NLWS.xtkSession.logon();
2431
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
2432
+ client._transport.mockReturnValueOnce(Mock.GET_QUERY_EXECUTE_RESPONSE);
2433
+ const queryDef = DomUtil.parse(`
2434
+ <queryDef schema="nms:extAccount" operation="select">
2435
+ <select>
2436
+ <node expr="@id"/>
2437
+ <node expr="@name"/>
2438
+ </select>
2439
+ </queryDef>
2440
+ `);
2441
+ const query = client.NLWS.xml.xtkQueryDef.create(queryDef);
2442
+ const result = await query.executeQuery();
2443
+ const xml = DomUtil.toXMLString(result);
2444
+ expect(xml).toBe(`<extAccount-collection xmlns="urn:xtk:queryDef">
2445
+ <extAccount id="1816" name="defaultPopAccount"/>
2446
+ <extAccount id="1818" name="defaultOther"/>
2447
+ <extAccount id="1849" name="billingReport"/>
2448
+ <extAccount id="12070" name="TST_EXT_ACCOUNT_POSTGRESQL"/>
2449
+ <extAccount id="1817" name="defaultEmailBulk"/>
2450
+ <extAccount id="2087" name="ffda"/>
2451
+ <extAccount id="2088" name="defaultEmailMid"/>
2452
+ </extAccount-collection>`);
2453
+ });
2454
+
2455
+ it("Should force an json representation", async () => {
2456
+ const client = await Mock.makeClient();
2457
+ client._transport.mockReturnValueOnce(Mock.LOGON_RESPONSE);
2458
+ await client.NLWS.xtkSession.logon();
2459
+ client._transport.mockReturnValueOnce(Mock.GET_XTK_QUERY_SCHEMA_RESPONSE);
2460
+ client._transport.mockReturnValueOnce(Mock.GET_QUERY_EXECUTE_RESPONSE);
2461
+ const queryDef = {
2462
+ "schema": "nms:extAccount",
2463
+ "operation": "select",
2464
+ "select": {
2465
+ "node": [
2466
+ { "expr": "@id" },
2467
+ { "expr": "@name" }
2468
+ ]
2469
+ }
2470
+ };
2471
+ const query = client.NLWS.json.xtkQueryDef.create(queryDef);
2472
+ const result = await query.executeQuery();
2473
+ const json = JSON.stringify(result);
2474
+ expect(json).toBe('{"#text":[],"extAccount":[{"id":"1816","name":"defaultPopAccount"},{"id":"1818","name":"defaultOther"},{"id":"1849","name":"billingReport"},{"id":"12070","name":"TST_EXT_ACCOUNT_POSTGRESQL"},{"id":"1817","name":"defaultEmailBulk"},{"id":"2087","name":"ffda"},{"id":"2088","name":"defaultEmailMid"}]}');
2475
+ });
2476
+ });
2425
2477
  });
package/test/soap.test.js CHANGED
@@ -21,11 +21,12 @@ const { SoapMethodCall } = require('../src/soap.js');
21
21
  const { CampaignException, makeCampaignException } = require('../src/campaign.js');
22
22
  const { DomUtil } = require('../src/domUtil.js');
23
23
  const assert = require('assert');
24
+ const sdk = require('../src/index.js');
24
25
 
25
26
  const URL = "https://soap-test/nl/jsp/soaprouter.jsp";
26
27
 
27
- function makeSoapMethodCall(transport, urn, methodName, sessionToken, securityToken, userAgentString) {
28
- const call = new SoapMethodCall(transport, urn, methodName, sessionToken, securityToken, userAgentString);
28
+ function makeSoapMethodCall(transport, urn, methodName, sessionToken, securityToken, userAgentString, optionalCharset) {
29
+ const call = new SoapMethodCall(transport, urn, methodName, sessionToken, securityToken, userAgentString, optionalCharset);
29
30
  return call;
30
31
  }
31
32
 
@@ -682,6 +683,56 @@ describe('SOAP', function() {
682
683
  });
683
684
  })
684
685
  });
686
+
687
+ describe("Charset encoding", function() {
688
+
689
+ it("Should support no encoding", function() {
690
+ const call = makeSoapMethodCall(undefined, "xtk:session", "Empty");
691
+ const request = call._createHTTPRequest(URL);
692
+ assert.equal(request.url, URL);
693
+ assert.equal(request.headers["Content-type"], "application/soap+xml");
694
+ });
695
+
696
+ it("Should support UTF-8 encoding", function() {
697
+ const call = makeSoapMethodCall(undefined, "xtk:session", "Empty", undefined, undefined, undefined, "UTF-8");
698
+ const request = call._createHTTPRequest(URL);
699
+ assert.equal(request.url, URL);
700
+ assert.equal(request.headers["Content-type"], "application/soap+xml;charset=UTF-8");
701
+ });
702
+
703
+ it("Default encoding should be UTF-8", async () => {
704
+ const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "mc/");
705
+ const client = await sdk.init(connectionParameters);
706
+ client._transport = jest.fn();
707
+ expect(client._connectionParameters._options.charset).toBe('UTF-8');
708
+ const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
709
+ expect (soapCall._charset).toBe('UTF-8');
710
+ const request = soapCall._createHTTPRequest(URL);
711
+ assert.equal(request.headers["Content-type"], "application/soap+xml;charset=UTF-8");
712
+ })
713
+
714
+ it("Default support forcing an empty encoding", async () => {
715
+ const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "mc/", { charset: "" });
716
+ const client = await sdk.init(connectionParameters);
717
+ client._transport = jest.fn();
718
+ expect(client._connectionParameters._options.charset).toBe('');
719
+ const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
720
+ expect (soapCall._charset).toBe('');
721
+ const request = soapCall._createHTTPRequest(URL);
722
+ assert.equal(request.headers["Content-type"], "application/soap+xml");
723
+ })
724
+
725
+ it("Default support forcing an ISO charset", async () => {
726
+ const connectionParameters = sdk.ConnectionParameters.ofSessionToken("http://acc-sdk:8080", "mc/", { charset: "ISO-8859-1" });
727
+ const client = await sdk.init(connectionParameters);
728
+ client._transport = jest.fn();
729
+ expect(client._connectionParameters._options.charset).toBe('ISO-8859-1');
730
+ const soapCall = client._prepareSoapCall("xtk:persist", "GetEntityIfMoreRecent", true);
731
+ expect (soapCall._charset).toBe('ISO-8859-1');
732
+ const request = soapCall._createHTTPRequest(URL);
733
+ assert.equal(request.headers["Content-type"], "application/soap+xml;charset=ISO-8859-1");
734
+ })
735
+ });
685
736
 
686
737
  });
687
738
 
package/test/util.test.js CHANGED
@@ -17,7 +17,7 @@ governing permissions and limitations under the License.
17
17
  *
18
18
  *********************************************************************************/
19
19
 
20
- const { Util } = require('../src/util.js');
20
+ const { Util, ArrayMap } = require('../src/util.js');
21
21
  const { SafeStorage, Cache } = require('../src/cache.js');
22
22
 
23
23
 
@@ -232,4 +232,170 @@ describe('Util', function() {
232
232
  expect(cache._cache["Hello"].value).toBe("World");
233
233
  })
234
234
 
235
+ describe("ArrayMap", () => {
236
+
237
+ it("Should support access by keys", () => {
238
+ const am = new ArrayMap();
239
+ am._push("hello", "Hello");
240
+ am._push("world", "World");
241
+ expect(am["hello"]).toBe("Hello");
242
+ expect(am["world"]).toBe("World");
243
+ expect(am.get("hello")).toBe("Hello");
244
+ expect(am.get("world")).toBe("World");
245
+ });
246
+
247
+ it("Should support access by index", () => {
248
+ const am = new ArrayMap();
249
+ am._push("hello", "Hello");
250
+ am._push("world", "World");
251
+ expect(am[0]).toBe("Hello");
252
+ expect(am[1]).toBe("World");
253
+ expect(am.get(0)).toBe("Hello");
254
+ expect(am.get(1)).toBe("World");
255
+ });
256
+
257
+ it("Should support length attribute", () => {
258
+ const am = new ArrayMap();
259
+ am._push("hello", "Hello");
260
+ am._push("world", "World");
261
+ expect(am.length).toBe(2);
262
+ });
263
+
264
+ it("Should support iterators (for...of)", () => {
265
+ const am = new ArrayMap();
266
+ am._push("hello", "Hello");
267
+ am._push("world", "World");
268
+ let cat = "";
269
+ for (const s of am) cat = cat + s;
270
+ expect(cat).toBe("HelloWorld");
271
+ });
272
+
273
+ it("Should support map()", () => {
274
+ const am = new ArrayMap();
275
+ am._push("hello", "Hello");
276
+ am._push("world", "World");
277
+ const cat = am.map(s => s).join(',');
278
+ expect(cat).toBe("Hello,World");
279
+ });
280
+
281
+ it("Should support flatMap()", () => {
282
+ const am = new ArrayMap();
283
+ am._push("hello", "Hello");
284
+ am._push("world", ["Adobe", "World"]);
285
+ const cat = am.flatMap(s => s).join(',');
286
+ expect(cat).toBe("Hello,Adobe,World");
287
+ });
288
+
289
+ it("Should support find()", () => {
290
+ const am = new ArrayMap();
291
+ am._push("hello", "Hello");
292
+ am._push("world", "World");
293
+ const world = am.find(s => s === 'World');
294
+ expect(world).toBe("World");
295
+ const notFound = am.find(s => s === 'NotFound');
296
+ expect(notFound).toBe(undefined);
297
+ });
298
+
299
+ it("Should support filter()", () => {
300
+ const am = new ArrayMap();
301
+ am._push("hello", "Hello");
302
+ am._push("world", "World");
303
+ const all = am.filter(s => true);
304
+ expect(all).toMatchObject([ "Hello", "World" ]);
305
+ const none = am.filter(s => false);
306
+ expect(none).toMatchObject([ ]);
307
+ const world = am.filter(s => s === 'World');
308
+ expect(world).toMatchObject([ "World" ]);
309
+ });
310
+
311
+ it("Should support forEach", () => {
312
+ const am = new ArrayMap();
313
+ am._push("hello", "Hello");
314
+ am._push("world", "World");
315
+ let cat = "";
316
+ am.forEach(s => cat = cat + s);
317
+ expect(cat).toBe("HelloWorld");
318
+ });
319
+
320
+ it("Should support forEach as a key", () => {
321
+ const am = new ArrayMap();
322
+ am._push("forEach", "Hello");
323
+ const cat = am.map(s => s).join(',');
324
+ expect(cat).toBe("Hello");
325
+ expect(typeof am.forEach).toBe('function');
326
+ expect(am["forEach"]).not.toBe("Hello"); // forEach is a function
327
+ expect(am.get("forEach")).toBe("Hello");
328
+ });
329
+
330
+ it("Should support for...in", () => {
331
+ const am = new ArrayMap();
332
+ am._push("hello", "Hello");
333
+ am._push("world", "World");
334
+ let cat = "";
335
+ for (const s in am) cat = cat + s;
336
+ expect(cat).toBe("helloworld");
337
+ });
338
+
339
+ it("Should not support for...in when there's a property named 'forEach'", () => {
340
+ const am = new ArrayMap();
341
+ am._push("hello", "Hello");
342
+ am._push("forEach", "World");
343
+ let cat = "";
344
+ for (const s in am) cat = cat + s;
345
+ expect(cat).toBe("hello");
346
+ });
347
+
348
+ it("Should support enumerations whose key is a number", () => {
349
+ // For instance the "addressQuality" enumeration
350
+ const am = new ArrayMap();
351
+ am._push("0", { name:"0", value:0 });
352
+ am._push("1", { name:"1", value:1 });
353
+ am._push("2", { name:"2", value:2 });
354
+ let cat = "";
355
+ for (const k in am) cat = cat + am.get(k).name;
356
+ expect(cat).toBe("012");
357
+ });
358
+
359
+ it("Should not support adding the same key twice", () => {
360
+ const am = new ArrayMap();
361
+ am._push("hello", "Hello");
362
+ expect(() => { am._push("hello", "World"); }).toThrow("Failed to add element 'hello' to ArrayMap. There's already an item with the same name");
363
+ });
364
+
365
+ it("Should support missing names", () => {
366
+ const am = new ArrayMap();
367
+ am._push("", { name:"0", value:0 });
368
+ am._push(undefined, { name:"1", value:1 });
369
+ am._push(null, { name:"2", value:2 });
370
+ expect(am.length).toBe(3);
371
+ expect(am[0].name).toBe("0");
372
+ expect(am[1].name).toBe("1");
373
+ expect(am[2].name).toBe("2");
374
+ });
375
+
376
+ it("Should handle compatibility", () => {
377
+ const am = new ArrayMap();
378
+ am._push("perfect", { name:"perfect", value:0 });
379
+ am._push("notPerfect", { name:"notPerfect", value:1 });
380
+ am._push("error", { name:"error", value:2 });
381
+ // length
382
+ expect(am.length).toBe(3);
383
+ // Access by name
384
+ expect(am.perfect).toMatchObject({ name:"perfect", value:0 });
385
+ expect(am.notPerfect).toMatchObject({ name:"notPerfect", value:1 });
386
+ expect(am.error).toMatchObject({ name:"error", value:2 });
387
+ expect(am.notFound).toBeUndefined();
388
+ // for .. in loop
389
+ const list = [];
390
+ for (const p in am) list.push(p);
391
+ expect(list).toMatchObject([ "perfect", "notPerfect", "error" ]);
392
+ });
393
+ });
394
+
395
+ describe("Is Browser", () => {
396
+ it("Should not be a browser", () => {
397
+ expect(Util.isBrowser()).toBe(false);
398
+ });
399
+ });
235
400
  });
401
+