From 39709056691223e9f0dec532590e15595acc8931 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Wed, 22 Jun 2022 18:40:53 -0700 Subject: [PATCH] test: adding coverage for PUT endpoint error handling --- __tests__/cmds/openapi.test.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/__tests__/cmds/openapi.test.js b/__tests__/cmds/openapi.test.js index ef6e600ae..3b4dd81e3 100644 --- a/__tests__/cmds/openapi.test.js +++ b/__tests__/cmds/openapi.test.js @@ -387,7 +387,7 @@ describe('rdme openapi', () => { ).rejects.toMatchSnapshot(); }); - it('should throw an error if an invalid Swagger definition is supplied', async () => { + it('should throw an error if an invalid Swagger definition is supplied (create)', async () => { const errorObject = { error: 'INTERNAL_ERROR', message: 'Unknown error (README VALIDATION ERROR "x-samples-languages" must be of type "Array")', @@ -422,6 +422,36 @@ describe('rdme openapi', () => { return mock.done(); }); + it('should throw an error if an invalid Swagger definition is supplied (update)', async () => { + const errorObject = { + error: 'INTERNAL_ERROR', + message: 'Unknown error (README VALIDATION ERROR "x-samples-languages" must be of type "Array")', + suggestion: '...a suggestion to resolve the issue...', + help: 'If you need help, email support@readme.io and mention log "fake-metrics-uuid".', + }; + + const registryUUID = getRandomRegistryId(); + + const mock = getApiNock() + .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .put(`/api/v1/api-specification/${id}`, { registryUUID }) + .delayConnection(1000) + .basicAuth({ user: key }) + .reply(400, errorObject); + + await expect( + openapi.run({ + spec: './__tests__/__fixtures__/swagger-with-invalid-extensions.json', + id, + key, + version, + }) + ).rejects.toStrictEqual(new APIError(errorObject)); + + return mock.done(); + }); + it('should throw an error if registry upload fails', async () => { const errorObject = { error: 'INTERNAL_ERROR',