Skip to content

Commit

Permalink
test: adding coverage for PUT endpoint error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta committed Jun 23, 2022
1 parent 7836b05 commit 3970905
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion __tests__/cmds/openapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")',
Expand Down Expand Up @@ -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 [email protected] 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',
Expand Down

0 comments on commit 3970905

Please sign in to comment.