From bf6199910d8c4fd921a82f1c409922c4a52fea2f Mon Sep 17 00:00:00 2001 From: vatsal Date: Mon, 30 Sep 2024 18:58:54 -0700 Subject: [PATCH] Add 404 spec for delete index, get document, delete document APIs Signed-off-by: Vatsal --- tools/src/tester/ChapterReader.ts | 2 +- tools/tests/tester/ChapterReader.test.ts | 29 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/src/tester/ChapterReader.ts b/tools/src/tester/ChapterReader.ts index 26dd02753..f85e6fdc6 100644 --- a/tools/src/tester/ChapterReader.ts +++ b/tools/src/tester/ChapterReader.ts @@ -62,7 +62,7 @@ export default class ChapterReader { response.status = e.response.status response.content_type = e.response.headers['content-type']?.split(';')[0] const payload = this.#deserialize_payload(e.response.data, response.content_type) - if (payload !== undefined) response.payload = payload.error + if (payload !== undefined) response.payload = payload.error ?? payload response.message = payload.error?.reason ?? e.response.statusText this.logger.info(`<= ${response.status} (${response.content_type}) | ${response.payload !== undefined ? to_json(response.payload) : response.message}`) } diff --git a/tools/tests/tester/ChapterReader.test.ts b/tools/tests/tester/ChapterReader.test.ts index 7e1776bb2..0a385d12b 100644 --- a/tools/tests/tester/ChapterReader.test.ts +++ b/tools/tests/tester/ChapterReader.test.ts @@ -219,6 +219,35 @@ describe('ChapterReader', () => { }] ]) }) + + it('sets payload to entire response when payload.error is missing', async () => { + const mockPayload = { '_data': '1', 'result': 'updated' }; + const mockError = { + response: { + status: 404, + headers: { + 'content-type': 'application/json' + }, + data: JSON.stringify(mockPayload), + statusText: 'Not Found' + } + }; + + mocked_axios.request.mockRejectedValue(mockError); + + const result = await reader.read({ + id: 'id', + path: 'path', + method: 'POST' + }, new StoryOutputs()); + + expect(result).toStrictEqual({ + status: 404, + content_type: 'application/json', + payload: mockPayload, + message: 'Not Found' + }); + }); }) describe('deserialize_payload', () => {