npm package diff
Package: @forge/storage
Versions: 1.6.0-next.0 - 1.6.0-next.1
Modified:package/out/global-storage.js
Index: package/out/global-storage.js
===================================================================
--- package/out/global-storage.js
+++ package/out/global-storage.js
@@ -128,8 +128,11 @@
return response;
}
async wrapInMetric(store, operation, encrypted, fn) {
const metrics = this.getMetrics();
+ if (!metrics) {
+ return await fn();
+ }
const timer = metrics
.timing('forge.runtime.storage.operation.latency', { store, operation, encrypted: String(encrypted) })
.measure();
try {
Modified: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();
});
});
});
Modified:package/package.json
Index: package/package.json
===================================================================
--- package/package.json
+++ package/package.json
@@ -1,7 +1,7 @@
{
"name": "@forge/storage",
- "version": "1.6.0-next.0",
+ "version": "1.6.0-next.1",
"description": "Forge Storage methods",
"author": "Atlassian",
"license": "UNLICENSED",
"main": "out/index.js",
Modified:package/out/global-storage.d.ts.map
Index: package/out/global-storage.d.ts.map
===================================================================
--- package/out/global-storage.d.ts.map
+++ package/out/global-storage.d.ts.map
@@ -1,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;IAG5C,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;IA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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"}
\ No newline at end of file
Modified:package/out/global-storage.d.ts
Index: package/out/global-storage.d.ts
===================================================================
--- package/out/global-storage.d.ts
+++ package/out/global-storage.d.ts
@@ -15,9 +15,9 @@
private getAppContextAri;
private apiClient;
private readonly getMetrics;
private readonly endpoint;
- constructor(getAppContextAri: (() => string) | string, apiClient: FetchMethod, getMetrics: () => Metrics);
+ constructor(getAppContextAri: (() => string) | string, apiClient: FetchMethod, getMetrics: () => Metrics | undefined);
private doGetAppContextAri;
get(key: string): Promise<any>;
getSecret(key: string): Promise<any>;
list(options: ListOptions): Promise<ListResults>;