Files
eatvio_app/test/fixtures/doubles/create_plan_doubles.dart
2026-10-12 08:50:33 +03:00

57 lines
1.8 KiB
Dart

import 'package:dio/dio.dart';
import 'package:eatvio_app/features/create_plan/repositories/create_plan_repository.dart';
import 'package:eatvio_app/features/create_plan/services/create_plan_service.dart';
class FixtureCreatePlanRepository extends CreatePlanRepository {
FixtureCreatePlanRepository()
: super(createPlanService: _NoopCreatePlanService());
final List<Map<String, dynamic>> createPlanRequests = <Map<String, dynamic>>[];
@override
Future<void> createPlan({required Map<String, dynamic> model}) async {
// Normalize request to match fixture format
final normalized = <String, dynamic>{
'name': model['name'],
'description': model['description_md'],
'duration': model['duration'],
'status': model['state'] == 'active' ? 'active' : 'draft',
};
// Extract options if present
if (model.containsKey('packets_count')) {
final options = <Map<String, dynamic>>[];
final packetsCount = model['packets_count'] as int;
for (int i = 1; i <= packetsCount; i++) {
final packetKey = 'packet${i}_options';
if (model.containsKey(packetKey)) {
final packet = model[packetKey] as Map<String, dynamic>;
options.add({
'title': packet['short'],
'price': packet['price'],
'description': packet['description_md'],
});
}
}
if (options.isNotEmpty) {
normalized['options'] = options;
}
}
createPlanRequests.add(normalized);
}
}
class _NoopCreatePlanService implements CreatePlanService {
@override
Future<void> createPlan({required FormData formData}) {
throw UnimplementedError('Not used in fixture tests');
}
@override
Future<void> updatePublishedPlan({required String slug, required FormData formData}) {
throw UnimplementedError('Not used in fixture tests');
}
}