forked from eatvio/eatvio_app
test(tests): add comprehensive unit tests for various models and repositories, enhancing test coverage and ensuring correct functionality
This commit is contained in:
@@ -23,6 +23,29 @@ void main() {
|
||||
expect(model.grInPortion, 100);
|
||||
expect(model.energyOn100Gr, 52.0);
|
||||
});
|
||||
|
||||
test('fromJson создает GlossaryModel из JSON', () {
|
||||
final json = {
|
||||
'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 = GlossaryModel.fromJson(json);
|
||||
|
||||
expect(model.id, 1);
|
||||
expect(model.name, 'Apple');
|
||||
expect(model.grInPortion, 100);
|
||||
expect(model.energyOn100Gr, 52.0);
|
||||
});
|
||||
});
|
||||
|
||||
group('GlossaryPaginationModel', () {
|
||||
@@ -46,6 +69,31 @@ void main() {
|
||||
expect(pagination.glossariesList.length, 1);
|
||||
expect(pagination.glossariesList.first.id, 1);
|
||||
});
|
||||
|
||||
test('fromJson создает GlossaryPaginationModel из JSON', () {
|
||||
final json = {
|
||||
'data': [
|
||||
{
|
||||
'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 pagination = GlossaryPaginationModel.fromJson(json);
|
||||
|
||||
expect(pagination.glossariesList.length, 1);
|
||||
expect(pagination.glossariesList.first.id, 1);
|
||||
});
|
||||
});
|
||||
|
||||
group('GlossaryModerationModel', () {
|
||||
@@ -69,6 +117,29 @@ void main() {
|
||||
expect(model.glossary.id, 1);
|
||||
expect(model.glossary.name, 'Apple');
|
||||
});
|
||||
|
||||
test('fromJson создает GlossaryModerationModel из JSON', () {
|
||||
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');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user