diff --git a/src/support/command/handle-response.js b/src/support/command/handle-response.js index a29e686e..9d9caae8 100644 --- a/src/support/command/handle-response.js +++ b/src/support/command/handle-response.js @@ -27,7 +27,7 @@ const checkForErrors = ({ resolveStatus = [] } = {}) => response => { } const filterResponseMessaging = response => { - if (response.status === 403) { + if (response.status === 401 || response.status === 403) { return Promise.reject(response) } diff --git a/test/commands/domain/create.test.js b/test/commands/domain/create.test.js index 883e5ee2..0f2c6af9 100644 --- a/test/commands/domain/create.test.js +++ b/test/commands/domain/create.test.js @@ -115,6 +115,38 @@ describe('invalid domain:create', () => { expect(ctx.message).to.equal('You have reached the limit of domains') }) .it('runs domain:create with org that doesn\'t exist') + + test + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}/domains`, domain => domain + .get('/org/domain') + .reply(404) + ) + .nock(`${shubUrl}/domains`, domain => domain + .post('/org/domain?version=1.0.0&isPrivate=true') + .reply(401, '{"code":401,"message":"Invalid API key"}') + ) + .command(['domain:create', `${validIdentifier}`, '--file=test/resources/valid_domain.json']) + .catch(ctx => { + expect(ctx.message).to.equal('Invalid API key') + }) + .it('runs domain:create with invalid API key returns 401') + + test + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}/domains`, domain => domain + .get('/org/domain') + .reply(404) + ) + .nock(`${shubUrl}/domains`, domain => domain + .post('/org/domain?version=1.0.0&isPrivate=true') + .reply(415, '{"code":415,"message":"Unsupported Media Type"}') + ) + .command(['domain:create', `${validIdentifier}`, '--file=test/resources/valid_domain.json']) + .catch(ctx => { + expect(ctx.message).to.equal('Unsupported Media Type') + }) + .it('runs domain:create with unsupported content type returns 415') test .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) diff --git a/test/commands/domain/delete.test.js b/test/commands/domain/delete.test.js index 8f703495..4e6be7e3 100644 --- a/test/commands/domain/delete.test.js +++ b/test/commands/domain/delete.test.js @@ -73,6 +73,19 @@ describe('domain:delete error responses', () => { expect(ctx.message).to.contain(`Unknown domain ${domainId}`) }) .it('runs domain:delete with domain that does not exist') + + test + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}/domains`, domain => domain + .delete('/org/domain/1.0.0') + .query({ force: 'true' }) + .reply(401, '{"code":401,"message":"Invalid API key"}') + ) + .command(['domain:delete', versionId]) + .catch(ctx => { + expect(ctx.message).to.contain('Invalid API key') + }) + .it('runs domain:delete with invalid API key returns 401') }) diff --git a/test/commands/domain/update.test.js b/test/commands/domain/update.test.js index 745ba431..012e6dda 100644 --- a/test/commands/domain/update.test.js +++ b/test/commands/domain/update.test.js @@ -103,6 +103,38 @@ describe('invalid domain:update', () => { .exit(2) .it('runs domain:update with error on updating domain') + test + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}/domains`, domain => domain + .get('/org/domain/1.0.0') + .reply(200) + ) + .nock(`${shubUrl}/domains`, domain => domain + .post('/org/domain?version=1.0.0') + .reply(401, '{"code":401,"message":"Invalid API key"}') + ) + .command(['domain:update', `${validIdentifier}`, '--file=test/resources/valid_domain.json']) + .catch(ctx => { + expect(ctx.message).to.equal('Invalid API key') + }) + .it('runs domain:update with invalid API key returns 401') + + test + .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) + .nock(`${shubUrl}/domains`, domain => domain + .get('/org/domain/1.0.0') + .reply(200) + ) + .nock(`${shubUrl}/domains`, domain => domain + .post('/org/domain?version=1.0.0') + .reply(415, '{"code":415,"message":"Unsupported Media Type"}') + ) + .command(['domain:update', `${validIdentifier}`, '--file=test/resources/valid_domain.json']) + .catch(ctx => { + expect(ctx.message).to.equal('Unsupported Media Type') + }) + .it('runs domain:update with unsupported content type returns 415') + test .stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: shubUrl })) .nock(`${shubUrl}/domains`, domain => domain