diet-guard/app/test/services/kuchnia_autolog_ids_test.dart
Krzysztof kuhy Rudnicki 26d6a68ac0 Due-mode log screen, Claude button, photos
Action row 1A, due mode, catering auto-log rows with undo, relay interface, photo input.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWZHWP4KZ6x5TcXDBFC
2026-11-17 21:26:13 +01:00

85 lines
2.3 KiB
Dart

/// 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<String, dynamic> _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<String, dynamic>;
}
/// The payload meal the fixture case describes, as the panel sends it.
Map<String, Object?> _payloadMeal(Map<String, dynamic> 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<Map<String, dynamic>>();
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');
});
}