@@ -4,6 +4,7 @@ import { generateCurl, parseCurl, type CurlRequest } from "./curl";
4
4
test ( "support url" , ( ) => {
5
5
const result = {
6
6
url : "https://my-url/hello-world" ,
7
+ searchParams : [ ] ,
7
8
method : "get" ,
8
9
headers : [ ] ,
9
10
} ;
@@ -19,6 +20,7 @@ test("support multiline command with backslashes", () => {
19
20
` )
20
21
) . toEqual ( {
21
22
url : "https://my-url/hello-world" ,
23
+ searchParams : [ ] ,
22
24
method : "get" ,
23
25
headers : [ ] ,
24
26
} ) ;
@@ -27,6 +29,7 @@ test("support multiline command with backslashes", () => {
27
29
test ( "forgive missing closed quotes" , ( ) => {
28
30
expect ( parseCurl ( `curl "https://my-url/hello-world` ) ) . toEqual ( {
29
31
url : "https://my-url/hello-world" ,
32
+ searchParams : [ ] ,
30
33
method : "get" ,
31
34
headers : [ ] ,
32
35
} ) ;
@@ -43,6 +46,7 @@ test("skip when invalid", () => {
43
46
test ( "support method with --request and -X flags" , ( ) => {
44
47
const result = {
45
48
url : "https://my-url/hello-world" ,
49
+ searchParams : [ ] ,
46
50
method : "post" ,
47
51
headers : [ ] ,
48
52
} ;
@@ -62,19 +66,41 @@ test("support --get and -G flags", () => {
62
66
expect (
63
67
parseCurl ( `curl --get https://my-url --data limit=3 --data first=0` )
64
68
) . toEqual ( {
65
- url : "https://my-url?limit=3&first=0" ,
69
+ url : "https://my-url/" ,
70
+ searchParams : [
71
+ { name : "limit" , value : "3" } ,
72
+ { name : "first" , value : "0" } ,
73
+ ] ,
66
74
method : "get" ,
67
75
headers : [ ] ,
68
76
} ) ;
69
77
expect ( parseCurl ( `curl -G https://my-url -d limit=3 -d first=0` ) ) . toEqual ( {
70
- url : "https://my-url?limit=3&first=0" ,
78
+ url : "https://my-url/" ,
79
+ searchParams : [
80
+ { name : "limit" , value : "3" } ,
81
+ { name : "first" , value : "0" } ,
82
+ ] ,
71
83
method : "get" ,
72
84
headers : [ ] ,
73
85
} ) ;
74
86
expect (
75
87
parseCurl ( `curl -G https://my-url?filter=1 -d limit=3 -d first=0` )
76
88
) . toEqual ( {
77
- url : "https://my-url?filter=1&limit=3&first=0" ,
89
+ url : "https://my-url/" ,
90
+ searchParams : [
91
+ { name : "filter" , value : "1" } ,
92
+ { name : "limit" , value : "3" } ,
93
+ { name : "first" , value : "0" } ,
94
+ ] ,
95
+ method : "get" ,
96
+ headers : [ ] ,
97
+ } ) ;
98
+ expect ( parseCurl ( `curl -G https://my-url?filter -d limit` ) ) . toEqual ( {
99
+ url : "https://my-url/" ,
100
+ searchParams : [
101
+ { name : "filter" , value : "" } ,
102
+ { name : "limit" , value : "" } ,
103
+ ] ,
78
104
method : "get" ,
79
105
headers : [ ] ,
80
106
} ) ;
@@ -85,12 +111,14 @@ test("support headers with --header and -H flags", () => {
85
111
parseCurl ( `curl https://my-url/hello-world --header "name: value"` )
86
112
) . toEqual ( {
87
113
url : "https://my-url/hello-world" ,
114
+ searchParams : [ ] ,
88
115
method : "get" ,
89
116
headers : [ { name : "name" , value : "value" } ] ,
90
117
} ) ;
91
118
expect ( parseCurl ( `curl https://my-url/hello-world -H "name: value"` ) ) . toEqual (
92
119
{
93
120
url : "https://my-url/hello-world" ,
121
+ searchParams : [ ] ,
94
122
method : "get" ,
95
123
headers : [ { name : "name" , value : "value" } ] ,
96
124
}
@@ -101,6 +129,7 @@ test("support headers with --header and -H flags", () => {
101
129
)
102
130
) . toEqual ( {
103
131
url : "https://my-url/hello-world" ,
132
+ searchParams : [ ] ,
104
133
method : "get" ,
105
134
headers : [
106
135
{ name : "name" , value : "value1" } ,
@@ -119,7 +148,8 @@ test("default to post method and urlencoded header when data is specified", () =
119
148
--data-raw param=4
120
149
` )
121
150
) . toEqual ( {
122
- url : "https://my-url" ,
151
+ url : "https://my-url/" ,
152
+ searchParams : [ ] ,
123
153
method : "post" ,
124
154
headers : [
125
155
{ name : "content-type" , value : "application/x-www-form-urlencoded" } ,
@@ -132,7 +162,8 @@ test("encode data for get request", () => {
132
162
expect (
133
163
parseCurl ( `curl -G https://my-url --data-urlencode param=привет` )
134
164
) . toEqual ( {
135
- url : "https://my-url?param=%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" ,
165
+ url : "https://my-url/" ,
166
+ searchParams : [ { name : "param" , value : "привет" } ] ,
136
167
method : "get" ,
137
168
headers : [ ] ,
138
169
} ) ;
@@ -142,7 +173,8 @@ test("encode data for post request", () => {
142
173
expect (
143
174
parseCurl ( `curl https://my-url --data-urlencode param=привет` )
144
175
) . toEqual ( {
145
- url : "https://my-url" ,
176
+ url : "https://my-url/" ,
177
+ searchParams : [ ] ,
146
178
method : "post" ,
147
179
headers : [
148
180
{ name : "content-type" , value : "application/x-www-form-urlencoded" } ,
@@ -160,6 +192,7 @@ test("support text body", () => {
160
192
` )
161
193
) . toEqual ( {
162
194
url : "https://my-url/hello-world" ,
195
+ searchParams : [ ] ,
163
196
method : "post" ,
164
197
headers : [ { name : "content-type" , value : "plain/text" } ] ,
165
198
body : `{"param":"value"}` ,
@@ -170,6 +203,7 @@ test("support text body", () => {
170
203
)
171
204
) . toEqual ( {
172
205
url : "https://my-url/hello-world" ,
206
+ searchParams : [ ] ,
173
207
method : "post" ,
174
208
headers : [ { name : "content-type" , value : "plain/text" } ] ,
175
209
body : `{"param":"value"}` ,
@@ -186,6 +220,7 @@ test("support text body with explicit method", () => {
186
220
` )
187
221
) . toEqual ( {
188
222
url : "https://my-url/hello-world" ,
223
+ searchParams : [ ] ,
189
224
method : "put" ,
190
225
headers : [ { name : "content-type" , value : "plain/text" } ] ,
191
226
body : `{"param":"value"}` ,
@@ -199,6 +234,7 @@ test("support json body", () => {
199
234
)
200
235
) . toEqual ( {
201
236
url : "https://my-url/hello-world" ,
237
+ searchParams : [ ] ,
202
238
method : "post" ,
203
239
headers : [ { name : "content-type" , value : "application/json" } ] ,
204
240
body : { param : "value" } ,
@@ -213,12 +249,13 @@ test("generate curl with json body", () => {
213
249
expect (
214
250
generateCurl ( {
215
251
url : "https://my-url.com" ,
252
+ searchParams : [ ] ,
216
253
method : "post" ,
217
254
headers : [ { name : "content-type" , value : "application/json" } ] ,
218
255
body : { param : "value" } ,
219
256
} )
220
257
) . toMatchInlineSnapshot ( `
221
- "curl "https://my-url.com" \\
258
+ "curl "https://my-url.com/ " \\
222
259
--request post \\
223
260
--header "content-type: application/json" \\
224
261
--data "{\\"param\\":\\"value\\"}""
@@ -229,12 +266,13 @@ test("generate curl with text body", () => {
229
266
expect (
230
267
generateCurl ( {
231
268
url : "https://my-url.com" ,
269
+ searchParams : [ ] ,
232
270
method : "post" ,
233
271
headers : [ ] ,
234
272
body : "my data" ,
235
273
} )
236
274
) . toMatchInlineSnapshot ( `
237
- "curl "https://my-url.com" \\
275
+ "curl "https://my-url.com/ " \\
238
276
--request post \\
239
277
--data "my data""
240
278
` ) ;
@@ -244,18 +282,38 @@ test("generate curl without body", () => {
244
282
expect (
245
283
generateCurl ( {
246
284
url : "https://my-url.com" ,
285
+ searchParams : [ ] ,
247
286
method : "post" ,
248
287
headers : [ ] ,
249
288
} )
250
289
) . toMatchInlineSnapshot ( `
251
- "curl "https://my-url.com" \\
290
+ "curl "https://my-url.com/ " \\
252
291
--request post"
253
292
` ) ;
254
293
} ) ;
255
294
295
+ test ( "generate curl with search params" , ( ) => {
296
+ expect (
297
+ generateCurl ( {
298
+ url : "https://my-url.com" ,
299
+ searchParams : [
300
+ { name : "search" , value : "term1" } ,
301
+ { name : "search" , value : "term2" } ,
302
+ { name : "filter" , value : "привет" } ,
303
+ ] ,
304
+ method : "get" ,
305
+ headers : [ ] ,
306
+ } )
307
+ ) . toMatchInlineSnapshot ( `
308
+ "curl "https://my-url.com/?search=term1&search=term2&filter=%D0%BF%D1%80%D0%B8%D0%B2%D0%B5%D1%82" \\
309
+ --request get"
310
+ ` ) ;
311
+ } ) ;
312
+
256
313
test ( "multiline graphql is idempotent" , ( ) => {
257
314
const request : CurlRequest = {
258
315
url : "https://eu-central-1-shared-euc1-02.cdn.hygraph.com/content/clorhpxi8qx7r01t6hfp1b5f6/master" ,
316
+ searchParams : [ ] ,
259
317
method : "post" ,
260
318
headers : [ { name : "Content-Type" , value : "application/json" } ] ,
261
319
body : {
@@ -276,7 +334,8 @@ test("multiline graphql is idempotent", () => {
276
334
277
335
test ( "support basic http authentication" , ( ) => {
278
336
expect ( parseCurl ( `curl https://my-url.com -u "user:password"` ) ) . toEqual ( {
279
- url : "https://my-url.com" ,
337
+ url : "https://my-url.com/" ,
338
+ searchParams : [ ] ,
280
339
method : "get" ,
281
340
headers : [
282
341
{
0 commit comments