forked from eatvio/eatvio_app
feat(insights): added kbju fetching for analitics
This commit is contained in:
@@ -49,7 +49,7 @@ void main() {
|
||||
expect(model.bmi.deltaText, contains('рост'));
|
||||
});
|
||||
|
||||
test('intra без wake/sleep и null в average/percent', () {
|
||||
test('пустой intra без wake/sleep; daily == null', () {
|
||||
final model = InsightsPayloadModel.fromJson(
|
||||
_fixture('insights_payload_minimal.json'),
|
||||
);
|
||||
@@ -57,8 +57,7 @@ void main() {
|
||||
expect(model.intra!.wake, isNull);
|
||||
expect(model.intra!.sleep, isNull);
|
||||
expect(model.intra!.bars, isEmpty);
|
||||
expect(model.daily!.average, isNull);
|
||||
expect(model.daily!.percent, isNull);
|
||||
expect(model.daily, isNull);
|
||||
expect(model.weight.last, isNull);
|
||||
});
|
||||
|
||||
|
||||
154
test/features/insights/models/insights_response_model_test.dart
Normal file
154
test/features/insights/models/insights_response_model_test.dart
Normal file
@@ -0,0 +1,154 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/features/insights/models/insights_response_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
Map<String, dynamic> _fixture(String name) =>
|
||||
jsonDecode(File('test/fixtures/insights/$name').readAsStringSync())
|
||||
as Map<String, dynamic>;
|
||||
|
||||
/// Контракт `GET /api/profile/insights*` (eatvio/eatvio#3017).
|
||||
void main() {
|
||||
group('InsightsResponseModel', () {
|
||||
test('полный ответ: data с weight/bmi/measure/daily/intra', () {
|
||||
final data = InsightsResponseModel.fromJson(
|
||||
_fixture('insights_response.json'),
|
||||
).data;
|
||||
|
||||
expect(data.weight.headline, '73.2');
|
||||
expect(data.measure.waist, [82, 80.5]);
|
||||
expect(data.daily!.kcal, hasLength(3));
|
||||
expect(data.intra!.bars, hasLength(2));
|
||||
});
|
||||
|
||||
test('daily.percent — изменение за период, а не процент от нормы', () {
|
||||
final daily = InsightsResponseModel.fromJson(
|
||||
_fixture('insights_response.json'),
|
||||
).data.daily!;
|
||||
|
||||
expect(daily.percent, 5);
|
||||
expect(daily.deltaText, 'Калораж вырос на 5% за период');
|
||||
});
|
||||
|
||||
test('нет КБЖУ за период: daily == null', () {
|
||||
final data = InsightsResponseModel.fromJson(
|
||||
_fixture('insights_response_empty.json'),
|
||||
).data;
|
||||
|
||||
expect(data.daily, isNull);
|
||||
});
|
||||
|
||||
test('пустые замеры: headline "—" и текст «Недостаточно данных»', () {
|
||||
final measure = InsightsResponseModel.fromJson(
|
||||
_fixture('insights_response_empty.json'),
|
||||
).data.measure;
|
||||
|
||||
expect(measure.labels, isEmpty);
|
||||
expect(measure.headline, '—');
|
||||
expect(measure.deltaText, 'Недостаточно данных');
|
||||
});
|
||||
|
||||
test('пустой день: intra приходит объектом с датами, без сна', () {
|
||||
final intra = InsightsResponseModel.fromJson(
|
||||
_fixture('insights_response_empty.json'),
|
||||
).data.intra!;
|
||||
|
||||
expect(intra.bars, isEmpty);
|
||||
expect(intra.satiety, isEmpty);
|
||||
expect(intra.mood, isEmpty);
|
||||
expect(intra.wake, isNull);
|
||||
expect(intra.sleep, isNull);
|
||||
expect(intra.date, '2026-11-09');
|
||||
expect(intra.maxDate, '2026-11-09');
|
||||
expect(intra.isToday, isTrue);
|
||||
});
|
||||
|
||||
test(
|
||||
'сокращённый пример из описания бэка разбирается без подписей сна',
|
||||
() {
|
||||
final data = InsightsResponseModel.fromJson(
|
||||
jsonDecode(
|
||||
jsonEncode({
|
||||
'data': {
|
||||
'weight': {
|
||||
'labels': ['30.10', '07.11'],
|
||||
'values': [80, 78],
|
||||
'last': 78,
|
||||
'delta': -2,
|
||||
'headline': '78',
|
||||
'unit': 'кг',
|
||||
'deltaText': 'Снизили на 2 кг за 3 месяца',
|
||||
},
|
||||
'bmi': {},
|
||||
'measure': {
|
||||
'labels': [],
|
||||
'waist': [],
|
||||
'chest': [],
|
||||
'hips': [],
|
||||
'headline': '—',
|
||||
'deltaText': 'Недостаточно данных',
|
||||
},
|
||||
'daily': {
|
||||
'labels': ['09.11'],
|
||||
'kcal': [250],
|
||||
'proteins': [10],
|
||||
'fats': [5],
|
||||
'carbs': [30],
|
||||
'average': 250,
|
||||
'percent': 0,
|
||||
'headline': '250',
|
||||
'deltaText': 'Калораж не изменился за период',
|
||||
},
|
||||
'intra': {
|
||||
'bars': [
|
||||
{'x': 12.5, 'p': 40, 'f': 45, 'c': 120},
|
||||
],
|
||||
'satiety': [
|
||||
{'x': 12.5, 'y': 4},
|
||||
],
|
||||
'mood': [
|
||||
{'x': 12.5, 'y': 3},
|
||||
],
|
||||
'wake': 7,
|
||||
'sleep': 23,
|
||||
'date': '2026-11-09',
|
||||
'maxDate': '2026-11-09',
|
||||
'dateLabel': 'Сегодня',
|
||||
'isToday': true,
|
||||
},
|
||||
},
|
||||
}),
|
||||
)
|
||||
as Map<String, dynamic>,
|
||||
).data;
|
||||
|
||||
expect(data.weight.values, [80, 78]);
|
||||
expect(data.daily!.percent, 0);
|
||||
expect(data.intra!.wake, 7);
|
||||
expect(data.intra!.wakeLabel, isNull);
|
||||
expect(data.intra!.wakeText, isNull);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('InsightsIntraResponseModel', () {
|
||||
test('ответ /insights/intra: data.intra', () {
|
||||
final intra = InsightsIntraResponseModel.fromJson(
|
||||
_fixture('insights_intra_response.json'),
|
||||
).data.intra;
|
||||
|
||||
expect(intra.date, '2026-11-09');
|
||||
expect(intra.bars, isNotEmpty);
|
||||
});
|
||||
|
||||
test('прошедший день: isToday == false', () {
|
||||
final intra = InsightsIntraResponseModel.fromJson(
|
||||
_fixture('insights_intra_response_yesterday.json'),
|
||||
).data.intra;
|
||||
|
||||
expect(intra.isToday, isFalse);
|
||||
expect(intra.dateLabel, '8 ноября');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user