Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/support/command/handle-response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
32 changes: 32 additions & 0 deletions test/commands/domain/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }))
Expand Down
13 changes: 13 additions & 0 deletions test/commands/domain/delete.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})


Expand Down
32 changes: 32 additions & 0 deletions test/commands/domain/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down