forked from eatvio/eatvio_app
55 lines
1.6 KiB
Dart
55 lines
1.6 KiB
Dart
import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
group('GlossaryModerationModel', () {
|
|
test('fromJson parses glossary correctly', () {
|
|
final json = {
|
|
'product_nutritional_value': {
|
|
'id': 1,
|
|
'name': 'Apple',
|
|
'portion_mass_gr': 100,
|
|
'energy_on_100gr': 52.0,
|
|
'proteins_on_100gr': 0.3,
|
|
'fats_on_100gr': 0.2,
|
|
'carbohydrates_on_100gr': 14.0,
|
|
'energy_on_portion': 52.0,
|
|
'proteins_on_portion': 0.3,
|
|
'fats_on_portion': 0.2,
|
|
'carbohydrates_on_portion': 14.0,
|
|
},
|
|
};
|
|
|
|
final model = GlossaryModerationModel.fromJson(json);
|
|
|
|
expect(model.glossary.id, 1);
|
|
expect(model.glossary.name, 'Apple');
|
|
expect(model.glossary.grInPortion, 100);
|
|
expect(model.glossary.energyOn100Gr, 52.0);
|
|
});
|
|
|
|
test('toJson serializes glossary correctly', () {
|
|
const glossary = GlossaryModel(
|
|
id: 1,
|
|
name: 'Apple',
|
|
grInPortion: 100,
|
|
energyOn100Gr: 52.0,
|
|
proteinsOn100Gr: 0.3,
|
|
fatsOn100Gr: 0.2,
|
|
carbohydratesOn100Gr: 14.0,
|
|
energyOnPortion: 52.0,
|
|
proteinsOnPortion: 0.3,
|
|
fatsOnPortion: 0.2,
|
|
carbohydratesOnPortion: 14.0,
|
|
);
|
|
const model = GlossaryModerationModel(glossary: glossary);
|
|
|
|
final json = model.toJson();
|
|
|
|
expect(json.containsKey('product_nutritional_value'), isTrue);
|
|
expect(json['product_nutritional_value'], isNotNull);
|
|
});
|
|
});
|
|
}
|
|
|