Skip to content

Commit b727444

Browse files
committed
Handled failing test- POST UrlEncoded body
1 parent a1fc8ea commit b727444

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

codegens/dart-dio/lib/index.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ var _ = require('lodash'),
1313
* @param {Boolean} trim indicates whether to trim string or not
1414
*/
1515
function parseUrlEncoded (body, indent, trim) {
16-
var bodySnippet = 'var data = FormData.fromMap({',
16+
var bodySnippet = 'var data = {',
1717
enabledBodyList = _.reject(body, 'disabled'),
1818
bodyDataMap;
1919
if (!_.isEmpty(enabledBodyList)) {
@@ -22,7 +22,7 @@ function parseUrlEncoded (body, indent, trim) {
2222
});
2323
bodySnippet += '\n' + bodyDataMap.join(',\n') + '\n';
2424
}
25-
bodySnippet += '});';
25+
bodySnippet += '};';
2626
return bodySnippet;
2727
}
2828

@@ -109,8 +109,8 @@ function parseFormData (body, indent, trim) {
109109
if (formDataArray.length > 0 || formDataFileArray.length > 0) {
110110
bodySnippet += 'var data = FormData.fromMap({\n';
111111
if (formDataFileArray.length > 0) {
112-
bodySnippet += `${indent}'files': [\n`;
113-
bodySnippet += formDataFileArray.join(`,\n${indent}`);
112+
bodySnippet += `${indent}'files': [\n${indent}${indent}`;
113+
bodySnippet += formDataFileArray.join(`,\n${indent}${indent}`);
114114
bodySnippet += `\n${indent}],\n`;
115115
}
116116
bodySnippet += formDataArray.join(',\n');
@@ -271,25 +271,24 @@ self = module.exports = {
271271
codeSnippet += body + '\n';
272272
}
273273

274-
codeSnippet += `
275-
var dio = Dio();
276-
var response = await dio.request(\n
277-
'${request.url.toString()}',
278-
options: Options(
279-
method: '${request.method.toUpperCase()}',\n
280-
${headers !== '' ? 'headers: headers,\n' : ''}
281-
${followRedirect ? 'followRedirects: true,\n' : 'followRedirects: false,\n'}
282-
${timeout ? `receiveTimeout: ${timeout},\n` : ''}
283-
),\n
284-
${body !== '' ? 'data: data,\n' : ''}
285-
);`;
274+
codeSnippet += 'var dio = Dio();\n';
275+
codeSnippet += 'var response = await dio.request(\n';
276+
codeSnippet += `${indent}'${request.url.toString()}',\n`;
277+
codeSnippet += `${indent}options: Options(\n`;
278+
codeSnippet += `${indent}${indent}method: '${request.method.toUpperCase()}',\n`;
279+
codeSnippet += `${headers !== '' ? `${indent}${indent}headers: headers,\n` : ''}`;
280+
codeSnippet += `${followRedirect ? '' : `${indent}${indent}followRedirects: false,\n`}`;
281+
codeSnippet += `${timeout ? `${indent}${indent}receiveTimeout: ${timeout},\n` : ''}`;
282+
codeSnippet += `${indent}),\n`;
283+
codeSnippet += `${body !== '' ? `${indent}data: data,\n` : ''}`;
284+
codeSnippet += ');';
286285

287-
codeSnippet += ';\n\n';
286+
codeSnippet += '\n\n';
288287
codeSnippet += 'if (response.statusCode == 200) {\n';
289288
codeSnippet += `${indent}print(json.encode(response.data));\n`;
290289
codeSnippet += '}\nelse {\n';
291290
codeSnippet += `${indent}print(response.statusMessage);\n`;
292-
codeSnippet += '}\n';
291+
codeSnippet += '}';
293292

294293
(options.includeBoilerplate) &&
295294
(codeSnippet = indent + codeSnippet.split('\n').join('\n' + indent) + '\n');

0 commit comments

Comments
 (0)