@@ -83,20 +83,59 @@ describe('nodejs-axios convert function', function () {
8383 } ) ;
8484 } ) ;
8585
86- it ( 'should return snippet with maxRedirects property set to ' +
87- '0 for no follow redirect' , function ( ) {
88- request = new sdk . Request ( mainCollection . item [ 0 ] . request ) ;
89- options = {
90- followRedirect : false
91- } ;
92- convert ( request , options , function ( error , snippet ) {
93- if ( error ) {
94- expect . fail ( null , null , error ) ;
95- return ;
96- }
86+ describe ( ' maxRedirects property' , function ( ) {
87+ it ( 'should return snippet with maxRedirects property set to ' +
88+ '0 for no follow redirect' , function ( ) {
89+ const request = new sdk . Request ( mainCollection . item [ 0 ] . request ) ;
90+ options = {
91+ followRedirect : false
92+ } ;
93+ convert ( request , options , function ( error , snippet ) {
94+ if ( error ) {
95+ expect . fail ( null , null , error ) ;
96+ }
9797
98- expect ( snippet ) . to . be . a ( 'string' ) ;
99- expect ( snippet ) . to . include ( 'maxRedirects: 0' ) ;
98+ expect ( snippet ) . to . be . a ( 'string' ) ;
99+ expect ( snippet ) . to . include ( 'maxRedirects: 0' ) ;
100+ } ) ;
101+ } ) ;
102+
103+ it ( 'should return snippet with maxRedirects property set to ' +
104+ '0 for no follow redirect from request settings' , function ( ) {
105+ const request = new sdk . Request ( mainCollection . item [ 0 ] . request ) ,
106+ options = { } ;
107+
108+ request . protocolProfileBehavior = {
109+ followRedirects : false
110+ } ;
111+
112+ convert ( request , options , function ( error , snippet ) {
113+ if ( error ) {
114+ expect . fail ( null , null , error ) ;
115+ }
116+
117+ expect ( snippet ) . to . be . a ( 'string' ) ;
118+ expect ( snippet ) . to . include ( 'maxRedirects: 0' ) ;
119+ } ) ;
120+ } ) ;
121+
122+ it ( 'should return snippet with no maxRedirects property when ' +
123+ 'follow redirect is true from request settings' , function ( ) {
124+ const request = new sdk . Request ( mainCollection . item [ 0 ] . request ) ,
125+ options = { } ;
126+
127+ request . protocolProfileBehavior = {
128+ followRedirects : true
129+ } ;
130+
131+ convert ( request , options , function ( error , snippet ) {
132+ if ( error ) {
133+ expect . fail ( null , null , error ) ;
134+ }
135+
136+ expect ( snippet ) . to . be . a ( 'string' ) ;
137+ expect ( snippet ) . to . not . include ( 'maxRedirects' ) ;
138+ } ) ;
100139 } ) ;
101140 } ) ;
102141
@@ -438,6 +477,35 @@ describe('nodejs-axios convert function', function () {
438477 } ) ;
439478 } ) ;
440479
480+ it ( 'should return snippet with promise based code when async_await is disabled' , function ( ) {
481+ const request = new sdk . Request ( mainCollection . item [ 0 ] . request ) ;
482+
483+ convert ( request , { } , function ( error , snippet ) {
484+ if ( error ) {
485+ expect . fail ( null , null , error ) ;
486+ }
487+ expect ( snippet ) . to . be . a ( 'string' ) ;
488+ expect ( snippet ) . to . include ( 'axios.request(config)' ) ;
489+ expect ( snippet ) . to . include ( '.then((response) => {' ) ;
490+ expect ( snippet ) . to . include ( '.catch((error) => {' ) ;
491+ } ) ;
492+ } ) ;
493+
494+ it ( 'should return snippet with async/await based code when option is enabled' , function ( ) {
495+ const request = new sdk . Request ( mainCollection . item [ 0 ] . request ) ;
496+
497+ convert ( request , { asyncAwaitEnabled : true } , function ( error , snippet ) {
498+ if ( error ) {
499+ expect . fail ( null , null , error ) ;
500+ }
501+ expect ( snippet ) . to . be . a ( 'string' ) ;
502+ expect ( snippet ) . to . include ( 'async function makeRequest() {' ) ;
503+ expect ( snippet ) . to . include ( 'const response = await axios.request(config);' ) ;
504+ expect ( snippet ) . to . include ( 'catch (error) {' ) ;
505+ expect ( snippet ) . to . include ( 'makeRequest();' ) ;
506+ } ) ;
507+ } ) ;
508+
441509 describe ( 'getOptions function' , function ( ) {
442510
443511 it ( 'should return an array of specific options' , function ( ) {
@@ -450,7 +518,7 @@ describe('nodejs-axios convert function', function () {
450518 expect ( getOptions ( ) [ 2 ] ) . to . have . property ( 'id' , 'requestTimeout' ) ;
451519 expect ( getOptions ( ) [ 3 ] ) . to . have . property ( 'id' , 'followRedirect' ) ;
452520 expect ( getOptions ( ) [ 4 ] ) . to . have . property ( 'id' , 'trimRequestBody' ) ;
453- // expect(getOptions()[5]).to.have.property('id', 'AsyncAwait_enabled ');
521+ expect ( getOptions ( ) [ 5 ] ) . to . have . property ( 'id' , 'asyncAwaitEnabled ' ) ;
454522 } ) ;
455523 } ) ;
456524
0 commit comments