@@ -277,7 +277,7 @@ describe('curl convert function', function () {
277277 expect . fail ( null , null , error ) ;
278278 }
279279 expect ( snippet ) . to . be . a ( 'string' ) ;
280- expect ( snippet ) . to . include ( "GET 'https://google.com'" ) ; // eslint-disable-line quotes
280+ expect ( snippet ) . to . include ( "'https://google.com'" ) ; // eslint-disable-line quotes
281281 } ) ;
282282 } ) ;
283283
@@ -635,5 +635,179 @@ describe('curl convert function', function () {
635635 expect ( outputUrlString ) . to . equal ( rawUrl ) ;
636636 } ) ;
637637 } ) ;
638+
639+ it ( 'should not add --request parameter in POST request if body is present' , function ( ) {
640+ var request = new sdk . Request ( {
641+ 'method' : 'POST' ,
642+ 'header' : [ ] ,
643+ 'body' : {
644+ 'mode' : 'graphql' ,
645+ 'graphql' : {
646+ 'query' : '{\n findScenes(\n filter: {per_page: 0}\n scene_filter: {is_missing: "performers"}){\n count\n scenes {\n id\n title\n path\n }\n }\n}' , // eslint-disable-line
647+ 'variables' : '{\n\t"variable_key": "variable_value"\n}'
648+ }
649+ } ,
650+ 'url' : {
651+ 'raw' : 'https://postman-echo.com/post' ,
652+ 'protocol' : 'https' ,
653+ 'host' : [
654+ 'postman-echo' ,
655+ 'com'
656+ ] ,
657+ 'path' : [
658+ 'post'
659+ ]
660+ }
661+ } ) ;
662+
663+ convert ( request , { followRedirect : true } , function ( error , snippet ) {
664+ if ( error ) {
665+ expect . fail ( null , null , error ) ;
666+ }
667+ expect ( snippet ) . to . be . a ( 'string' ) ;
668+ expect ( snippet ) . to . not . include ( '--request POST' ) ;
669+ } ) ;
670+ } ) ;
671+
672+ it ( 'should add --request parameter in POST request if body is not present' , function ( ) {
673+ var request = new sdk . Request ( {
674+ 'method' : 'POST' ,
675+ 'header' : [ ] ,
676+ 'url' : {
677+ 'raw' : 'https://postman-echo.com/post' ,
678+ 'protocol' : 'https' ,
679+ 'host' : [
680+ 'postman-echo' ,
681+ 'com'
682+ ] ,
683+ 'path' : [
684+ 'post'
685+ ]
686+ }
687+ } ) ;
688+
689+ convert ( request , { followRedirect : true } , function ( error , snippet ) {
690+ if ( error ) {
691+ expect . fail ( null , null , error ) ;
692+ }
693+ expect ( snippet ) . to . be . a ( 'string' ) ;
694+ expect ( snippet ) . to . include ( '--request POST' ) ;
695+ } ) ;
696+ } ) ;
697+
698+ it ( 'should add --request parameter in GET request if body is present' , function ( ) {
699+ var request = new sdk . Request ( {
700+ 'method' : 'GET' ,
701+ 'header' : [ ] ,
702+ 'body' : {
703+ 'mode' : 'graphql' ,
704+ 'graphql' : {
705+ 'query' : '{\n findScenes(\n filter: {per_page: 0}\n scene_filter: {is_missing: "performers"}){\n count\n scenes {\n id\n title\n path\n }\n }\n}' , // eslint-disable-line
706+ 'variables' : '{\n\t"variable_key": "variable_value"\n}'
707+ }
708+ } ,
709+ 'url' : {
710+ 'raw' : 'https://postman-echo.com/get' ,
711+ 'protocol' : 'https' ,
712+ 'host' : [
713+ 'postman-echo' ,
714+ 'com'
715+ ] ,
716+ 'path' : [
717+ 'get'
718+ ]
719+ }
720+ } ) ;
721+
722+ convert ( request , { followRedirect : true } , function ( error , snippet ) {
723+ if ( error ) {
724+ expect . fail ( null , null , error ) ;
725+ }
726+ expect ( snippet ) . to . be . a ( 'string' ) ;
727+ expect ( snippet ) . to . include ( '--request GET' ) ;
728+ } ) ;
729+ } ) ;
730+
731+ it ( 'should not add --request parameter in GET request if body is present ' +
732+ 'but disableBodyPruning is false' , function ( ) {
733+ const request = new sdk . Request ( {
734+ 'method' : 'GET' ,
735+ 'header' : [ ] ,
736+ 'body' : {
737+ 'mode' : 'graphql' ,
738+ 'graphql' : {
739+ 'query' : '{\n findScenes(\n filter: {per_page: 0}\n scene_filter: {is_missing: "performers"}){\n count\n scenes {\n id\n title\n path\n }\n }\n}' , // eslint-disable-line
740+ 'variables' : '{\n\t"variable_key": "variable_value"\n}'
741+ }
742+ } ,
743+ 'url' : {
744+ 'raw' : 'https://postman-echo.com/get' ,
745+ 'protocol' : 'https' ,
746+ 'host' : [
747+ 'postman-echo' ,
748+ 'com'
749+ ] ,
750+ 'path' : [
751+ 'get'
752+ ]
753+ }
754+ } ) ;
755+
756+ // this needs to be done here because protocolProfileBehavior is not in collections SDK
757+ request . protocolProfileBehavior = {
758+ disableBodyPruning : false
759+ } ;
760+
761+ convert ( request , { followRedirect : true } , function ( error , snippet ) {
762+ if ( error ) {
763+ expect . fail ( null , null , error ) ;
764+ }
765+ expect ( snippet ) . to . be . a ( 'string' ) ;
766+ expect ( snippet ) . to . not . include ( '--request GET' ) ;
767+ } ) ;
768+ } ) ;
769+
770+ it ( 'should add --request parameter when options ' +
771+ 'followRedirect and followOriginalHttpMethod are true' , function ( ) {
772+ const methods = [ 'GET' , 'HEAD' , 'DELETE' , 'PUT' , 'POST' , 'PATCH' ] ,
773+ request = new sdk . Request ( {
774+ 'method' : 'POST' ,
775+ 'header' : [ ] ,
776+ 'body' : {
777+ 'mode' : 'graphql' ,
778+ 'graphql' : {
779+ 'query' : '{\n findScenes(\n filter: {per_page: 0}\n scene_filter: {is_missing: "performers"}){\n count\n scenes {\n id\n title\n path\n }\n }\n}' , // eslint-disable-line
780+ 'variables' : '{\n\t"variable_key": "variable_value"\n}'
781+ }
782+ } ,
783+ 'url' : {
784+ 'raw' : 'https://postman-echo.com/post' ,
785+ 'protocol' : 'https' ,
786+ 'host' : [
787+ 'postman-echo' ,
788+ 'com'
789+ ] ,
790+ 'path' : [
791+ 'post'
792+ ]
793+ }
794+ } ) ;
795+
796+ // this needs to be done here because protocolProfileBehavior is not in collections SDK
797+ request . protocolProfileBehavior = {
798+ followOriginalHttpMethod : true
799+ } ;
800+
801+ for ( let method of methods ) {
802+ request . method = method ;
803+ convert ( request , { followRedirect : true } , function ( error , snippet ) {
804+ if ( error ) {
805+ expect . fail ( null , null , error ) ;
806+ }
807+ expect ( snippet ) . to . be . a ( 'string' ) ;
808+ expect ( snippet ) . to . include ( `--request ${ method } ` ) ;
809+ } ) ;
810+ }
811+ } ) ;
638812 } ) ;
639813} ) ;
0 commit comments