forked from eatvio/eatvio_app
feat(insights): first isights impemetation
This commit is contained in:
54
test/fixtures/doubles/insights_doubles.dart
vendored
Normal file
54
test/fixtures/doubles/insights_doubles.dart
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:eatvio_app/features/insights/models/insights_payload_model.dart';
|
||||
import 'package:eatvio_app/features/insights/models/insights_period.dart';
|
||||
import 'package:eatvio_app/features/insights/repositories/insights_repository.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
InsightsPayloadModel loadInsightsPayloadFixture([String name = 'insights_payload.json']) {
|
||||
final json = jsonDecode(File('test/fixtures/insights/$name').readAsStringSync()) as Map<String, dynamic>;
|
||||
return InsightsPayloadModel.fromJson(json);
|
||||
}
|
||||
|
||||
/// Подмена [InsightsRepository] для виджет-тестов: без сети, с журналом вызовов.
|
||||
class FakeInsightsRepository extends Fake implements InsightsRepository {
|
||||
FakeInsightsRepository({InsightsPayloadModel? payload, this.error, this.heightCm = 176}) : payload = payload ?? loadInsightsPayloadFixture();
|
||||
|
||||
InsightsPayloadModel payload;
|
||||
|
||||
/// Если задан — выбрасывается из [getInsights] (например, [InsightsForbidden]).
|
||||
Object? error;
|
||||
int? heightCm;
|
||||
|
||||
final List<({String? slug, BodyPeriod period})> insightsRequests = [];
|
||||
final List<double> addedWeights = [];
|
||||
final List<({int chest, int waist, int hip})> addedCircumferences = [];
|
||||
|
||||
@override
|
||||
Future<int?> getHeightCm({String? slug}) async => heightCm;
|
||||
|
||||
@override
|
||||
Future<InsightsPayloadModel> getInsights({String? slug, required BodyPeriod bodyPeriod, int? heightCm}) async {
|
||||
insightsRequests.add((slug: slug, period: bodyPeriod));
|
||||
final failure = error;
|
||||
if (failure != null) {
|
||||
throw failure;
|
||||
}
|
||||
return payload;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addWeight({required double weight}) async {
|
||||
addedWeights.add(weight);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> addCircumference({
|
||||
required int chestCircumference,
|
||||
required int waistCircumference,
|
||||
required int hipCircumference,
|
||||
}) async {
|
||||
addedCircumferences.add((chest: chestCircumference, waist: waistCircumference, hip: hipCircumference));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user