mirror of
https://github.com/foss42/apidash.git
synced 2025-06-04 17:37:05 +08:00
95 lines
2.7 KiB
Dart
95 lines
2.7 KiB
Dart
import 'package:apidash/importer/curl/curl.dart';
|
|
import 'package:test/test.dart';
|
|
import 'package:apidash_core/apidash_core.dart';
|
|
|
|
void main() {
|
|
group('CurlFileImport Tests', () {
|
|
late CurlFileImport curlImport;
|
|
|
|
setUp(() {
|
|
curlImport = CurlFileImport();
|
|
});
|
|
|
|
test('should parse simple GET request', () {
|
|
const curl = 'curl https://api.apidash.dev/users';
|
|
final result = curlImport.getHttpRequestModel(curl);
|
|
|
|
expect(
|
|
result,
|
|
const HttpRequestModel(
|
|
method: HTTPVerb.get,
|
|
url: 'https://api.apidash.dev/users',
|
|
headers: null,
|
|
params: [],
|
|
body: null,
|
|
bodyContentType: ContentType.text,
|
|
formData: null));
|
|
});
|
|
|
|
test('should parse POST request with JSON body and headers', () {
|
|
const curl = '''
|
|
curl -X POST https://api.apidash.dev/users
|
|
-H "Content-Type: application/json"
|
|
-H "Authorization: Bearer token123"
|
|
-d '{"name": "John", "age": 30}'
|
|
''';
|
|
|
|
final result = curlImport.getHttpRequestModel(curl);
|
|
|
|
expect(
|
|
result,
|
|
const HttpRequestModel(
|
|
method: HTTPVerb.post,
|
|
url: 'https://api.apidash.dev/users',
|
|
headers: [
|
|
NameValueModel(name: 'Content-Type', value: 'application/json'),
|
|
NameValueModel(name: 'Authorization', value: 'Bearer token123'),
|
|
],
|
|
params: [],
|
|
body: '{"name": "John", "age": 30}',
|
|
bodyContentType: ContentType.json,
|
|
formData: null,
|
|
),
|
|
);
|
|
});
|
|
|
|
test('should parse form data request', () {
|
|
const curl = '''
|
|
curl -X POST https://api.apidash.dev/upload
|
|
-F "file=@photo.jpg"
|
|
-F "description=My Photo"
|
|
''';
|
|
|
|
final result = curlImport.getHttpRequestModel(curl);
|
|
|
|
expect(
|
|
result,
|
|
const HttpRequestModel(
|
|
method: HTTPVerb.post,
|
|
url: 'https://api.apidash.dev/upload',
|
|
headers: [
|
|
NameValueModel(name: "Content-Type", value: "multipart/form-data")
|
|
],
|
|
params: [],
|
|
body: null,
|
|
bodyContentType: ContentType.formdata,
|
|
formData: [
|
|
FormDataModel(
|
|
name: 'file', value: 'photo.jpg', type: FormDataType.file),
|
|
FormDataModel(
|
|
name: 'description',
|
|
value: 'My Photo',
|
|
type: FormDataType.text),
|
|
],
|
|
));
|
|
});
|
|
|
|
test('should return null for invalid curl command', () {
|
|
const curl = 'invalid curl command';
|
|
final result = curlImport.getHttpRequestModel(curl);
|
|
|
|
expect(result, isNull);
|
|
});
|
|
});
|
|
}
|