forked from eatvio/eatvio_app
fix(diary): parse commented_from_diet/reviewed_from_diet portion states, fallback unknown states to PortionState.unknown
This commit is contained in:
@@ -4,14 +4,48 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
void main() {
|
||||
group('PortionState enum', () {
|
||||
test('has all expected values', () {
|
||||
expect(PortionState.values.length, 7);
|
||||
expect(PortionState.values.length, 10);
|
||||
expect(PortionState.filledDiet, isNotNull);
|
||||
expect(PortionState.eatenFromDiet, isNotNull);
|
||||
expect(PortionState.eaten, isNotNull);
|
||||
expect(PortionState.eatenDeleted, isNotNull);
|
||||
expect(PortionState.eatenEdited, isNotNull);
|
||||
expect(PortionState.commented, isNotNull);
|
||||
expect(PortionState.commentedFromDiet, isNotNull);
|
||||
expect(PortionState.reviewedByUser, isNotNull);
|
||||
expect(PortionState.reviewedFromDiet, isNotNull);
|
||||
expect(PortionState.unknown, isNotNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('PortionModel.fromJson', () {
|
||||
Map<String, dynamic> portionJson({required String state}) => {
|
||||
'id': 1,
|
||||
'product_nutritional_value_id': null,
|
||||
'product_calories_info': null,
|
||||
'product_name': 'Oatmeal',
|
||||
'quantity': 1,
|
||||
'portion': '100g',
|
||||
'from_diet': true,
|
||||
'state': state,
|
||||
};
|
||||
|
||||
test('parses commented_from_diet state', () {
|
||||
final model = PortionModel.fromJson(portionJson(state: 'commented_from_diet'));
|
||||
|
||||
expect(model.portionState, PortionState.commentedFromDiet);
|
||||
});
|
||||
|
||||
test('parses reviewed_from_diet state', () {
|
||||
final model = PortionModel.fromJson(portionJson(state: 'reviewed_from_diet'));
|
||||
|
||||
expect(model.portionState, PortionState.reviewedFromDiet);
|
||||
});
|
||||
|
||||
test('does not throw on unknown state from backend', () {
|
||||
final model = PortionModel.fromJson(portionJson(state: 'some_future_state'));
|
||||
|
||||
expect(model.portionState, PortionState.unknown);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user