npm package diff
Package: @forge/storage
Versions: 1.6.0-next.0 - 1.6.0-next.1
File: package/out/__test__/global-storage.test.js
Index: package/out/__test__/global-storage.test.js
===================================================================
--- package/out/__test__/global-storage.test.js
+++ package/out/__test__/global-storage.test.js
@@ -55,9 +55,12 @@
extensions: {
errorType: 'INVALID_CURSOR'
}
};
-describe('GlobalStorage', () => {
+describe.each([
+ ['with metrics', true],
+ ['no metrics', false]
+])('GlobalStorage - %s', (_, passMetrics) => {
function verifyApiClientCalledWith(apiClientMock, variables, query) {
expect(apiClientMock).toHaveBeenCalledWith('/forge/entities/graphql', expect.objectContaining({
method: 'POST',
body: expect.any(String),
@@ -83,17 +86,19 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.get('testKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',
encrypted: false
});
expect(returnedValue).toEqual('testValue');
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should call the storage API, passing the provided key and returning undefined if the key doesnt exist', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -102,17 +107,19 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.get('testKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',
encrypted: false
});
expect(returnedValue).toEqual(undefined);
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should call the storage API, passing the provided key and returning the stored falsey value 0', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -121,17 +128,19 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.get('testKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',
encrypted: false
});
expect(returnedValue).toEqual(0);
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should call the storage API, passing the provided key and returning the stored empty string', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -140,46 +149,54 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.get('testKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',
encrypted: false
});
expect(returnedValue).toEqual('');
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error with the returned status for non-200 status codes', async () => {
const apiClientMock = getApiClientMock(undefined, 400);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.get('testKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error with the returned error message for failed responses', async () => {
const apiClientMock = getApiClientMock({
errors: [INVALID_CURSOR_ERROR]
}, 200);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.get('testKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the response is not a valid JSON', async () => {
const apiClientMock = getApiClientMockInvalidJson('test', 200);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.get('testKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forUnexpected('Response text was not a valid JSON: test'));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('get secret', () => {
it('should call the storage API, passing the provided key and returning the stored value', async () => {
@@ -190,17 +207,19 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.getSecret('testKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
key: 'testKey',
encrypted: true
});
expect(returnedValue).toEqual('testValue');
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: true }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'get', encrypted: true }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('set', () => {
it('should call the storage API, passing the provided key and value', async () => {
@@ -213,9 +232,9 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await globalStorage.set('testKey', 'testValue');
verifyApiClientCalledWith(apiClientMock, {
input: {
contextAri,
@@ -223,9 +242,11 @@
value: 'testValue',
encrypted: false
}
});
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns successful = false', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -237,22 +258,26 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.set('testKey', 'testValue');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('INVALID_CURSOR', 'error message'));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns a non 200 status code', async () => {
const apiClientMock = getApiClientMockInvalidJson('', 400);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.set('testKey', 'testValue');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw a 500 error if success=false but no errors were returned', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -263,9 +288,9 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await expect(globalStorage.set('testKey', 'testValue')).rejects.toThrow(errors_1.APIError.forStatus(500));
verifyApiClientCalledWith(apiClientMock, {
input: {
contextAri,
@@ -273,9 +298,11 @@
value: 'testValue',
encrypted: false
}
});
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('set secret', () => {
it('should call the storage API, passing the provided key and value', async () => {
@@ -288,9 +315,9 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await globalStorage.setSecret('testKey', 'testValue');
verifyApiClientCalledWith(apiClientMock, {
input: {
contextAri,
@@ -298,9 +325,11 @@
value: 'testValue',
encrypted: true
}
});
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: true }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'set', encrypted: true }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('delete', () => {
it('should call the storage API, passing the provided key', async () => {
@@ -313,18 +342,20 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await globalStorage.delete('testKey');
verifyApiClientCalledWith(apiClientMock, {
input: {
contextAri,
key: 'testKey',
encrypted: false
}
});
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns successful = false', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -336,22 +367,26 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.delete('testKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
const apiClientMock = getApiClientMockInvalidJson('', 400);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.delete('testKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('delete secret', () => {
it('should call the storage API, passing the provided key', async () => {
@@ -364,18 +399,20 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await globalStorage.deleteSecret('testKey');
verifyApiClientCalledWith(apiClientMock, {
input: {
contextAri,
key: 'testKey',
encrypted: true
}
});
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: true }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'delete', encrypted: true }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('getEntity', () => {
it('should call the storage API, passing the provided entity name and entity key and returning the stored value', async () => {
@@ -386,17 +423,19 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
entityName: 'testEntityName',
key: 'testEntityKey'
});
expect(returnedValue).toEqual('testValue');
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should call the storage API, passing the provided entity key and returning undefined if the key doesnt exist', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -405,17 +444,19 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
entityName: 'testEntityName',
key: 'testEntityKey'
});
expect(returnedValue).toEqual(undefined);
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should call the storage API, passing the provided key and returning the stored falsey value 0', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -424,17 +465,19 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
entityName: 'testEntityName',
key: 'testEntityKey'
});
expect(returnedValue).toEqual(0);
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should call the storage API, passing the provided key and returning the stored empty string', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -443,46 +486,54 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const returnedValue = await globalStorage.getEntity('testEntityName', 'testEntityKey');
verifyApiClientCalledWith(apiClientMock, {
contextAri,
entityName: 'testEntityName',
key: 'testEntityKey'
});
expect(returnedValue).toEqual('');
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error with the returned status for non-200 status codes', async () => {
const apiClientMock = getApiClientMock(undefined, 400);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error with the returned error message for failed responses', async () => {
const apiClientMock = getApiClientMock({
errors: [INVALID_CURSOR_ERROR]
}, 200);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the response is not a valid JSON', async () => {
const apiClientMock = getApiClientMockInvalidJson('test', 200);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.getEntity('testEntityName', 'testEntityKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forUnexpected('Response text was not a valid JSON: test'));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'get', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('setEntity', () => {
it('should call the storage API, passing the provided entity name, entity key and value', async () => {
@@ -495,9 +546,9 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
verifyApiClientCalledWith(apiClientMock, {
input: {
contextAri,
@@ -505,9 +556,11 @@
key: 'testEntityKey',
value: 'testValue'
}
});
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns successful = false', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -519,22 +572,26 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('INVALID_CURSOR', 'error message'));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns a non 200 status code', async () => {
const apiClientMock = getApiClientMockInvalidJson('', 400);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw a 500 error if success=false but no errors were returned', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -545,9 +602,9 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await expect(globalStorage.setEntity('testEntityName', 'testEntityKey', 'testValue')).rejects.toThrow(errors_1.APIError.forStatus(500));
verifyApiClientCalledWith(apiClientMock, {
input: {
contextAri,
@@ -555,9 +612,11 @@
key: 'testEntityKey',
value: 'testValue'
}
});
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'set', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('deleteEntity', () => {
it('should call the storage API, passing the provided entity name and key', async () => {
@@ -570,18 +629,20 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await globalStorage.deleteEntity('testEntityName', 'testEntityKey');
verifyApiClientCalledWith(apiClientMock, {
input: {
contextAri,
entityName: 'testEntityName',
key: 'testEntityKey'
}
});
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns successful = false', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -593,22 +654,26 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.deleteEntity('testEntityKey', 'testEntityKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
const apiClientMock = getApiClientMockInvalidJson('', 400);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.deleteEntity('testEntityKey', 'testEntityKey');
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'delete', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('list', () => {
it('should call the storage API with the provided parameters', async () => {
@@ -622,9 +687,9 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const where = [
{
field: 'key',
condition: 'STARTS_WITH',
@@ -646,9 +711,11 @@
{ key: 'key2', value: 'testValue' }
],
nextCursor: 'cursor2'
}));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should query the appStoredEntitiesForCleanup endpoint given process.env.IS_CLEANUP_FUNCTION is set to true', async () => {
process.env.IS_CLEANUP_FUNCTION = 'true';
const apiClientMock = getApiClientMock({
@@ -661,9 +728,9 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const where = [
{
field: 'key',
condition: 'STARTS_WITH',
@@ -685,9 +752,11 @@
{ key: 'key2', value: 'testValue' }
],
nextCursor: 'cursor2'
}));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
process.env.IS_CLEANUP_FUNCTION = '';
});
it('should use default values', async () => {
const apiClientMock = getApiClientMock({
@@ -697,17 +766,19 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
await globalStorage.list({});
verifyApiClientCalledWith(apiClientMock, {
contextAri,
where: null,
cursor: null,
limit: null
}, gql_queries_1.UntypedQueries.listQuery(contextAri, {}).query);
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should handle an empty result set', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -716,9 +787,9 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const where = [
{
field: 'key',
condition: 'STARTS_WITH',
@@ -729,29 +800,35 @@
expect(response).toEqual(expect.objectContaining({
results: [],
nextCursor: undefined
}));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns an error', async () => {
const apiClientMock = getApiClientMock({
errors: [INVALID_CURSOR_ERROR]
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.list({});
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
const apiClientMock = getApiClientMockInvalidJson('', 400);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.list({});
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
- checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'untyped', operation: 'query', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
describe('listCustomEntities', () => {
it('should use default values', async () => {
@@ -762,18 +839,20 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = await globalStorage.listCustomEntities({});
expect(response).toMatchObject({
results: [],
nextCursor: null
});
verifyApiClientCalledWith(apiClientMock, {
contextAri
}, gql_queries_1.CustomEntityQueries.listQuery(contextAri, {}).query);
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should return cursor when results are not present', async () => {
const apiClientMock = getApiClientMock({
data: {
@@ -783,37 +862,43 @@
}
}
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = await globalStorage.listCustomEntities({});
expect(response).toMatchObject({
results: [],
nextCursor: 'DUMMY_CURSOR'
});
verifyApiClientCalledWith(apiClientMock, {
contextAri
}, gql_queries_1.CustomEntityQueries.listQuery(contextAri, {}).query);
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, true);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, true)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns an error', async () => {
const apiClientMock = getApiClientMock({
errors: [INVALID_CURSOR_ERROR]
});
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.listCustomEntities({});
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forErrorCode('CURSOR_INVALID', 'error message'));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
it('should throw an error if the storage API returns a non 200 status code and has no body', async () => {
const apiClientMock = getApiClientMockInvalidJson('', 400);
const metricMocks = getMetricMock();
- const globalStorage = getStorage(apiClientMock, metricMocks.mockMetrics);
+ const globalStorage = getStorage(apiClientMock, passMetrics ? metricMocks.mockMetrics : undefined);
const response = globalStorage.listCustomEntities({});
expect(apiClientMock).toHaveBeenCalled();
await expect(response).rejects.toThrow(errors_1.APIError.forStatus(400));
- checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, false);
+ passMetrics
+ ? checkMetricsFired(metricMocks, { store: 'typed', operation: 'query', encrypted: false }, false)
+ : expect(metricMocks.mockMetrics.counter).not.toHaveBeenCalled();
});
});
});