Skip to content

Commit

Permalink
Add 404 spec for delete index, get document, delete document APIs
Browse files Browse the repository at this point in the history
Signed-off-by: Vatsal <[email protected]>
  • Loading branch information
imvtsl committed Oct 1, 2024
1 parent 9798e59 commit bf61999
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tools/src/tester/ChapterReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`)
}
Expand Down
29 changes: 29 additions & 0 deletions tools/tests/tester/ChapterReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit bf61999

Please sign in to comment.