forked from eatvio/eatvio_app
48 lines
1.2 KiB
Dart
48 lines
1.2 KiB
Dart
import 'package:eatvio_app/features/profile/models/weight_model.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
group('WeightModel', () {
|
|
test('fromJson parses all fields correctly', () {
|
|
final json = {
|
|
'id': 1,
|
|
'user_id': 123,
|
|
'weight': 75,
|
|
'created_at': '2024-01-15T10:00:00Z',
|
|
'updated_at': '2024-01-16T10:00:00Z',
|
|
'bmi': 22.5,
|
|
};
|
|
|
|
final model = WeightModel.fromJson(json);
|
|
|
|
expect(model.id, 1);
|
|
expect(model.userId, 123);
|
|
expect(model.weight, 75);
|
|
expect(model.createdAt, isA<DateTime>());
|
|
expect(model.updatedAt, isA<DateTime>());
|
|
expect(model.bmi, 22.5);
|
|
});
|
|
|
|
test('toJson serializes all fields correctly', () {
|
|
final model = WeightModel(
|
|
id: 1,
|
|
userId: 123,
|
|
weight: 75,
|
|
createdAt: DateTime(2024, 1, 15, 10, 0, 0),
|
|
updatedAt: DateTime(2024, 1, 16, 10, 0, 0),
|
|
bmi: 22.5,
|
|
);
|
|
|
|
final json = model.toJson();
|
|
|
|
expect(json['id'], 1);
|
|
expect(json['user_id'], 123);
|
|
expect(json['weight'], 75);
|
|
expect(json['bmi'], 22.5);
|
|
expect(json['created_at'], isA<String>());
|
|
expect(json['updated_at'], isA<String>());
|
|
});
|
|
});
|
|
}
|
|
|