1
1
const nock = require ( 'nock' ) ;
2
2
const config = require ( 'config' ) ;
3
- const assert = require ( 'assert' ) ;
4
3
5
4
const swagger = require ( '../cli' ) . bind ( null , 'swagger' ) ;
6
5
@@ -11,14 +10,26 @@ describe('swagger command', () => {
11
10
afterAll ( ( ) => nock . cleanAll ( ) ) ;
12
11
13
12
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
+ ) ) ;
17
16
18
17
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
+ } ) ;
22
33
23
34
it ( 'should POST to the swagger api if no id provided' , ( ) => {
24
35
const mock = nock ( config . host )
0 commit comments