@adobe/acc-js-sdk 1.0.9 → 1.1.0

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.0.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.0.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.0.acc-sdk:8080.cache.OptionCache$");
2295
2295
  })
2296
2296
 
2297
2297
  it("Should support no storage", async () => {
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
+