File tree Expand file tree Collapse file tree 1 file changed +63
-1
lines changed Expand file tree Collapse file tree 1 file changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -515,7 +515,6 @@ describe('SwaggerClient', function () {
515515 } ) ;
516516 } ) ;
517517
518-
519518 it ( 'passes headers to the request interceptor' , function ( done ) {
520519 var spec = {
521520 paths : {
@@ -583,4 +582,67 @@ describe('SwaggerClient', function () {
583582 done ( exception ) ;
584583 } ) ;
585584 } ) ;
585+
586+ it ( 'uses a custom http client implementation' , function ( done ) {
587+
588+ var spec = {
589+ paths : {
590+ '/foo' : {
591+ post : {
592+ operationId : 'addFoo' ,
593+ tags : [
594+ 'nada'
595+ ] ,
596+ parameters : [
597+ {
598+ in : 'header' ,
599+ name : 'username' ,
600+ type : 'string'
601+ }
602+ ] ,
603+ responses : {
604+ '200' : {
605+ description : 'ok'
606+ }
607+ }
608+ }
609+ }
610+ }
611+ } ;
612+ var myHttpClient = {
613+ execute : function ( requestObj ) {
614+ /**
615+ * Do your magic here. When done, you should call the responseObj callback if successful
616+ * For this mock client, just make it act async
617+ */
618+
619+ setTimeout ( function ( ) {
620+ requestObj . on . response ( {
621+ obj : {
622+ // payload
623+ content : 'it works!'
624+ } ,
625+ status : 200 ,
626+ statusText : 'it works!'
627+ } ) ;
628+ // and if something goes wrong call requestObj.on.error and pass the payload
629+ } , 1000 )
630+ }
631+ }
632+
633+ new SwaggerClient ( {
634+ url : 'http://localhost:8000/v2/swagger.json' ,
635+ spec : spec ,
636+ usePromise : true ,
637+ client : myHttpClient
638+ } ) . then ( function ( client ) {
639+ client . nada . addFoo ( { username : 'bob' } ) . then ( function ( data ) {
640+ expect ( data . obj ) . toBeAn ( 'object' ) ;
641+ expect ( data . status ) . toBe ( 200 ) ;
642+ done ( ) ;
643+ } ) ;
644+ } ) . catch ( function ( exception ) {
645+ done ( exception ) ;
646+ } ) ;
647+ } ) ;
586648} ) ;
You can’t perform that action at this time.
0 commit comments