Skip to content

Commit e1f8a1b

Browse files
committed
feat(tests): add more tests for codegen with multipart body
1 parent dc25c6a commit e1f8a1b

File tree

1 file changed

+101
-1
lines changed

1 file changed

+101
-1
lines changed

test/request_models.dart

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import 'package:apidash/models/models.dart' show NameValueModel, RequestModel;
1+
import 'package:apidash/models/models.dart'
2+
show FormDataModel, NameValueModel, RequestModel;
23
import 'package:apidash/consts.dart';
34

45
/// Basic GET request model
@@ -226,6 +227,105 @@ const requestModelPost3 = RequestModel(
226227
],
227228
);
228229

230+
/// POST request model with multipart body(text)
231+
const requestModelPost4 = RequestModel(
232+
id: 'post4',
233+
url: 'https://oshi.at',
234+
method: HTTPVerb.post,
235+
requestFormDataList: [
236+
FormDataModel(
237+
name: "text", value: "some textual string", type: FormDataType.file)
238+
],
239+
requestBodyContentType: ContentType.formdata,
240+
);
241+
242+
/// POST request model with multipart body and headers
243+
const requestModelPost5 = RequestModel(
244+
id: 'post5',
245+
url: 'https://oshi.at',
246+
method: HTTPVerb.post,
247+
requestFormDataList: [
248+
FormDataModel(
249+
name: "text", value: "some textual string", type: FormDataType.text)
250+
],
251+
requestHeaders: [
252+
NameValueModel(name: 'User-Agent', value: 'Test Agent'),
253+
],
254+
requestBodyContentType: ContentType.formdata,
255+
);
256+
257+
/// POST request model with multipart body(file)
258+
const requestModelPost6 = RequestModel(
259+
id: 'post6',
260+
url: 'https://oshi.at',
261+
method: HTTPVerb.post,
262+
requestFormDataList: [
263+
FormDataModel(name: "f", value: "/path/to/file", type: FormDataType.file)
264+
],
265+
requestBodyContentType: ContentType.formdata,
266+
);
267+
268+
/// POST request model with multipart body and requestBody (the requestBody shouldn't be in codegen)
269+
const requestModelPost7 = RequestModel(
270+
id: 'post7',
271+
url: 'https://oshi.at',
272+
method: HTTPVerb.post,
273+
requestBody: r"""{
274+
"text": "I LOVE Flutter"
275+
}""",
276+
requestFormDataList: [
277+
FormDataModel(
278+
name: "text", value: "some textual string", type: FormDataType.text)
279+
],
280+
requestBodyContentType: ContentType.formdata,
281+
);
282+
283+
/// POST request model with multipart body and requestParams
284+
const requestModelPost8 = RequestModel(
285+
id: 'post8',
286+
url: 'https://oshi.at',
287+
method: HTTPVerb.post,
288+
requestFormDataList: [
289+
FormDataModel(
290+
name: "text", value: "some textual string", type: FormDataType.text)
291+
],
292+
requestParams: [
293+
NameValueModel(name: 'num', value: '8700000'),
294+
NameValueModel(name: 'digits', value: '3'),
295+
NameValueModel(name: 'system', value: 'SS'),
296+
NameValueModel(name: 'add_space', value: 'true'),
297+
NameValueModel(name: 'trailing_zeros', value: 'true'),
298+
],
299+
requestBodyContentType: ContentType.formdata,
300+
);
301+
302+
/// POST request model with multipart body(file and text), requestParams, requestHeaders and requestBody
303+
const requestModelPost9 = RequestModel(
304+
id: 'post9',
305+
url: 'https://oshi.at',
306+
method: HTTPVerb.post,
307+
requestBody: r"""{
308+
"text": "I LOVE Flutter"
309+
}""",
310+
requestFormDataList: [
311+
FormDataModel(
312+
name: "text", value: "some textual string", type: FormDataType.text),
313+
FormDataModel(name: "f", value: "/path/to/file", type: FormDataType.file)
314+
],
315+
requestParams: [
316+
NameValueModel(name: 'num', value: '8700000'),
317+
NameValueModel(name: 'digits', value: '3'),
318+
NameValueModel(name: 'system', value: 'SS'),
319+
NameValueModel(name: 'add_space', value: 'true'),
320+
NameValueModel(name: 'trailing_zeros', value: 'true'),
321+
],
322+
requestHeaders: [
323+
NameValueModel(name: 'User-Agent', value: 'Test Agent'),
324+
NameValueModel(name: 'Content-Type', value: 'multipart/form-data'),
325+
],
326+
requestBodyContentType: ContentType.formdata,
327+
);
328+
229329
/// PUT request model
230330
const requestModelPut1 = RequestModel(
231331
id: 'put1',

0 commit comments

Comments
 (0)