forked from eatvio/eatvio_app
feat(insights): added kbju fetching for analitics
This commit is contained in:
@@ -31,24 +31,70 @@ void main() {
|
||||
};
|
||||
|
||||
test('parses commented_from_diet state', () {
|
||||
final model = PortionModel.fromJson(portionJson(state: 'commented_from_diet'));
|
||||
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'));
|
||||
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'));
|
||||
final model = PortionModel.fromJson(
|
||||
portionJson(state: 'some_future_state'),
|
||||
);
|
||||
|
||||
expect(model.portionState, PortionState.unknown);
|
||||
});
|
||||
});
|
||||
|
||||
group('DiaryDayModel.user (владелец дневника)', () {
|
||||
Map<String, dynamic> diaryJson({Object? user}) => {
|
||||
'id': 1,
|
||||
'date': '2026-11-09',
|
||||
'closed': 0,
|
||||
'comment': '',
|
||||
'state': {
|
||||
'has_chosen_diet': false,
|
||||
'has_chosen_plan': false,
|
||||
'last_state': null,
|
||||
},
|
||||
'meals': <dynamic>[],
|
||||
'chosen_plan_id': null,
|
||||
'day_of_chosen_diet': null,
|
||||
'chosen_diet': null,
|
||||
'user': ?user,
|
||||
};
|
||||
|
||||
test('user.slug попадает в entity как ownerSlug', () {
|
||||
final model = DiaryDayModel.fromJson(
|
||||
diaryJson(user: {'id': 3577, 'slug': 'id-3577'}),
|
||||
);
|
||||
|
||||
expect(model.owner?.id, 3577);
|
||||
expect(model.toEntity()!.ownerSlug, 'id-3577');
|
||||
});
|
||||
|
||||
test('старый ответ без user: ownerSlug == null', () {
|
||||
expect(DiaryDayModel.fromJson(diaryJson()).toEntity()!.ownerSlug, isNull);
|
||||
});
|
||||
|
||||
test('user.slug == null (у владельца нет slug): ownerSlug == null', () {
|
||||
final model = DiaryDayModel.fromJson(
|
||||
diaryJson(user: {'id': 1, 'slug': null}),
|
||||
);
|
||||
|
||||
expect(model.toEntity()!.ownerSlug, isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('DiaryDayWrapperModel', () {
|
||||
test('fromJson parses diary correctly', () {
|
||||
final json = {
|
||||
@@ -57,7 +103,11 @@ void main() {
|
||||
'date': '2024-01-15',
|
||||
'closed': 0,
|
||||
'comment': 'Test comment',
|
||||
'state': {'has_chosen_diet': false, 'has_chosen_plan': false, 'last_state': null},
|
||||
'state': {
|
||||
'has_chosen_diet': false,
|
||||
'has_chosen_plan': false,
|
||||
'last_state': null,
|
||||
},
|
||||
'meals': [],
|
||||
'chosen_plan_id': null,
|
||||
'day_of_chosen_diet': null,
|
||||
@@ -78,7 +128,11 @@ void main() {
|
||||
date: '2024-01-15',
|
||||
closed: 0,
|
||||
comment: 'Test comment',
|
||||
typeOfDiary: TypeOfDiaryModel(hasChosenDiet: false, hasChosenPlan: false, diaryState: null),
|
||||
typeOfDiary: TypeOfDiaryModel(
|
||||
hasChosenDiet: false,
|
||||
hasChosenPlan: false,
|
||||
diaryState: null,
|
||||
),
|
||||
meals: [],
|
||||
chosenPlanId: null,
|
||||
dayOfChosenDiet: null,
|
||||
@@ -119,7 +173,12 @@ void main() {
|
||||
|
||||
group('DiaryPhotoModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {'id': 10, 'original_name': 'photo.jpg', 'path': '/path/to/photo.jpg', 'size': 1024};
|
||||
final json = {
|
||||
'id': 10,
|
||||
'original_name': 'photo.jpg',
|
||||
'path': '/path/to/photo.jpg',
|
||||
'size': 1024,
|
||||
};
|
||||
|
||||
final model = DiaryPhotoModel.fromJson(json);
|
||||
|
||||
@@ -130,7 +189,12 @@ void main() {
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const model = DiaryPhotoModel(id: 10, originalName: 'photo.jpg', path: '/path/to/photo.jpg', size: 1024);
|
||||
const model = DiaryPhotoModel(
|
||||
id: 10,
|
||||
originalName: 'photo.jpg',
|
||||
path: '/path/to/photo.jpg',
|
||||
size: 1024,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
@@ -201,7 +265,11 @@ void main() {
|
||||
|
||||
group('ProductInMeal', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {'product_name': 'Banana', 'portion': '1 piece', 'quantity': 2};
|
||||
final json = {
|
||||
'product_name': 'Banana',
|
||||
'portion': '1 piece',
|
||||
'quantity': 2,
|
||||
};
|
||||
|
||||
final model = ProductInMeal.fromJson(json);
|
||||
|
||||
@@ -211,7 +279,11 @@ void main() {
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const model = ProductInMeal(productName: 'Banana', portion: '1 piece', quantity: 2);
|
||||
const model = ProductInMeal(
|
||||
productName: 'Banana',
|
||||
portion: '1 piece',
|
||||
quantity: 2,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
@@ -228,7 +300,11 @@ void main() {
|
||||
date: '2024-01-15',
|
||||
closed: 0,
|
||||
comment: 'Test',
|
||||
typeOfDiary: TypeOfDiaryModel(hasChosenDiet: false, hasChosenPlan: false, diaryState: null),
|
||||
typeOfDiary: TypeOfDiaryModel(
|
||||
hasChosenDiet: false,
|
||||
hasChosenPlan: false,
|
||||
diaryState: null,
|
||||
),
|
||||
meals: [],
|
||||
chosenPlanId: null,
|
||||
dayOfChosenDiet: null,
|
||||
@@ -248,7 +324,11 @@ void main() {
|
||||
retire: '22:00',
|
||||
closed: 0,
|
||||
comment: 'Test comment',
|
||||
typeOfDiary: TypeOfDiaryModel(hasChosenDiet: false, hasChosenPlan: false, diaryState: null),
|
||||
typeOfDiary: TypeOfDiaryModel(
|
||||
hasChosenDiet: false,
|
||||
hasChosenPlan: false,
|
||||
diaryState: null,
|
||||
),
|
||||
meals: [],
|
||||
chosenPlanId: null,
|
||||
dayOfChosenDiet: null,
|
||||
@@ -272,7 +352,11 @@ void main() {
|
||||
date: '2024-01-15',
|
||||
closed: 0,
|
||||
comment: 'Test',
|
||||
typeOfDiary: TypeOfDiaryModel(hasChosenDiet: true, hasChosenPlan: false, diaryState: null),
|
||||
typeOfDiary: TypeOfDiaryModel(
|
||||
hasChosenDiet: true,
|
||||
hasChosenPlan: false,
|
||||
diaryState: null,
|
||||
),
|
||||
meals: [],
|
||||
chosenPlanId: null,
|
||||
dayOfChosenDiet: 5,
|
||||
|
||||
Reference in New Issue
Block a user