Skip to content

Commit f410c7c

Browse files
committed
Return with proper exit code on unsuccessful swagger upload
Fixes #11
1 parent 3afc5f4 commit f410c7c

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

lib/swagger.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ exports.run = function({ args, opts }) {
3434

3535
function error(err) {
3636
console.log(err.error);
37-
console.error('There was an error uploading!'.red);
37+
return Promise.reject(new Error('There was an error uploading!'));
3838
}
3939

4040
const options = {

test/swagger.test.js

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const nock = require('nock');
22
const config = require('config');
3-
const assert = require('assert');
43

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

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

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

1817
it('should error if no file provided', () =>
19-
swagger([], { key }).catch(err => {
20-
assert.equal(err.message, 'No swagger file provided. Usage `rdme swagger <swagger-file>`');
21-
}));
18+
expect(swagger([], { key })).rejects.toThrow(
19+
'No swagger file provided. Usage `rdme swagger <swagger-file>`',
20+
));
21+
22+
it('should error if API errors', async () => {
23+
const mock = nock(config.host)
24+
.post('/api/v1/swagger', body => body.match('form-data; name="swagger"'))
25+
.basicAuth({ user: key })
26+
.reply(400);
27+
28+
await expect(swagger(['./test/fixtures/swagger.json'], { key })).rejects.toThrow(
29+
'There was an error uploading!',
30+
);
31+
mock.done();
32+
});
2233

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

0 commit comments

Comments
 (0)