Update dart_to_curl_test.dart

This commit is contained in:
Ashita Prasad
2024-11-30 16:37:56 +05:30
parent bd7b1e5e3a
commit b227ae2e9c

View File

@ -3,8 +3,12 @@ import 'package:curl_parser/curl_parser.dart';
import 'package:test/test.dart';
void main() {
group('Basic HTTP Methods', () {
test('GET request', () {
group(
'Basic HTTP Methods',
() {
test(
'GET request',
() {
final curl = Curl(
method: 'GET',
uri: Uri.parse('https://api.apidash.dev'),
@ -13,9 +17,12 @@ void main() {
curl.toCurlString(),
'curl "https://api.apidash.dev"',
);
});
},
);
test('POST request', () {
test(
'POST request',
() {
final curl = Curl(
method: 'POST',
uri: Uri.parse('https://api.apidash.dev/test'),
@ -24,7 +31,8 @@ void main() {
curl.toCurlString(),
'curl -X POST "https://api.apidash.dev/test"',
);
});
},
);
test('HEAD request', () {
final curl = Curl(
@ -36,10 +44,15 @@ void main() {
'curl -I "https://api.apidash.dev"',
);
});
});
},
);
group('Headers and Data', () {
test('request with headers', () {
group(
'Headers and Data',
() {
test(
'request with headers',
() {
final curl = Curl(
method: 'GET',
uri: Uri.parse('https://api.apidash.dev'),
@ -54,7 +67,8 @@ void main() {
-H "Content-Type: application/json" \
-H "Authorization: Bearer token123"''',
);
});
},
);
test('POST request with data', () {
final curl = Curl(
@ -70,9 +84,12 @@ void main() {
-d '{"key": "value"}'""",
);
});
});
},
);
group('Form Data', () {
group(
'Post with Form Data',
() {
test('request with form data', () {
final curl = Curl(
method: 'POST',
@ -100,10 +117,15 @@ void main() {
-F "name=test"''',
);
});
});
},
);
group('Special Parameters', () {
test('request with cookie', () {
group(
'Special Parameters',
() {
test(
'request with cookie',
() {
final curl = Curl(
method: 'GET',
uri: Uri.parse('https://api.apidash.dev'),
@ -114,9 +136,12 @@ void main() {
r"""curl "https://api.apidash.dev" \
-b 'session=abc123'""",
);
});
},
);
test('request with user credentials', () {
test(
'request with user credentials',
() {
final curl = Curl(
method: 'GET',
uri: Uri.parse('https://api.apidash.dev'),
@ -127,9 +152,12 @@ void main() {
r"""curl "https://api.apidash.dev" \
-u 'username:password'""",
);
});
},
);
test('request with referer', () {
test(
'request with referer',
() {
final curl = Curl(
method: 'GET',
uri: Uri.parse('https://api.apidash.dev'),
@ -140,9 +168,12 @@ void main() {
r"""curl "https://api.apidash.dev" \
-e 'https://example.com'""",
);
});
},
);
test('request with user agent', () {
test(
'request with user agent',
() {
final curl = Curl(
method: 'GET',
uri: Uri.parse('https://api.apidash.dev'),
@ -153,9 +184,12 @@ void main() {
r"""curl "https://api.apidash.dev" \
-A 'MyApp/1.0'""",
);
});
},
);
test('request with insecure flag', () {
test(
'request with insecure flag',
() {
final curl = Curl(
method: 'GET',
uri: Uri.parse('https://api.apidash.dev'),
@ -165,7 +199,8 @@ void main() {
curl.toCurlString(),
r"""curl "https://api.apidash.dev" -k""",
);
});
},
);
test('request with location flag', () {
final curl = Curl(
@ -178,9 +213,12 @@ void main() {
r"""curl "https://api.apidash.dev" -L""",
);
});
});
},
);
group('Complex Requests', () {
group(
'Complex Requests',
() {
test('request with all parameters', () {
final curl = Curl(
method: 'POST',
@ -209,5 +247,6 @@ void main() {
-A 'MyApp/1.0' -k -L""",
);
});
});
},
);
}