@forge/storage 1.6.0-next.0 → 1.6.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.
|
@@ -56,7 +56,10 @@ const INVALID_CURSOR_ERROR = {
|
|
|
56
56
|
errorType: 'INVALID_CURSOR'
|
|
57
57
|
}
|
|
58
58
|
};
|
|
59
|
-
describe(
|
|
59
|
+
describe.each([
|
|
60
|
+
['with metrics', true],
|
|
61
|
+
['no metrics', false]
|
|
62
|
+
])('GlobalStorage - %s', (_, passMetrics) => {
|
|
60
63
|
function verifyApiClientCalledWith(apiClientMock, variables, query) {
|
|
61
64
|
expect(apiClientMock).toHaveBeenCalledWith('/forge/entities/graphql', expect.objectContaining({
|
|
62
65
|
method: 'POST',
|
|
@@ -84,7 +87,7 @@ describe('GlobalStorage', () => {
|
|
|
84
87
|
}
|
|
85
88
|
});
|
|
86
89
|
const metricMocks = getMetricMock();
|
|
87
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
90
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
88
91
|
const returnedValue = await globalStorage.get('testKey');
|
|
89
92
|
verifyApiClientCalledWith(apiClientMock, {
|
|
90
93
|
contextAri,
|
|
@@ -92,7 +95,9 @@ describe('GlobalStorage', () => {
|
|
|
92
95
|
encrypted: false
|
|
93
96
|
});
|
|
94
97
|
expect(returnedValue).toEqual('testValue');
|
|
95
|
-
|
|
98
|
+
passMetrics
|
|
99
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true)
|
|
100
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
96
101
|
});
|
|
97
102
|
it('should call the storage API, passing the provided key and returning undefined if the key doesnt exist', async () => {
|
|
98
103
|
const apiClientMock = getApiClientMock({
|
|
@@ -103,7 +108,7 @@ describe('GlobalStorage', () => {
|
|
|
103
108
|
}
|
|
104
109
|
});
|
|
105
110
|
const metricMocks = getMetricMock();
|
|
106
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
111
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
107
112
|
const returnedValue = await globalStorage.get('testKey');
|
|
108
113
|
verifyApiClientCalledWith(apiClientMock, {
|
|
109
114
|
contextAri,
|
|
@@ -111,7 +116,9 @@ describe('GlobalStorage', () => {
|
|
|
111
116
|
encrypted: false
|
|
112
117
|
});
|
|
113
118
|
expect(returnedValue).toEqual(undefined);
|
|
114
|
-
|
|
119
|
+
passMetrics
|
|
120
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true)
|
|
121
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
115
122
|
});
|
|
116
123
|
it('should call the storage API, passing the provided key and returning the stored falsey value 0', async () => {
|
|
117
124
|
const apiClientMock = getApiClientMock({
|
|
@@ -122,7 +129,7 @@ describe('GlobalStorage', () => {
|
|
|
122
129
|
}
|
|
123
130
|
});
|
|
124
131
|
const metricMocks = getMetricMock();
|
|
125
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
132
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
126
133
|
const returnedValue = await globalStorage.get('testKey');
|
|
127
134
|
verifyApiClientCalledWith(apiClientMock, {
|
|
128
135
|
contextAri,
|
|
@@ -130,7 +137,9 @@ describe('GlobalStorage', () => {
|
|
|
130
137
|
encrypted: false
|
|
131
138
|
});
|
|
132
139
|
expect(returnedValue).toEqual(0);
|
|
133
|
-
|
|
140
|
+
passMetrics
|
|
141
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true)
|
|
142
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
134
143
|
});
|
|
135
144
|
it('should call the storage API, passing the provided key and returning the stored empty string', async () => {
|
|
136
145
|
const apiClientMock = getApiClientMock({
|
|
@@ -141,7 +150,7 @@ describe('GlobalStorage', () => {
|
|
|
141
150
|
}
|
|
142
151
|
});
|
|
143
152
|
const metricMocks = getMetricMock();
|
|
144
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
153
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
145
154
|
const returnedValue = await globalStorage.get('testKey');
|
|
146
155
|
verifyApiClientCalledWith(apiClientMock, {
|
|
147
156
|
contextAri,
|
|
@@ -149,36 +158,44 @@ describe('GlobalStorage', () => {
|
|
|
149
158
|
encrypted: false
|
|
150
159
|
});
|
|
151
160
|
expect(returnedValue).toEqual('');
|
|
152
|
-
|
|
161
|
+
passMetrics
|
|
162
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true)
|
|
163
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
153
164
|
});
|
|
154
165
|
it('should throw an error with the returned status for non-200 status codes', async () => {
|
|
155
166
|
const apiClientMock = getApiClientMock(undefined, 400);
|
|
156
167
|
const metricMocks = getMetricMock();
|
|
157
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
168
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
158
169
|
const response = globalStorage.get('testKey');
|
|
159
170
|
expect(apiClientMock).toHaveBeenCalled();
|
|
160
171
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
161
|
-
|
|
172
|
+
passMetrics
|
|
173
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false)
|
|
174
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
162
175
|
});
|
|
163
176
|
it('should throw an error with the returned error message for failed responses', async () => {
|
|
164
177
|
const apiClientMock = getApiClientMock({
|
|
165
178
|
errors: [INVALID_CURSOR_ERROR]
|
|
166
179
|
}, 200);
|
|
167
180
|
const metricMocks = getMetricMock();
|
|
168
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
181
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
169
182
|
const response = globalStorage.get('testKey');
|
|
170
183
|
expect(apiClientMock).toHaveBeenCalled();
|
|
171
184
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
172
|
-
|
|
185
|
+
passMetrics
|
|
186
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false)
|
|
187
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
173
188
|
});
|
|
174
189
|
it('should throw an error if the response is not a valid JSON', async () => {
|
|
175
190
|
const apiClientMock = getApiClientMockInvalidJson('test', 200);
|
|
176
191
|
const metricMocks = getMetricMock();
|
|
177
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
192
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
178
193
|
const response = globalStorage.get('testKey');
|
|
179
194
|
expect(apiClientMock).toHaveBeenCalled();
|
|
180
195
|
await expect(response).rejects.toThrow(errors_1.APIError.forUnexpected('Response text was not a valid JSON: test'));
|
|
181
|
-
|
|
196
|
+
passMetrics
|
|
197
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false)
|
|
198
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
182
199
|
});
|
|
183
200
|
});
|
|
184
201
|
describe('get secret', () => {
|
|
@@ -191,7 +208,7 @@ describe('GlobalStorage', () => {
|
|
|
191
208
|
}
|
|
192
209
|
});
|
|
193
210
|
const metricMocks = getMetricMock();
|
|
194
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
211
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
195
212
|
const returnedValue = await globalStorage.getSecret('testKey');
|
|
196
213
|
verifyApiClientCalledWith(apiClientMock, {
|
|
197
214
|
contextAri,
|
|
@@ -199,7 +216,9 @@ describe('GlobalStorage', () => {
|
|
|
199
216
|
encrypted: true
|
|
200
217
|
});
|
|
201
218
|
expect(returnedValue).toEqual('testValue');
|
|
202
|
-
|
|
219
|
+
passMetrics
|
|
220
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: true }, true)
|
|
221
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
203
222
|
});
|
|
204
223
|
});
|
|
205
224
|
describe('set', () => {
|
|
@@ -214,7 +233,7 @@ describe('GlobalStorage', () => {
|
|
|
214
233
|
}
|
|
215
234
|
});
|
|
216
235
|
const metricMocks = getMetricMock();
|
|
217
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
236
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
218
237
|
await globalStorage.set('testKey', 'testValue');
|
|
219
238
|
verifyApiClientCalledWith(apiClientMock, {
|
|
220
239
|
input: {
|
|
@@ -224,7 +243,9 @@ describe('GlobalStorage', () => {
|
|
|
224
243
|
encrypted: false
|
|
225
244
|
}
|
|
226
245
|
});
|
|
227
|
-
|
|
246
|
+
passMetrics
|
|
247
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, true)
|
|
248
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
228
249
|
});
|
|
229
250
|
it('should throw an error if the storage API returns successful = false', async () => {
|
|
230
251
|
const apiClientMock = getApiClientMock({
|
|
@@ -238,20 +259,24 @@ describe('GlobalStorage', () => {
|
|
|
238
259
|
}
|
|
239
260
|
});
|
|
240
261
|
const metricMocks = getMetricMock();
|
|
241
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
262
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
242
263
|
const response = globalStorage.set('testKey', 'testValue');
|
|
243
264
|
expect(apiClientMock).toHaveBeenCalled();
|
|
244
265
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('INVALID_CURSOR', 'error message'));
|
|
245
|
-
|
|
266
|
+
passMetrics
|
|
267
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false)
|
|
268
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
246
269
|
});
|
|
247
270
|
it('should throw an error if the storage API returns a non 200 status code', async () => {
|
|
248
271
|
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
249
272
|
const metricMocks = getMetricMock();
|
|
250
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
273
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
251
274
|
const response = globalStorage.set('testKey', 'testValue');
|
|
252
275
|
expect(apiClientMock).toHaveBeenCalled();
|
|
253
276
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
254
|
-
|
|
277
|
+
passMetrics
|
|
278
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false)
|
|
279
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
255
280
|
});
|
|
256
281
|
it('should throw a 500 error if success=false but no errors were returned', async () => {
|
|
257
282
|
const apiClientMock = getApiClientMock({
|
|
@@ -264,7 +289,7 @@ describe('GlobalStorage', () => {
|
|
|
264
289
|
}
|
|
265
290
|
});
|
|
266
291
|
const metricMocks = getMetricMock();
|
|
267
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
292
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
268
293
|
await expect(globalStorage.set('testKey', 'testValue')).rejects.toThrow(errors_1.APIError.forStatus(500));
|
|
269
294
|
verifyApiClientCalledWith(apiClientMock, {
|
|
270
295
|
input: {
|
|
@@ -274,7 +299,9 @@ describe('GlobalStorage', () => {
|
|
|
274
299
|
encrypted: false
|
|
275
300
|
}
|
|
276
301
|
});
|
|
277
|
-
|
|
302
|
+
passMetrics
|
|
303
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false)
|
|
304
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
278
305
|
});
|
|
279
306
|
});
|
|
280
307
|
describe('set secret', () => {
|
|
@@ -289,7 +316,7 @@ describe('GlobalStorage', () => {
|
|
|
289
316
|
}
|
|
290
317
|
});
|
|
291
318
|
const metricMocks = getMetricMock();
|
|
292
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
319
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
293
320
|
await globalStorage.setSecret('testKey', 'testValue');
|
|
294
321
|
verifyApiClientCalledWith(apiClientMock, {
|
|
295
322
|
input: {
|
|
@@ -299,7 +326,9 @@ describe('GlobalStorage', () => {
|
|
|
299
326
|
encrypted: true
|
|
300
327
|
}
|
|
301
328
|
});
|
|
302
|
-
|
|
329
|
+
passMetrics
|
|
330
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: true }, true)
|
|
331
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
303
332
|
});
|
|
304
333
|
});
|
|
305
334
|
describe('delete', () => {
|
|
@@ -314,7 +343,7 @@ describe('GlobalStorage', () => {
|
|
|
314
343
|
}
|
|
315
344
|
});
|
|
316
345
|
const metricMocks = getMetricMock();
|
|
317
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
346
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
318
347
|
await globalStorage.delete('testKey');
|
|
319
348
|
verifyApiClientCalledWith(apiClientMock, {
|
|
320
349
|
input: {
|
|
@@ -323,7 +352,9 @@ describe('GlobalStorage', () => {
|
|
|
323
352
|
encrypted: false
|
|
324
353
|
}
|
|
325
354
|
});
|
|
326
|
-
|
|
355
|
+
passMetrics
|
|
356
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, true)
|
|
357
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
327
358
|
});
|
|
328
359
|
it('should throw an error if the storage API returns successful = false', async () => {
|
|
329
360
|
const apiClientMock = getApiClientMock({
|
|
@@ -337,20 +368,24 @@ describe('GlobalStorage', () => {
|
|
|
337
368
|
}
|
|
338
369
|
});
|
|
339
370
|
const metricMocks = getMetricMock();
|
|
340
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
371
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
341
372
|
const response = globalStorage.delete('testKey');
|
|
342
373
|
expect(apiClientMock).toHaveBeenCalled();
|
|
343
374
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
344
|
-
|
|
375
|
+
passMetrics
|
|
376
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, false)
|
|
377
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
345
378
|
});
|
|
346
379
|
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
|
|
347
380
|
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
348
381
|
const metricMocks = getMetricMock();
|
|
349
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
382
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
350
383
|
const response = globalStorage.delete('testKey');
|
|
351
384
|
expect(apiClientMock).toHaveBeenCalled();
|
|
352
385
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
353
|
-
|
|
386
|
+
passMetrics
|
|
387
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, false)
|
|
388
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
354
389
|
});
|
|
355
390
|
});
|
|
356
391
|
describe('delete secret', () => {
|
|
@@ -365,7 +400,7 @@ describe('GlobalStorage', () => {
|
|
|
365
400
|
}
|
|
366
401
|
});
|
|
367
402
|
const metricMocks = getMetricMock();
|
|
368
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
403
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
369
404
|
await globalStorage.deleteSecret('testKey');
|
|
370
405
|
verifyApiClientCalledWith(apiClientMock, {
|
|
371
406
|
input: {
|
|
@@ -374,7 +409,9 @@ describe('GlobalStorage', () => {
|
|
|
374
409
|
encrypted: true
|
|
375
410
|
}
|
|
376
411
|
});
|
|
377
|
-
|
|
412
|
+
passMetrics
|
|
413
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: true }, true)
|
|
414
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
378
415
|
});
|
|
379
416
|
});
|
|
380
417
|
describe('getEntity', () => {
|
|
@@ -387,7 +424,7 @@ describe('GlobalStorage', () => {
|
|
|
387
424
|
}
|
|
388
425
|
});
|
|
389
426
|
const metricMocks = getMetricMock();
|
|
390
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
427
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
391
428
|
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
392
429
|
verifyApiClientCalledWith(apiClientMock, {
|
|
393
430
|
contextAri,
|
|
@@ -395,7 +432,9 @@ describe('GlobalStorage', () => {
|
|
|
395
432
|
key: 'testEntityKey'
|
|
396
433
|
});
|
|
397
434
|
expect(returnedValue).toEqual('testValue');
|
|
398
|
-
|
|
435
|
+
passMetrics
|
|
436
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true)
|
|
437
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
399
438
|
});
|
|
400
439
|
it('should call the storage API, passing the provided entity key and returning undefined if the key doesnt exist', async () => {
|
|
401
440
|
const apiClientMock = getApiClientMock({
|
|
@@ -406,7 +445,7 @@ describe('GlobalStorage', () => {
|
|
|
406
445
|
}
|
|
407
446
|
});
|
|
408
447
|
const metricMocks = getMetricMock();
|
|
409
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
448
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
410
449
|
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
411
450
|
verifyApiClientCalledWith(apiClientMock, {
|
|
412
451
|
contextAri,
|
|
@@ -414,7 +453,9 @@ describe('GlobalStorage', () => {
|
|
|
414
453
|
key: 'testEntityKey'
|
|
415
454
|
});
|
|
416
455
|
expect(returnedValue).toEqual(undefined);
|
|
417
|
-
|
|
456
|
+
passMetrics
|
|
457
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true)
|
|
458
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
418
459
|
});
|
|
419
460
|
it('should call the storage API, passing the provided key and returning the stored falsey value 0', async () => {
|
|
420
461
|
const apiClientMock = getApiClientMock({
|
|
@@ -425,7 +466,7 @@ describe('GlobalStorage', () => {
|
|
|
425
466
|
}
|
|
426
467
|
});
|
|
427
468
|
const metricMocks = getMetricMock();
|
|
428
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
469
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
429
470
|
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
430
471
|
verifyApiClientCalledWith(apiClientMock, {
|
|
431
472
|
contextAri,
|
|
@@ -433,7 +474,9 @@ describe('GlobalStorage', () => {
|
|
|
433
474
|
key: 'testEntityKey'
|
|
434
475
|
});
|
|
435
476
|
expect(returnedValue).toEqual(0);
|
|
436
|
-
|
|
477
|
+
passMetrics
|
|
478
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true)
|
|
479
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
437
480
|
});
|
|
438
481
|
it('should call the storage API, passing the provided key and returning the stored empty string', async () => {
|
|
439
482
|
const apiClientMock = getApiClientMock({
|
|
@@ -444,7 +487,7 @@ describe('GlobalStorage', () => {
|
|
|
444
487
|
}
|
|
445
488
|
});
|
|
446
489
|
const metricMocks = getMetricMock();
|
|
447
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
490
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
448
491
|
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
449
492
|
verifyApiClientCalledWith(apiClientMock, {
|
|
450
493
|
contextAri,
|
|
@@ -452,36 +495,44 @@ describe('GlobalStorage', () => {
|
|
|
452
495
|
key: 'testEntityKey'
|
|
453
496
|
});
|
|
454
497
|
expect(returnedValue).toEqual('');
|
|
455
|
-
|
|
498
|
+
passMetrics
|
|
499
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true)
|
|
500
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
456
501
|
});
|
|
457
502
|
it('should throw an error with the returned status for non-200 status codes', async () => {
|
|
458
503
|
const apiClientMock = getApiClientMock(undefined, 400);
|
|
459
504
|
const metricMocks = getMetricMock();
|
|
460
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
505
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
461
506
|
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
462
507
|
expect(apiClientMock).toHaveBeenCalled();
|
|
463
508
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
464
|
-
|
|
509
|
+
passMetrics
|
|
510
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false)
|
|
511
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
465
512
|
});
|
|
466
513
|
it('should throw an error with the returned error message for failed responses', async () => {
|
|
467
514
|
const apiClientMock = getApiClientMock({
|
|
468
515
|
errors: [INVALID_CURSOR_ERROR]
|
|
469
516
|
}, 200);
|
|
470
517
|
const metricMocks = getMetricMock();
|
|
471
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
518
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
472
519
|
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
473
520
|
expect(apiClientMock).toHaveBeenCalled();
|
|
474
521
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
475
|
-
|
|
522
|
+
passMetrics
|
|
523
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false)
|
|
524
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
476
525
|
});
|
|
477
526
|
it('should throw an error if the response is not a valid JSON', async () => {
|
|
478
527
|
const apiClientMock = getApiClientMockInvalidJson('test', 200);
|
|
479
528
|
const metricMocks = getMetricMock();
|
|
480
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
529
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
481
530
|
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
|
|
482
531
|
expect(apiClientMock).toHaveBeenCalled();
|
|
483
532
|
await expect(response).rejects.toThrow(errors_1.APIError.forUnexpected('Response text was not a valid JSON: test'));
|
|
484
|
-
|
|
533
|
+
passMetrics
|
|
534
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false)
|
|
535
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
485
536
|
});
|
|
486
537
|
});
|
|
487
538
|
describe('setEntity', () => {
|
|
@@ -496,7 +547,7 @@ describe('GlobalStorage', () => {
|
|
|
496
547
|
}
|
|
497
548
|
});
|
|
498
549
|
const metricMocks = getMetricMock();
|
|
499
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
550
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
500
551
|
await globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
|
|
501
552
|
verifyApiClientCalledWith(apiClientMock, {
|
|
502
553
|
input: {
|
|
@@ -506,7 +557,9 @@ describe('GlobalStorage', () => {
|
|
|
506
557
|
value: 'testValue'
|
|
507
558
|
}
|
|
508
559
|
});
|
|
509
|
-
|
|
560
|
+
passMetrics
|
|
561
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, true)
|
|
562
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
510
563
|
});
|
|
511
564
|
it('should throw an error if the storage API returns successful = false', async () => {
|
|
512
565
|
const apiClientMock = getApiClientMock({
|
|
@@ -520,20 +573,24 @@ describe('GlobalStorage', () => {
|
|
|
520
573
|
}
|
|
521
574
|
});
|
|
522
575
|
const metricMocks = getMetricMock();
|
|
523
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
576
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
524
577
|
const response = globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
|
|
525
578
|
expect(apiClientMock).toHaveBeenCalled();
|
|
526
579
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('INVALID_CURSOR', 'error message'));
|
|
527
|
-
|
|
580
|
+
passMetrics
|
|
581
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false)
|
|
582
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
528
583
|
});
|
|
529
584
|
it('should throw an error if the storage API returns a non 200 status code', async () => {
|
|
530
585
|
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
531
586
|
const metricMocks = getMetricMock();
|
|
532
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
587
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
533
588
|
const response = globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
|
|
534
589
|
expect(apiClientMock).toHaveBeenCalled();
|
|
535
590
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
536
|
-
|
|
591
|
+
passMetrics
|
|
592
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false)
|
|
593
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
537
594
|
});
|
|
538
595
|
it('should throw a 500 error if success=false but no errors were returned', async () => {
|
|
539
596
|
const apiClientMock = getApiClientMock({
|
|
@@ -546,7 +603,7 @@ describe('GlobalStorage', () => {
|
|
|
546
603
|
}
|
|
547
604
|
});
|
|
548
605
|
const metricMocks = getMetricMock();
|
|
549
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
606
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
550
607
|
await expect(globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue')).rejects.toThrow(errors_1.APIError.forStatus(500));
|
|
551
608
|
verifyApiClientCalledWith(apiClientMock, {
|
|
552
609
|
input: {
|
|
@@ -556,7 +613,9 @@ describe('GlobalStorage', () => {
|
|
|
556
613
|
value: 'testValue'
|
|
557
614
|
}
|
|
558
615
|
});
|
|
559
|
-
|
|
616
|
+
passMetrics
|
|
617
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false)
|
|
618
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
560
619
|
});
|
|
561
620
|
});
|
|
562
621
|
describe('deleteEntity', () => {
|
|
@@ -571,7 +630,7 @@ describe('GlobalStorage', () => {
|
|
|
571
630
|
}
|
|
572
631
|
});
|
|
573
632
|
const metricMocks = getMetricMock();
|
|
574
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
633
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
575
634
|
await globalStorage.deleteEntity('testEntityName', 'testEntityKey');
|
|
576
635
|
verifyApiClientCalledWith(apiClientMock, {
|
|
577
636
|
input: {
|
|
@@ -580,7 +639,9 @@ describe('GlobalStorage', () => {
|
|
|
580
639
|
key: 'testEntityKey'
|
|
581
640
|
}
|
|
582
641
|
});
|
|
583
|
-
|
|
642
|
+
passMetrics
|
|
643
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, true)
|
|
644
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
584
645
|
});
|
|
585
646
|
it('should throw an error if the storage API returns successful = false', async () => {
|
|
586
647
|
const apiClientMock = getApiClientMock({
|
|
@@ -594,20 +655,24 @@ describe('GlobalStorage', () => {
|
|
|
594
655
|
}
|
|
595
656
|
});
|
|
596
657
|
const metricMocks = getMetricMock();
|
|
597
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
658
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
598
659
|
const response = globalStorage.deleteEntity('testEntityKey', 'testEntityKey');
|
|
599
660
|
expect(apiClientMock).toHaveBeenCalled();
|
|
600
661
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
601
|
-
|
|
662
|
+
passMetrics
|
|
663
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, false)
|
|
664
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
602
665
|
});
|
|
603
666
|
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
|
|
604
667
|
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
605
668
|
const metricMocks = getMetricMock();
|
|
606
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
669
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
607
670
|
const response = globalStorage.deleteEntity('testEntityKey', 'testEntityKey');
|
|
608
671
|
expect(apiClientMock).toHaveBeenCalled();
|
|
609
672
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
610
|
-
|
|
673
|
+
passMetrics
|
|
674
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, false)
|
|
675
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
611
676
|
});
|
|
612
677
|
});
|
|
613
678
|
describe('list', () => {
|
|
@@ -623,7 +688,7 @@ describe('GlobalStorage', () => {
|
|
|
623
688
|
}
|
|
624
689
|
});
|
|
625
690
|
const metricMocks = getMetricMock();
|
|
626
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
691
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
627
692
|
const where = [
|
|
628
693
|
{
|
|
629
694
|
field: 'key',
|
|
@@ -647,7 +712,9 @@ describe('GlobalStorage', () => {
|
|
|
647
712
|
],
|
|
648
713
|
nextCursor: 'cursor2'
|
|
649
714
|
}));
|
|
650
|
-
|
|
715
|
+
passMetrics
|
|
716
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)
|
|
717
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
651
718
|
});
|
|
652
719
|
it('should query the appStoredEntitiesForCleanup endpoint given process.env.IS_CLEANUP_FUNCTION is set to true', async () => {
|
|
653
720
|
process.env.IS_CLEANUP_FUNCTION = 'true';
|
|
@@ -662,7 +729,7 @@ describe('GlobalStorage', () => {
|
|
|
662
729
|
}
|
|
663
730
|
});
|
|
664
731
|
const metricMocks = getMetricMock();
|
|
665
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
732
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
666
733
|
const where = [
|
|
667
734
|
{
|
|
668
735
|
field: 'key',
|
|
@@ -686,7 +753,9 @@ describe('GlobalStorage', () => {
|
|
|
686
753
|
],
|
|
687
754
|
nextCursor: 'cursor2'
|
|
688
755
|
}));
|
|
689
|
-
|
|
756
|
+
passMetrics
|
|
757
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)
|
|
758
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
690
759
|
process.env.IS_CLEANUP_FUNCTION = '';
|
|
691
760
|
});
|
|
692
761
|
it('should use default values', async () => {
|
|
@@ -698,7 +767,7 @@ describe('GlobalStorage', () => {
|
|
|
698
767
|
}
|
|
699
768
|
});
|
|
700
769
|
const metricMocks = getMetricMock();
|
|
701
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
770
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
702
771
|
await globalStorage.list({});
|
|
703
772
|
verifyApiClientCalledWith(apiClientMock, {
|
|
704
773
|
contextAri,
|
|
@@ -706,7 +775,9 @@ describe('GlobalStorage', () => {
|
|
|
706
775
|
cursor: null,
|
|
707
776
|
limit: null
|
|
708
777
|
}, gql_queries_1.UntypedQueries.listQuery(contextAri, {}).query);
|
|
709
|
-
|
|
778
|
+
passMetrics
|
|
779
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)
|
|
780
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
710
781
|
});
|
|
711
782
|
it('should handle an empty result set', async () => {
|
|
712
783
|
const apiClientMock = getApiClientMock({
|
|
@@ -717,7 +788,7 @@ describe('GlobalStorage', () => {
|
|
|
717
788
|
}
|
|
718
789
|
});
|
|
719
790
|
const metricMocks = getMetricMock();
|
|
720
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
791
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
721
792
|
const where = [
|
|
722
793
|
{
|
|
723
794
|
field: 'key',
|
|
@@ -730,27 +801,33 @@ describe('GlobalStorage', () => {
|
|
|
730
801
|
results: [],
|
|
731
802
|
nextCursor: undefined
|
|
732
803
|
}));
|
|
733
|
-
|
|
804
|
+
passMetrics
|
|
805
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)
|
|
806
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
734
807
|
});
|
|
735
808
|
it('should throw an error if the storage API returns an error', async () => {
|
|
736
809
|
const apiClientMock = getApiClientMock({
|
|
737
810
|
errors: [INVALID_CURSOR_ERROR]
|
|
738
811
|
});
|
|
739
812
|
const metricMocks = getMetricMock();
|
|
740
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
813
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
741
814
|
const response = globalStorage.list({});
|
|
742
815
|
expect(apiClientMock).toHaveBeenCalled();
|
|
743
816
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
744
|
-
|
|
817
|
+
passMetrics
|
|
818
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, false)
|
|
819
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
745
820
|
});
|
|
746
821
|
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
|
|
747
822
|
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
748
823
|
const metricMocks = getMetricMock();
|
|
749
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
824
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
750
825
|
const response = globalStorage.list({});
|
|
751
826
|
expect(apiClientMock).toHaveBeenCalled();
|
|
752
827
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
753
|
-
|
|
828
|
+
passMetrics
|
|
829
|
+
? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, false)
|
|
830
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
754
831
|
});
|
|
755
832
|
});
|
|
756
833
|
describe('listCustomEntities', () => {
|
|
@@ -763,7 +840,7 @@ describe('GlobalStorage', () => {
|
|
|
763
840
|
}
|
|
764
841
|
});
|
|
765
842
|
const metricMocks = getMetricMock();
|
|
766
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
843
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
767
844
|
const response = await globalStorage.listCustomEntities({});
|
|
768
845
|
expect(response).toMatchObject({
|
|
769
846
|
results: [],
|
|
@@ -772,7 +849,9 @@ describe('GlobalStorage', () => {
|
|
|
772
849
|
verifyApiClientCalledWith(apiClientMock, {
|
|
773
850
|
contextAri
|
|
774
851
|
}, gql_queries_1.CustomEntityQueries.listQuery(contextAri, {}).query);
|
|
775
|
-
|
|
852
|
+
passMetrics
|
|
853
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, true)
|
|
854
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
776
855
|
});
|
|
777
856
|
it('should return cursor when results are not present', async () => {
|
|
778
857
|
const apiClientMock = getApiClientMock({
|
|
@@ -784,7 +863,7 @@ describe('GlobalStorage', () => {
|
|
|
784
863
|
}
|
|
785
864
|
});
|
|
786
865
|
const metricMocks = getMetricMock();
|
|
787
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
866
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
788
867
|
const response = await globalStorage.listCustomEntities({});
|
|
789
868
|
expect(response).toMatchObject({
|
|
790
869
|
results: [],
|
|
@@ -793,27 +872,33 @@ describe('GlobalStorage', () => {
|
|
|
793
872
|
verifyApiClientCalledWith(apiClientMock, {
|
|
794
873
|
contextAri
|
|
795
874
|
}, gql_queries_1.CustomEntityQueries.listQuery(contextAri, {}).query);
|
|
796
|
-
|
|
875
|
+
passMetrics
|
|
876
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, true)
|
|
877
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
797
878
|
});
|
|
798
879
|
it('should throw an error if the storage API returns an error', async () => {
|
|
799
880
|
const apiClientMock = getApiClientMock({
|
|
800
881
|
errors: [INVALID_CURSOR_ERROR]
|
|
801
882
|
});
|
|
802
883
|
const metricMocks = getMetricMock();
|
|
803
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
884
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
804
885
|
const response = globalStorage.listCustomEntities({});
|
|
805
886
|
expect(apiClientMock).toHaveBeenCalled();
|
|
806
887
|
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
|
|
807
|
-
|
|
888
|
+
passMetrics
|
|
889
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, false)
|
|
890
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
808
891
|
});
|
|
809
892
|
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
|
|
810
893
|
const apiClientMock = getApiClientMockInvalidJson('', 400);
|
|
811
894
|
const metricMocks = getMetricMock();
|
|
812
|
-
const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
|
|
895
|
+
const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
|
|
813
896
|
const response = globalStorage.listCustomEntities({});
|
|
814
897
|
expect(apiClientMock).toHaveBeenCalled();
|
|
815
898
|
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
|
|
816
|
-
|
|
899
|
+
passMetrics
|
|
900
|
+
? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, false)
|
|
901
|
+
: expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
|
|
817
902
|
});
|
|
818
903
|
});
|
|
819
904
|
});
|
package/out/global-storage.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class GlobalStorage implements SharedStorageAdapter {
|
|
|
16
16
|
private apiClient;
|
|
17
17
|
private readonly getMetrics;
|
|
18
18
|
private readonly endpoint;
|
|
19
|
-
constructor(getAppContextAri: (() => string) | string, apiClient: FetchMethod, getMetrics: () => Metrics);
|
|
19
|
+
constructor(getAppContextAri: (() => string) | string, apiClient: FetchMethod, getMetrics: () => Metrics | undefined);
|
|
20
20
|
private doGetAppContextAri;
|
|
21
21
|
get(key: string): Promise<any>;
|
|
22
22
|
getSecret(key: string): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-storage.d.ts","sourceRoot":"","sources":["../src/global-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,SAAS,CAAC;AAInD,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAEtE,UAAU,WAAW;IACnB,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,EAAE,CAAC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAcD,oBAAY,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAC5C,oBAAY,aAAa,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AA+B/D,qBAAa,aAAc,YAAW,oBAAoB;IAGtD,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJ7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;gBAE5C,gBAAgB,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EACzC,SAAS,EAAE,WAAW,EACb,UAAU,EAAE,MAAM,OAAO;
|
|
1
|
+
{"version":3,"file":"global-storage.d.ts","sourceRoot":"","sources":["../src/global-storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,WAAW,EAAE,MAAM,SAAS,CAAC;AAInD,OAAO,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wCAAwC,CAAC;AAEtE,UAAU,WAAW;IACnB,OAAO,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,GAAG,CAAA;KAAE,EAAE,CAAC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAcD,oBAAY,SAAS,GAAG,OAAO,GAAG,SAAS,CAAC;AAC5C,oBAAY,aAAa,GAAG,KAAK,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AA+B/D,qBAAa,aAAc,YAAW,oBAAoB;IAGtD,OAAO,CAAC,gBAAgB;IACxB,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAJ7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;gBAE5C,gBAAgB,EAAE,CAAC,MAAM,MAAM,CAAC,GAAG,MAAM,EACzC,SAAS,EAAE,WAAW,EACb,UAAU,EAAE,MAAM,OAAO,GAAG,SAAS;IAGxD,OAAO,CAAC,kBAAkB;IAIpB,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAI9B,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAIpC,IAAI,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;IAqBhD,kBAAkB,CAAC,OAAO,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC;IAc1E,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3C,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAUjD,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOlC,YAAY,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOxC,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAI/D,SAAS,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAO5E,YAAY,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAU1D,WAAW;YAUX,iBAAiB;IAU/B,OAAO,CAAC,YAAY;YAUN,KAAK;YAML,QAAQ;YAsBR,YAAY;CAyC3B"}
|
package/out/global-storage.js
CHANGED
|
@@ -129,6 +129,9 @@ class GlobalStorage {
|
|
|
129
129
|
}
|
|
130
130
|
async wrapInMetric(store, operation, encrypted, fn) {
|
|
131
131
|
const metrics = this.getMetrics();
|
|
132
|
+
if (!metrics) {
|
|
133
|
+
return await fn();
|
|
134
|
+
}
|
|
132
135
|
const timer = metrics
|
|
133
136
|
.timing('forge.runtime.storage.operation.latency', { store, operation, encrypted: String(encrypted) })
|
|
134
137
|
.measure();
|