@forge/kvs
1.5.1-next.01.6.0-next.1
out/__test__/index.test.js~
out/__test__/index.test.jsModified+70−15
Index: package/out/__test__/index.test.js
===================================================================
--- package/out/__test__/index.test.js
+++ package/out/__test__/index.test.js
@@ -101,27 +101,43 @@
body: JSON.stringify({ key: 'foo' })
}));
});
it('should handle unexpected metadata fields', async () => {
- const response = new Response(JSON.stringify({
+ const body = JSON.stringify({
code: 'BAD_REQUEST',
message: 'Provided request body is invalid'
- }), {
+ });
+ const response = new Response(body, {
status: 400,
statusText: 'Bad Request',
headers: { 'x-trace-id': traceId }
});
const { sut } = prepare(response);
- await expect(sut.get('foo', { metadataFields: ['INVALID_METADATA_FIELD'] })).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 400, statusText: 'Bad Request', traceId }, { code: 'BAD_REQUEST', message: 'Provided request body is invalid' }));
+ await expect(sut.get('foo', { metadataFields: ['INVALID_METADATA_FIELD'] })).rejects.toMatchError(new errors_1.ForgeKvsAPIError({
+ status: 400,
+ statusText: 'Bad Request',
+ traceId,
+ httpMethod: 'POST',
+ httpPath: '/api/v1/get',
+ responseBodyLength: body.length
+ }, { code: 'BAD_REQUEST', message: 'Provided request body is invalid' }));
});
it('should handle unexpected response', async () => {
- const response = new Response(JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }), {
+ const body = JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' });
+ const response = new Response(body, {
status: 500,
statusText: 'Internal Server Error',
headers: { 'x-trace-id': traceId }
});
const { sut } = prepare(response);
- await expect(sut.get('foo')).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 500, statusText: 'Internal Server Error', traceId }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
+ await expect(sut.get('foo')).rejects.toMatchError(new errors_1.ForgeKvsAPIError({
+ status: 500,
+ statusText: 'Internal Server Error',
+ traceId,
+ httpMethod: 'POST',
+ httpPath: '/api/v1/get',
+ responseBodyLength: body.length
+ }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
});
it('should handle non-json response even though status is ok', async () => {
const responseText = 'Text that will fail to parse';
const response = new Response(responseText, {
@@ -129,9 +145,16 @@
statusText: 'OK',
headers: { 'x-trace-id': traceId, 'content-length': responseText.length.toString() }
});
const { sut } = prepare(response);
- await expect(sut.get('foo')).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 200, statusText: 'OK', traceId }, {
+ await expect(sut.get('foo')).rejects.toMatchError(new errors_1.ForgeKvsAPIError({
+ status: 200,
+ statusText: 'OK',
+ traceId,
+ httpMethod: 'POST',
+ httpPath: '/api/v1/get',
+ responseBodyLength: responseText.length
+ }, {
code: 'UNKNOWN_ERROR',
message: 'Unexpected error in Forge KVS API. Response was not valid JSON',
context: { contentLength: responseText.length.toString() }
}));
@@ -1177,16 +1200,24 @@
body: JSON.stringify(items)
}));
});
it('should handle batchSet API error response', async () => {
- const response = new Response(JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }), {
+ const body = JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' });
+ const response = new Response(body, {
status: 500,
statusText: 'Internal Server Error',
headers: { 'x-trace-id': traceId }
});
const { sut } = prepare(response);
const items = [{ key: 'foo', value: 'bar' }];
- await expect(sut.batchSet(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 500, statusText: 'Internal Server Error', traceId }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
+ await expect(sut.batchSet(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({
+ status: 500,
+ statusText: 'Internal Server Error',
+ traceId,
+ httpMethod: 'POST',
+ httpPath: '/api/v1/batch/set',
+ responseBodyLength: body.length
+ }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
});
it('should handle batchDelete correctly with mixed entity and non-entity items', async () => {
const response = new Response(JSON.stringify({
successfulKeys: [{ key: 'foo', entityName: 'employees' }, { key: 'bar' }],
@@ -1276,16 +1307,24 @@
body: JSON.stringify(items)
}));
});
it('should handle batchDelete API error response', async () => {
- const response = new Response(JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }), {
+ const body = JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' });
+ const response = new Response(body, {
status: 500,
statusText: 'Internal Server Error',
headers: { 'x-trace-id': traceId }
});
const { sut } = prepare(response);
const items = [{ key: 'foo' }];
- await expect(sut.batchDelete(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 500, statusText: 'Internal Server Error', traceId }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
+ await expect(sut.batchDelete(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({
+ status: 500,
+ statusText: 'Internal Server Error',
+ traceId,
+ httpMethod: 'POST',
+ httpPath: '/api/v1/batch/delete',
+ responseBodyLength: body.length
+ }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
});
it('should handle batchGet with mixed entity and non-entity items', async () => {
const response = new Response(JSON.stringify({
successfulKeys: [
@@ -1450,22 +1489,31 @@
body: JSON.stringify(items)
}));
});
it('should handle batchGet API error response', async () => {
- const response = new Response(JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }), {
+ const body = JSON.stringify({ code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' });
+ const response = new Response(body, {
status: 500,
statusText: 'Internal Server Error',
headers: { 'x-trace-id': traceId }
});
const { sut } = prepare(response);
const items = [{ key: 'foo' }];
- await expect(sut.batchGet(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 500, statusText: 'Internal Server Error', traceId }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
+ await expect(sut.batchGet(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({
+ status: 500,
+ statusText: 'Internal Server Error',
+ traceId,
+ httpMethod: 'POST',
+ httpPath: '/api/v1/batch/get',
+ responseBodyLength: body.length
+ }, { code: 'INTERNAL_SERVER_ERROR', message: 'An internal server error has occurred' }));
});
it('should handle batchGet with invalid metadata fields', async () => {
- const response = new Response(JSON.stringify({
+ const body = JSON.stringify({
code: 'BAD_REQUEST',
message: 'Provided request body is invalid'
- }), {
+ });
+ const response = new Response(body, {
status: 400,
statusText: 'Bad Request',
headers: { 'x-trace-id': traceId }
});
@@ -1475,7 +1523,14 @@
key: 'foo',
options: { metadataFields: ['INVALID_METADATA_FIELD'] }
}
];
- await expect(sut.batchGet(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({ status: 400, statusText: 'Bad Request', traceId }, { code: 'BAD_REQUEST', message: 'Provided request body is invalid' }));
+ await expect(sut.batchGet(items)).rejects.toMatchError(new errors_1.ForgeKvsAPIError({
+ status: 400,
+ statusText: 'Bad Request',
+ traceId,
+ httpMethod: 'POST',
+ httpPath: '/api/v1/batch/get',
+ responseBodyLength: body.length
+ }, { code: 'BAD_REQUEST', message: 'Provided request body is invalid' }));
});
});