Skip to content

Commit 67b48bd

Browse files
Copilotmtrezza
andcommitted
Add tests for file extension detection
Added tests to verify that files with extensions and without extensions are correctly identified, which is crucial for the content-type header logic. Co-authored-by: mtrezza <5673677+mtrezza@users.noreply.github.com>
1 parent a9f3522 commit 67b48bd

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

packages/dart/test/src/objects/parse_file_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'dart:io';
22
import 'package:parse_server_sdk/parse_server_sdk.dart';
33
import 'package:test/test.dart';
4+
import 'package:path/path.dart' as path;
45

56
import '../../test_utils.dart';
67

@@ -15,5 +16,44 @@ void main() {
1516
final parseFile = ParseFile(file, name: 'bb.jpg');
1617
expect(parseFile.name, 'bb.jpg');
1718
});
19+
20+
test('should detect file extension correctly for files with extensions',
21+
() {
22+
// Test various file extensions
23+
final testCases = [
24+
'image.jpg',
25+
'photo.png',
26+
'document.pdf',
27+
'myfile.txt',
28+
'archive.zip',
29+
];
30+
31+
for (final filename in testCases) {
32+
File file = File('/path/to/$filename');
33+
final parseFile = ParseFile(file, name: filename);
34+
// Verify that the extension is detected
35+
expect(path.extension(parseFile.name).isNotEmpty, true,
36+
reason: '$filename should have an extension');
37+
}
38+
});
39+
40+
test(
41+
'should detect missing extension correctly for files without extensions',
42+
() {
43+
// Test files without extensions
44+
final testCases = [
45+
'image',
46+
'file',
47+
'document',
48+
];
49+
50+
for (final filename in testCases) {
51+
File file = File('/path/to/$filename');
52+
final parseFile = ParseFile(file, name: filename);
53+
// Verify that no extension is detected
54+
expect(path.extension(parseFile.name).isEmpty, true,
55+
reason: '$filename should not have an extension');
56+
}
57+
});
1858
});
1959
}

packages/dart/test/src/objects/parse_x_file_test.dart

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:cross_file/cross_file.dart';
22
import 'package:parse_server_sdk/parse_server_sdk.dart';
33
import 'package:test/test.dart';
4+
import 'package:path/path.dart' as path;
45

56
import '../../test_utils.dart';
67

@@ -15,5 +16,44 @@ void main() {
1516
final parseFile = ParseXFile(file, name: 'bb.jpg');
1617
expect(parseFile.name, 'bb.jpg');
1718
});
19+
20+
test('should detect file extension correctly for files with extensions',
21+
() {
22+
// Test various file extensions
23+
final testCases = [
24+
'image.jpg',
25+
'photo.png',
26+
'document.pdf',
27+
'myfile.txt',
28+
'archive.zip',
29+
];
30+
31+
for (final filename in testCases) {
32+
XFile file = XFile('/path/to/$filename');
33+
final parseFile = ParseXFile(file, name: filename);
34+
// Verify that the extension is detected
35+
expect(path.extension(parseFile.name).isNotEmpty, true,
36+
reason: '$filename should have an extension');
37+
}
38+
});
39+
40+
test(
41+
'should detect missing extension correctly for files without extensions',
42+
() {
43+
// Test files without extensions
44+
final testCases = [
45+
'image',
46+
'file',
47+
'document',
48+
];
49+
50+
for (final filename in testCases) {
51+
XFile file = XFile('/path/to/$filename');
52+
final parseFile = ParseXFile(file, name: filename);
53+
// Verify that no extension is detected
54+
expect(path.extension(parseFile.name).isEmpty, true,
55+
reason: '$filename should not have an extension');
56+
}
57+
});
1858
});
1959
}

0 commit comments

Comments
 (0)