Skip to content

Commit

Permalink
Return with proper exit code on unsuccessful swagger upload
Browse files Browse the repository at this point in the history
Fixes #11
  • Loading branch information
domharrington committed Feb 15, 2019
1 parent 3afc5f4 commit f410c7c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ exports.run = function({ args, opts }) {

function error(err) {
console.log(err.error);
console.error('There was an error uploading!'.red);
return Promise.reject(new Error('There was an error uploading!'));
}

const options = {
Expand Down
25 changes: 18 additions & 7 deletions test/swagger.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const nock = require('nock');
const config = require('config');
const assert = require('assert');

const swagger = require('../cli').bind(null, 'swagger');

Expand All @@ -11,14 +10,26 @@ describe('swagger command', () => {
afterAll(() => nock.cleanAll());

it('should error if no api key provided', () =>
swagger(['./test/fixtures/swagger.json'], {}).catch(err => {
assert.equal(err.message, 'No api key provided. Please use --key');
}));
expect(swagger(['./test/fixtures/swagger.json'], {})).rejects.toThrow(
'No api key provided. Please use --key',
));

it('should error if no file provided', () =>
swagger([], { key }).catch(err => {
assert.equal(err.message, 'No swagger file provided. Usage `rdme swagger <swagger-file>`');
}));
expect(swagger([], { key })).rejects.toThrow(
'No swagger file provided. Usage `rdme swagger <swagger-file>`',
));

it('should error if API errors', async () => {
const mock = nock(config.host)
.post('/api/v1/swagger', body => body.match('form-data; name="swagger"'))
.basicAuth({ user: key })
.reply(400);

await expect(swagger(['./test/fixtures/swagger.json'], { key })).rejects.toThrow(
'There was an error uploading!',
);
mock.done();
});

it('should POST to the swagger api if no id provided', () => {
const mock = nock(config.host)
Expand Down

0 comments on commit f410c7c

Please sign in to comment.