@@ -16,8 +16,11 @@ describe('Rust reqwest converter', function () {
1616 'raw' : 'http://postman-echo.com/get' ,
1717 'protocol' : 'http' ,
1818 'host' : [
19- 'google ' ,
19+ 'postman-echo ' ,
2020 'com'
21+ ] ,
22+ 'path' : [
23+ 'get'
2124 ]
2225 }
2326 } ) ,
@@ -39,8 +42,11 @@ describe('Rust reqwest converter', function () {
3942 'raw' : 'http://postman-echo.com/get' ,
4043 'protocol' : 'http' ,
4144 'host' : [
42- 'google ' ,
45+ 'postman-echo ' ,
4346 'com'
47+ ] ,
48+ 'path' : [
49+ 'get'
4450 ]
4551 }
4652 } ) ,
@@ -54,4 +60,61 @@ describe('Rust reqwest converter', function () {
5460 } ) ;
5561 } ) ;
5662
63+ it ( 'should use the method name directly if it is part of allowed methods' , function ( ) {
64+ [ 'GET' , 'POST' , 'PUT' , 'DELETE' , 'HEAD' , 'OPTIONS' , 'CONNECT' , 'PATH' , 'TRACE' ] . forEach ( function ( method ) {
65+ const request = new sdk . Request ( {
66+ 'method' : method ,
67+ 'header' : [ ] ,
68+ 'url' : {
69+ 'raw' : 'http://postman-echo.com/get' ,
70+ 'protocol' : 'http' ,
71+ 'host' : [
72+ 'postman-echo' ,
73+ 'com'
74+ ] ,
75+ 'path' : [
76+ 'get'
77+ ]
78+ }
79+ } ) ,
80+ options = { } ;
81+ convert ( request , options , function ( error , snippet ) {
82+ if ( error ) {
83+ expect . fail ( null , null , error ) ;
84+ }
85+ expect ( snippet ) . to . be . a ( 'string' ) ;
86+ expect ( snippet ) . to . include ( `let request = client.request(reqwest::Method::${ method } ` ) ;
87+ } ) ;
88+ } ) ;
89+ } ) ;
90+
91+ it ( 'should use the method name using bytes if it not part of the allowed list' , function ( ) {
92+ [ 'PROPFIND' , 'PURGE' , 'LOCK' , 'UNLOCK' , 'LINK' , 'UNLINK' , 'COPY' ] . forEach ( function ( method ) {
93+ const request = new sdk . Request ( {
94+ 'method' : method ,
95+ 'header' : [ ] ,
96+ 'url' : {
97+ 'raw' : 'http://postman-echo.com/get' ,
98+ 'protocol' : 'http' ,
99+ 'host' : [
100+ 'postman-echo' ,
101+ 'com'
102+ ] ,
103+ 'path' : [
104+ 'get'
105+ ]
106+ }
107+ } ) ,
108+ options = { } ;
109+ convert ( request , options , function ( error , snippet ) {
110+ if ( error ) {
111+ expect . fail ( null , null , error ) ;
112+ }
113+ expect ( snippet ) . to . be . a ( 'string' ) ;
114+ expect ( snippet ) . to . include ( `let method = "${ method } "` ) ;
115+ expect ( snippet ) . to . include ( 'let request = client.request(reqwest::Method::from_bytes(method.as_bytes())?' ) ;
116+ } ) ;
117+ } ) ;
118+ } ) ;
119+
57120} ) ;
0 commit comments