Fixed a bug in toCurlString() and fixed the dart_to_curl_test with valid curls.

This commit is contained in:
Pratham
2024-11-26 12:25:16 +05:30
parent 49e2b3d11e
commit 166c9286f9
2 changed files with 15 additions and 33 deletions

View File

@ -260,7 +260,11 @@ class Curl extends Equatable {
if (form) {
for (final formEntry in formData!) {
cmd += '\\\n -F ';
cmd += '"${formEntry.name}=${formEntry.value}" ';
if (formEntry.type == FormDataType.file) {
cmd += '"${formEntry.name}=@${formEntry.value}" ';
} else {
cmd += '"${formEntry.name}=${formEntry.value}" ';
}
}
}
// Add the insecure flag

View File

@ -51,9 +51,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl "https://api.apidash.dev" \\\n'
' -H "Content-Type: application/json" \\\n'
' -H "Authorization: Bearer token123"',
'curl "https://api.apidash.dev" \\\n -H "Content-Type: application/json" \\\n -H "Authorization: Bearer token123"',
);
});
@ -66,9 +64,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl -X POST "https://api.apidash.dev/test" \\\n'
' -H "Content-Type: application/json" \\\n'
' -d \'{"key": "value"}\'',
"""curl -X POST "https://api.apidash.dev/test" \\\n -H "Content-Type: application/json" \\\n -d '{"key": "value"}'""",
);
});
});
@ -95,10 +91,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl -X POST "https://api.apidash.dev/upload" \\\n'
' -H "Content-Type: multipart/form-data" \\\n'
' -F "file=/path/to/file.txt" \\\n'
' -F "name=test"',
'curl -X POST "https://api.apidash.dev/upload" \\\n -H "Content-Type: multipart/form-data" \\\n -F "file=@/path/to/file.txt" \\\n -F "name=test"',
);
});
});
@ -112,8 +105,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl "https://api.apidash.dev" \\\n'
' -b \'session=abc123\'',
"""curl "https://api.apidash.dev" \\\n -b 'session=abc123'""",
);
});
@ -125,8 +117,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl "https://api.apidash.dev" \\\n'
' -u \'username:password\'',
"""curl "https://api.apidash.dev" \\\n -u 'username:password'""",
);
});
@ -138,8 +129,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl "https://api.apidash.dev" \\\n'
' -e \'https://example.com\'',
"""curl "https://api.apidash.dev" \\\n -e 'https://example.com'""",
);
});
@ -151,8 +141,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl "https://api.apidash.dev" \\\n'
' -A \'MyApp/1.0\'',
"""curl "https://api.apidash.dev" \\\n -A 'MyApp/1.0'""",
);
});
@ -164,8 +153,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl "https://api.apidash.dev" \\\n'
' -k',
"""curl "https://api.apidash.dev" \\\n -k""",
);
});
@ -177,8 +165,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl "https://api.apidash.dev" \\\n'
' -L',
"""curl "https://api.apidash.dev" \\\n -L""",
);
});
});
@ -202,16 +189,7 @@ void main() {
);
expect(
curl.toCurlString(),
'curl -X POST "https://api.apidash.dev/test" \\\n'
' -H "Content-Type: application/json" \\\n'
' -H "Authorization: Bearer token123" \\\n'
' -d \'{"key": "value"}\' \\\n'
' -b \'session=abc123\' \\\n'
' -u \'username:password\' \\\n'
' -e \'https://example.com\' \\\n'
' -A \'MyApp/1.0\' \\\n'
' -k \\\n'
' -L',
"""curl -X POST "https://api.apidash.dev/test" \\\n -H "Content-Type: application/json" \\\n -H "Authorization: Bearer token123" \\\n -d '{"key": "value"}' \\\n -b 'session=abc123' \\\n -u 'username:password' \\\n -e 'https://example.com' \\\n -A 'MyApp/1.0' \\\n -k \\\n -L""",
);
});
});