@@ -7,15 +7,15 @@ import fs from 'fs'
77import Swagger from '../src/index'
88
99describe ( 'http' , ( ) => {
10- var server
11- before ( function ( ) {
10+ let server
11+ before ( function ( ) {
1212 server = http . createServer ( function ( req , res ) {
13- var accept = req . headers . accept
14- var contentType
15- var uri = url . parse ( req . url ) . pathname ;
16- var filename = path . join ( 'test' , 'data' , uri ) ;
13+ const accept = req . headers . accept
14+ let contentType
15+ const uri = url . parse ( req . url ) . pathname
16+ const filename = path . join ( 'test' , 'data' , uri )
1717
18- if ( filename . indexOf ( '.yaml' ) > 0 ) {
18+ if ( filename . indexOf ( '.yaml' ) > 0 ) {
1919 contentType = 'application/yaml'
2020 }
2121 else {
@@ -30,66 +30,66 @@ describe('http', () => {
3030 }
3131
3232 if ( accept . indexOf ( 'application/json' ) >= 0 ) {
33- contentType = accept ;
34- res . setHeader ( 'Content-Type' , contentType ) ;
33+ contentType = accept
34+ res . setHeader ( 'Content-Type' , contentType )
3535 }
3636 if ( filename . indexOf ( '.yaml' ) > 0 ) {
37- res . setHeader ( 'Content-Type' , 'application/yaml' ) ;
37+ res . setHeader ( 'Content-Type' , 'application/yaml' )
3838 }
3939 }
4040
4141 fs . exists ( filename , function ( exists ) {
42- if ( exists ) {
43- let fileStream = fs . createReadStream ( filename ) ;
42+ if ( exists ) {
43+ const fileStream = fs . createReadStream ( filename )
4444 res . setHeader ( 'Access-Control-Allow-Origin' , '*' )
4545 res . writeHead ( 200 , contentType )
46- fileStream . pipe ( res ) ;
46+ fileStream . pipe ( res )
4747 }
4848 else {
49- res . writeHead ( 404 , { 'Content-Type' : 'text/plain' } ) ;
50- res . write ( '404 Not Found\n' ) ;
51- res . end ( ) ;
49+ res . writeHead ( 404 , { 'Content-Type' : 'text/plain' } )
50+ res . write ( '404 Not Found\n' )
51+ res . end ( )
5252 }
5353 } )
5454 } ) . listen ( 8000 )
5555 } )
5656
57- after ( function ( ) {
57+ after ( function ( ) {
5858 server . close ( )
5959 } )
6060
6161 afterEach ( function ( ) {
6262 } )
6363
64- it . skip ( 'should get the petstore api and build it' , done => {
64+ it . skip ( 'should get the petstore api and build it' , ( done ) => {
6565 Swagger ( 'http://localhost:8000/petstore.json' )
66- . then ( client => {
66+ . then ( ( client ) => {
6767 expect ( client ) . toExist ( )
6868
6969 // we have 3 tags
7070 expect ( Object . keys ( client . apis ) . length ) . toBe ( 3 )
7171
7272 // the pet tag exists
73- expect ( client . apis [ ' pet' ] ) . toExist ( )
73+ expect ( client . apis . pet ) . toExist ( )
7474
7575 // the get pet operation
76- expect ( client . apis [ ' pet' ] . getPetById ) . toExist ( )
76+ expect ( client . apis . pet . getPetById ) . toExist ( )
7777
7878 done ( )
79- } )
79+ } )
8080 } )
8181
8282 /**
8383 * See https://github.com/swagger-api/swagger-js/issues/1005
8484 */
85- it . skip ( 'should get a pet from the petstore' , done => {
85+ it . skip ( 'should get a pet from the petstore' , ( done ) => {
8686 Swagger ( 'http://localhost:8000/petstore.json' )
87- . then ( client => {
88- client . apis [ ' pet' ] . getPetById ( { petId : - 1 } )
89- . then ( data => {
87+ . then ( ( client ) => {
88+ client . apis . pet . getPetById ( { petId : - 1 } )
89+ . then ( ( data ) => {
9090 done ( 'shoulda thrown an error!' )
9191 } )
92- . catch ( err => {
92+ . catch ( ( err ) => {
9393 done ( )
9494 } )
9595 } )
@@ -98,24 +98,24 @@ describe('http', () => {
9898 /**
9999 * See https://github.com/swagger-api/swagger-js/issues/1002
100100 */
101- it . skip ( 'should return an error when a spec doesnt exist' , done => {
101+ it . skip ( 'should return an error when a spec doesnt exist' , ( done ) => {
102102 Swagger ( 'http://localhost:8000/absent.yaml' )
103- . then ( client => {
103+ . then ( ( client ) => {
104104 done ( 'expected an error' )
105105 } )
106- . catch ( error => {
106+ . catch ( ( error ) => {
107107 done ( )
108108 } )
109109 } )
110110
111111 /**
112112 * See https://github.com/swagger-api/swagger-js/issues/1004
113113 */
114- it . skip ( 'fail with invalid verbs' , done => {
114+ it . skip ( 'fail with invalid verbs' , ( done ) => {
115115 Swagger ( 'http://localhost:8000/invalid-operation.yaml' )
116- . then ( client => {
117- expect ( client . apis [ ' default' ] ) . toExist ( )
118- expect ( client . apis [ ' default' ] [ 'not-a-valid-verb' ] ) . toBeAn ( 'undefined' )
116+ . then ( ( client ) => {
117+ expect ( client . apis . default ) . toExist ( )
118+ expect ( client . apis . default [ 'not-a-valid-verb' ] ) . toBeAn ( 'undefined' )
119119 done ( )
120120 } )
121121 } )
@@ -124,16 +124,16 @@ describe('http', () => {
124124 * Loads a spec where the `host` and `schema` are not defined
125125 * See https://github.com/swagger-api/swagger-js/issues/1000
126126 */
127- it ( 'use the host from whence the spec was fetched' , done => {
127+ it ( 'use the host from whence the spec was fetched' , ( done ) => {
128128 Swagger ( 'http://localhost:8000/pathless.yaml' )
129- . then ( client => {
130- client . apis [ ' default' ] . tryMe ( ) . then ( data => {
131- expect ( data . status ) . toBe ( 404 )
129+ . then ( ( client ) => {
130+ client . apis . default . tryMe ( ) . catch ( ( err ) => {
131+ expect ( err . status ) . toBe ( 404 )
132132 done ( )
133133 } )
134134 } )
135- . catch ( err => {
135+ . catch ( ( err ) => {
136136 done ( err )
137137 } )
138138 } )
139- } )
139+ } )
0 commit comments