@adobe/acc-js-sdk 1.1.18 → 1.1.20

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/test/soap.test.js CHANGED
@@ -163,6 +163,7 @@ describe('SOAP', function() {
163
163
  const call = makeSoapMethodCall(undefined, "xtk:session", "Empty", "$session$", "$security$");
164
164
  const [ request ] = call._createHTTPRequest(URL);
165
165
  assert.equal(request.headers["X-Security-Token"], "$security$", "Security token matches");
166
+ assert.equal(request.headers["X-Session-Token"], "$session$", "Session token matches");
166
167
  assert.equal(request.headers["Cookie"], "__sessiontoken=$session$", "Session token matches");
167
168
  const env = DomUtil.parse(request.data).documentElement;
168
169
  const header = hasChildElement(env, "SOAP-ENV:Header");
package/test/util.test.js CHANGED
@@ -86,6 +86,10 @@ describe('Util', function() {
86
86
  expect(Util.trim({hello:"Lead<X-Security-Token>Stuff</X-Security-Token>Trail"})).toStrictEqual({hello:"Lead<X-Security-Token>***</X-Security-Token>Trail"});
87
87
  })
88
88
 
89
+ it("Should remove session token headers", () => {
90
+ expect(Util.trim({hello:"Lead<X-Session-Token>Stuff</X-Session-Token>Trail"})).toStrictEqual({hello:"Lead<X-Session-Token>***</X-Session-Token>Trail"});
91
+ })
92
+
89
93
  it("Should remove session tokens", () => {
90
94
  expect(Util.trim({hello:'Lead<sessiontoken xsi:type="xsd:string">Stuff</sessiontoken>Trail'})).toStrictEqual({hello:'Lead<sessiontoken xsi:type="xsd:string">***</sessiontoken>Trail'});
91
95
  })
@@ -112,18 +116,18 @@ describe('Util', function() {
112
116
  })
113
117
 
114
118
  describe("Safe storage", () => {
115
- it("Should support undefined delegate", () => {
119
+ it("Should support undefined delegate", async () => {
116
120
  const storage = new SafeStorage();
117
- expect(storage.getItem("Hello")).toBeUndefined();
121
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
118
122
  storage.setItem("Hello", { text: "World" });
119
- expect(storage.getItem("Hello")).toBeUndefined();
123
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
120
124
  storage.setItem("Hello", "World"); // value should be JSON but errors are ignored
121
- expect(storage.getItem("Hello")).toBeUndefined();
125
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
122
126
  storage.removeItem("Hello");
123
- expect(storage.getItem("Hello")).toBeUndefined();
127
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
124
128
  })
125
129
 
126
- it("Should handle map", () => {
130
+ it("Should handle map", async () => {
127
131
  const map = {};
128
132
  const delegate = {
129
133
  getItem: (key) => map[key],
@@ -131,18 +135,18 @@ describe('Util', function() {
131
135
  removeItem: (key) => { delete map[key] }
132
136
  };
133
137
  const storage = new SafeStorage(delegate);
134
- expect(storage.getItem("Hello")).toBeUndefined();
135
- storage.setItem("Hello", { text: "World" });
138
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
139
+ await storage.setItem("Hello", { text: "World" });
136
140
  expect(map["Hello"]).toStrictEqual(JSON.stringify({text: "World"}));
137
- expect(storage.getItem("Hello")).toStrictEqual({"text": "World"});
138
- storage.setItem("Hello", "World"); // value should be JSON but errors are ignored
139
- expect(storage.getItem("Hello")).toBeUndefined();
140
- storage.setItem("Hello", { text: "World" });
141
- storage.removeItem("Hello");
142
- expect(storage.getItem("Hello")).toBeUndefined();
141
+ await expect(storage.getItem("Hello")).resolves.toStrictEqual({"text": "World"});
142
+ await storage.setItem("Hello", "World"); // value should be JSON but errors are ignored
143
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
144
+ await storage.setItem("Hello", { text: "World" });
145
+ await storage.removeItem("Hello");
146
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
143
147
  })
144
148
 
145
- it("Should handle root key", () => {
149
+ it("Should handle root key", async () => {
146
150
  const map = {};
147
151
  const delegate = {
148
152
  getItem: (key) => map[key],
@@ -150,17 +154,17 @@ describe('Util', function() {
150
154
  removeItem: (key) => { delete map[key] }
151
155
  };
152
156
  const storage = new SafeStorage(delegate, "root");
153
- expect(storage.getItem("Hello")).toBeUndefined();
154
- storage.setItem("Hello", { text: "World" });
157
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
158
+ await storage.setItem("Hello", { text: "World" });
155
159
  expect(map["root$Hello"]).toStrictEqual(JSON.stringify({text: "World"}));
156
- expect(storage.getItem("Hello")).toStrictEqual({"text": "World"});
157
- storage.setItem("Hello", "World"); // value should be JSON but errors are ignored
160
+ await expect(storage.getItem("Hello")).resolves.toStrictEqual({"text": "World"});
161
+ await storage.setItem("Hello", "World"); // value should be JSON but errors are ignored
158
162
  expect(map["root$Hello"]).toBeUndefined();
159
- expect(storage.getItem("Hello")).toBeUndefined();
160
- storage.setItem("Hello", { text: "World" });
161
- storage.removeItem("Hello");
163
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
164
+ await storage.setItem("Hello", { text: "World" });
165
+ await storage.removeItem("Hello");
162
166
  expect(map["root$Hello"]).toBeUndefined();
163
- expect(storage.getItem("Hello")).toBeUndefined();
167
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
164
168
  })
165
169
 
166
170
  it("Edge cases", () => {
@@ -172,7 +176,7 @@ describe('Util', function() {
172
176
  expect(new SafeStorage(null, "")._rootKey).toBe("");
173
177
  })
174
178
 
175
- it("Should remove invalid items on get", () => {
179
+ it("Should remove invalid items on get", async () => {
176
180
  const map = {};
177
181
  const delegate = {
178
182
  getItem: (key) => map[key],
@@ -182,12 +186,12 @@ describe('Util', function() {
182
186
  const storage = new SafeStorage(delegate, "root");
183
187
  // value is not valid because not a JSON serialized string
184
188
  map["root$Hello"] = "Invalid";
185
- expect(storage.getItem("Hello")).toBeUndefined();
189
+ await expect(storage.getItem("Hello")).resolves.toBeUndefined();
186
190
  // Get should have removed invalid value
187
191
  expect(map["root$Hello"]).toBeUndefined()
188
192
  })
189
193
 
190
- it("Should handle cache last cleared", () => {
194
+ it("Should handle cache last cleared", async () => {
191
195
  const map = {};
192
196
  const delegate = {
193
197
  getItem: (key) => map[key],
@@ -195,18 +199,18 @@ describe('Util', function() {
195
199
  removeItem: (key) => { delete map[key] }
196
200
  };
197
201
  const cache = new Cache(delegate, "root");
198
- cache.put("Hello", "World");
202
+ await cache.put("Hello", "World");
199
203
  expect(JSON.parse(map["root$Hello"])).toMatchObject({ value:"World" });
200
- expect(cache.get("Hello")).toBe("World");
201
- cache.clear();
204
+ await expect(cache.get("Hello")).resolves.toBe("World");
205
+ await cache.clear();
202
206
  // Clear could not remove the item from the map
203
207
  expect(JSON.parse(map["root$Hello"])).toMatchObject({ value:"World" });
204
208
  // But get from cache will
205
- expect(cache.get("Hello")).toBeUndefined();
209
+ await expect(cache.get("Hello")).resolves.toBeUndefined();
206
210
  })
207
211
  })
208
212
 
209
- it("Should preserve last cleared", () => {
213
+ it("Should preserve last cleared", async () => {
210
214
  const map = {};
211
215
  const delegate = {
212
216
  getItem: (key) => map[key],
@@ -214,19 +218,22 @@ describe('Util', function() {
214
218
  removeItem: (key) => { delete map[key] }
215
219
  };
216
220
  const cache = new Cache(delegate, "root");
217
- expect(cache._lastCleared).toBeUndefined();
218
- cache.put("Hello", "World");
219
- cache.clear();
221
+ expect(cache._lastCleared).toBeNull(); // means we do not have the last cleared value yet
222
+ await cache.get("dummy"); // trigger getItem to lastCleared, and then dummy
223
+ await cache.put("Hello", "World");
224
+ await cache.clear();
220
225
  const lastCleared = cache._lastCleared;
221
226
  expect(lastCleared).not.toBeUndefined();
222
- expect(cache.get("Hello")).toBeUndefined();
227
+ await expect(cache.get("Hello")).resolves.toBeUndefined();
223
228
  expect(map["root$lastCleared"]).toBe(JSON.stringify({timestamp:lastCleared}));
224
229
  // New cache with same delegate storage should preserve lastCleared date
225
230
  const cache2 = new Cache(delegate, "root");
231
+ expect(cache2._lastCleared).toBeNull(); // means we do not have the last cleared value yet
232
+ await cache2.get("dummy"); // trigger getItem to lastCleared, and then dummy
226
233
  expect(cache2._lastCleared).toBe(lastCleared);
227
234
  })
228
235
 
229
- it("Should cache in memory value which is in local storage", () => {
236
+ it("Should cache in memory value which is in local storage", async () => {
230
237
  const map = {};
231
238
  const delegate = {
232
239
  getItem: (key) => map[key],
@@ -235,7 +242,7 @@ describe('Util', function() {
235
242
  };
236
243
  const cache = new Cache(delegate, "root");
237
244
  map["root$Hello"] = JSON.stringify({ value: "World", cachedAt:Date.now() + 99999999 });
238
- const value = cache.get("Hello");
245
+ const value = await cache.get("Hello");
239
246
  expect(value).toBe("World");
240
247
  expect(cache._cache["Hello"].value).toBe("World");
241
248
  })
@@ -405,5 +412,23 @@ describe('Util', function() {
405
412
  expect(Util.isBrowser()).toBe(false);
406
413
  });
407
414
  });
415
+
416
+ describe("Promises", () => {
417
+ it("Should tell if an object is a promise", () => {
418
+ expect(Util.isPromise()).toBe(false);
419
+ expect(Util.isPromise(null)).toBe(false);
420
+ expect(Util.isPromise({})).toBe(false);
421
+ expect(Util.isPromise([])).toBe(false);
422
+ expect(Util.isPromise({ then: 3 })).toBe(false);
423
+ expect(Util.isPromise(new Promise((resolve, reject) => {}))).toBe(true);
424
+ expect(Util.isPromise(Promise.resolve(3))).toBe(true);
425
+ });
426
+
427
+ it("Should ensure a promise", async () => {
428
+ await expect(Util.asPromise(null)).resolves.toBe(null);
429
+ await expect(Util.asPromise(3)).resolves.toBe(3);
430
+ await expect(Util.asPromise(Promise.resolve(3))).resolves.toBe(3);
431
+ });
432
+ });
408
433
  });
409
434