/// The catering auto-log entry ids against the shared fixture. /// /// `tests/fixtures/kuchnia_autolog_ids.json` is generated by Python's stdlib /// `uuid.uuid5` (scripts/build_kuchnia_autolog_fixture.py), so this test /// checks a value Dart did not compute itself. library; import 'dart:convert'; import 'dart:io'; import 'package:diet_guard_app/models/kuchnia_dish.dart'; import 'package:diet_guard_app/services/kuchnia_autolog.dart'; import 'package:diet_guard_app/services/kuchnia_parse.dart'; import 'package:flutter_test/flutter_test.dart'; Map _fixture() { var dir = Directory.current; while (!File( '${dir.path}/tests/fixtures/kuchnia_autolog_ids.json', ).existsSync()) { dir = dir.parent; } return jsonDecode( File( '${dir.path}/tests/fixtures/kuchnia_autolog_ids.json', ).readAsStringSync(), ) as Map; } /// The payload meal the fixture case describes, as the panel sends it. Map _payloadMeal(Map c) => { if (c['delivery_meal_id'] != null) 'deliveryMealId': c['delivery_meal_id'], 'mealName': 'Obiad', 'mealPriority': 3, 'menuMealName': c['name'], 'nutrition': { 'weight': 300.0, 'calories': 400.0, 'protein': 25.0, 'carbohydrate': 45.0, 'fat': 12.0, }, }; void main() { final fixture = _fixture(); final cases = (fixture['cases'] as List).cast>(); test('the fixture uses the RFC URL namespace', () { expect(fixture['namespace'], '6ba7b811-9dad-11d1-80b4-00c04fd430c8'); expect(cases, isNotEmpty); }); for (final c in cases) { test('${c['name_string']} -> ${c['expected_id']}', () { final dish = parseMeal(_payloadMeal(c), 1)!; expect( kuchniaAutologId(c['delivery_date'] as String, dish), c['expected_id'], ); }); } test('the panel id never leaks into the bank record', () { final dish = parseMeal(_payloadMeal(cases.first), 1)!; expect(dish.toBankRecord().containsKey('dishId'), isFalse); expect(dish.dishId, '1001'); }); test('a dish with no id keys on its bank key', () { const dish = KuchniaDish( name: ' Zupa ', kcal: 1, proteinG: 0, carbsG: 0, fatG: 0, grams: 1, priority: 1, slotLabel: '', ); expect(dish.autologKey, 'zupa'); }); }