格式化代码
This commit is contained in:
127
test/unit/domain/entities/photo_test.dart
Normal file
127
test/unit/domain/entities/photo_test.dart
Normal file
@@ -0,0 +1,127 @@
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import '../../../../bin/domain/entities/photo.dart';
|
||||
|
||||
void main() {
|
||||
group('Photo', () {
|
||||
test('should create a Photo with required fields', () {
|
||||
final now = DateTime.now();
|
||||
final photo = Photo(
|
||||
id: 1,
|
||||
albumId: 10,
|
||||
filePath: '/data/vacation/photo.jpg',
|
||||
fileName: 'photo.jpg',
|
||||
fileSize: 1024000,
|
||||
mimeType: 'image/jpeg',
|
||||
createdAt: now,
|
||||
);
|
||||
|
||||
expect(photo.id, 1);
|
||||
expect(photo.albumId, 10);
|
||||
expect(photo.filePath, '/data/vacation/photo.jpg');
|
||||
expect(photo.fileName, 'photo.jpg');
|
||||
expect(photo.fileSize, 1024000);
|
||||
expect(photo.mimeType, 'image/jpeg');
|
||||
expect(photo.width, isNull);
|
||||
expect(photo.height, isNull);
|
||||
expect(photo.createdAt, now);
|
||||
});
|
||||
|
||||
test('should create a Photo with optional dimensions', () {
|
||||
final now = DateTime.now();
|
||||
final photo = Photo(
|
||||
id: 2,
|
||||
albumId: 10,
|
||||
filePath: '/data/vacation/photo.png',
|
||||
fileName: 'photo.png',
|
||||
fileSize: 2048000,
|
||||
mimeType: 'image/png',
|
||||
width: 1920,
|
||||
height: 1080,
|
||||
createdAt: now,
|
||||
);
|
||||
|
||||
expect(photo.width, 1920);
|
||||
expect(photo.height, 1080);
|
||||
});
|
||||
|
||||
test('toJson should return correct map', () {
|
||||
final now = DateTime(2024, 6, 15, 10, 30, 0);
|
||||
final photo = Photo(
|
||||
id: 42,
|
||||
albumId: 5,
|
||||
filePath: '/data/test/image.webp',
|
||||
fileName: 'image.webp',
|
||||
fileSize: 500000,
|
||||
mimeType: 'image/webp',
|
||||
width: 800,
|
||||
height: 600,
|
||||
createdAt: now,
|
||||
);
|
||||
|
||||
final json = photo.toJson();
|
||||
|
||||
expect(json, isA<Map<String, dynamic>>());
|
||||
expect(json['id'], 42);
|
||||
expect(json['albumId'], 5);
|
||||
expect(json['filePath'], '/data/test/image.webp');
|
||||
expect(json['fileName'], 'image.webp');
|
||||
expect(json['fileSize'], 500000);
|
||||
expect(json['mimeType'], 'image/webp');
|
||||
expect(json['width'], 800);
|
||||
expect(json['height'], 600);
|
||||
expect(json['createdAt'], now.toIso8601String());
|
||||
});
|
||||
|
||||
test('toJson should include null dimensions when not set', () {
|
||||
final now = DateTime.now();
|
||||
final photo = Photo(
|
||||
id: 1,
|
||||
albumId: 1,
|
||||
filePath: '/data/video.mp4',
|
||||
fileName: 'video.mp4',
|
||||
fileSize: 10000,
|
||||
mimeType: 'video/mp4',
|
||||
createdAt: now,
|
||||
);
|
||||
|
||||
final json = photo.toJson();
|
||||
|
||||
expect(json['width'], isNull);
|
||||
expect(json['height'], isNull);
|
||||
});
|
||||
|
||||
test('toJson should serialize dates in ISO8601 format', () {
|
||||
final createdAt = DateTime(2024, 1, 1);
|
||||
final photo = Photo(
|
||||
id: 1,
|
||||
albumId: 1,
|
||||
filePath: '/data/test.jpg',
|
||||
fileName: 'test.jpg',
|
||||
fileSize: 1000,
|
||||
mimeType: 'image/jpeg',
|
||||
createdAt: createdAt,
|
||||
);
|
||||
|
||||
final json = photo.toJson();
|
||||
|
||||
expect(json['createdAt'], '2024-01-01T00:00:00.000');
|
||||
});
|
||||
|
||||
test('should support video mime types', () {
|
||||
final now = DateTime.now();
|
||||
final photo = Photo(
|
||||
id: 3,
|
||||
albumId: 1,
|
||||
filePath: '/data/clip.mp4',
|
||||
fileName: 'clip.mp4',
|
||||
fileSize: 5000000,
|
||||
mimeType: 'video/mp4',
|
||||
createdAt: now,
|
||||
);
|
||||
|
||||
expect(photo.mimeType, 'video/mp4');
|
||||
expect(photo.toJson()['mimeType'], 'video/mp4');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user