forked from eatvio/eatvio_app
94 lines
2.7 KiB
Dart
94 lines
2.7 KiB
Dart
import 'package:eatvio_app/features/profile/models/circumference_model.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>());
|
|
});
|
|
|
|
Map<String, dynamic> json({Object? weight = 72.3, Object? bmi = 22.4}) => {
|
|
'id': 1,
|
|
'user_id': 2,
|
|
'weight': weight,
|
|
'created_at': '2026-11-01T10:00:00.000000Z',
|
|
'updated_at': '2026-11-01T10:00:00.000000Z',
|
|
'bmi': bmi,
|
|
};
|
|
|
|
test('парсит дробный weight', () {
|
|
final model = WeightModel.fromJson(json());
|
|
|
|
expect(model.weight, 72.3);
|
|
expect(model.bmi, 22.4);
|
|
});
|
|
|
|
test('парсит целый weight как double', () {
|
|
final model = WeightModel.fromJson(json(weight: 72));
|
|
|
|
expect(model.weight, 72.0);
|
|
});
|
|
|
|
test('допускает bmi: null (рост не указан)', () {
|
|
final model = WeightModel.fromJson(json(bmi: null));
|
|
|
|
expect(model.bmi, isNull);
|
|
});
|
|
});
|
|
|
|
group('CircumferenceModel', () {
|
|
test('парсит целые и дробные значения (прореженные средние)', () {
|
|
final model = CircumferenceModel.fromJson({
|
|
'id': 1,
|
|
'user_id': 2,
|
|
'chest_circumference': 95,
|
|
'waist_circumference': 80.5,
|
|
'hip_circumference': 100,
|
|
'created_at': '2026-11-01T10:00:00.000000Z',
|
|
'updated_at': '2026-11-01T10:00:00.000000Z',
|
|
});
|
|
|
|
expect(model.chestCircumference, 95.0);
|
|
expect(model.waistCircumference, 80.5);
|
|
expect(model.hipCircumference, 100.0);
|
|
});
|
|
});
|
|
}
|