The dashboard (Raspberry Pi 3.5" screen + web pages), the end-to-end encrypted sync mailbox (PHP + SQLite) and the Android companion app (Flutter), with docs, clean-install checks and screenshots made from demo data. Built mostly with an AI coding assistant; not yet reviewed line by line by a human (see README and SECURITY.md). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
45 lines
2.4 KiB
Dart
45 lines
2.4 KiB
Dart
// Products kept from the archive ("food.product", food_model.dart): stored as the dashboard's db.save_product
|
|
// does (uid "p:<food_id>"), found again by id / barcode / name (folded), and their added sugar.
|
|
import 'dart:io';
|
|
|
|
import 'package:dash_app/health/food_model.dart';
|
|
import 'package:dash_app/health/sugar.dart';
|
|
import 'package:dash_app/sync/store.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
void main() {
|
|
final store = SyncStore('${Directory.systemTemp.createTempSync('product').path}/d.db', 'test00000000');
|
|
final item = {
|
|
'id': 24032663211215, 'name': 'Zarte Haferflocken', 'brand': 'Kölln', 'barcode': '4032663211215', 'countries': 'germany',
|
|
'category': 'Kölln · Rolled oats', 'nutriscore': 'a', 'nova': 1, 'labels': null, 'sugars_in': '', 'dairy': 0, 'added_sugar': null,
|
|
'per100': {'kcal': 372, 'protein': 13.5, 'carbs': 58.7, 'sugar': 0.7, 'fat': 7},
|
|
'portions': [{'label': 'serving (40 g)', 'grams': 40}],
|
|
};
|
|
|
|
test('kept, found again, synced under p:<id>', () {
|
|
final f = keepProduct(store, item)!;
|
|
expect(f.foodId, 24032663211215);
|
|
expect(f.portions.single.grams, 40);
|
|
expect(store.row(tProduct, 'p:24032663211215')!['food_id'], 24032663211215);
|
|
expect(keptProduct(store, 24032663211215)!.name, 'Zarte Haferflocken');
|
|
expect(keptByBarcode(store, '4032663211215').single.brand, 'Kölln');
|
|
expect(keptProducts(store, 'kolln hafer', fold: fold).single.foodId, 24032663211215);
|
|
expect(keptProducts(store, 'muesli', fold: fold), isEmpty);
|
|
});
|
|
|
|
test('not a product: refused', () {
|
|
expect(keepProduct(store, {...item, 'id': 123}), isNull);
|
|
expect(keepProduct(store, {...item, 'name': ' '}), isNull);
|
|
});
|
|
|
|
test('added sugar: the label figure first, else its ingredients', () {
|
|
final oats = keepProduct(store, item)!;
|
|
expect(foodPart(oats, 0.7, 100), 0); // sugars_in "" → natural
|
|
final cereal = keepProduct(store, {...item, 'id': 20000000000017, 'name': 'Choco cereal', 'sugars_in': 'sugar',
|
|
'added_sugar': 20, 'per100': {'kcal': 390, 'sugar': 25}})!;
|
|
expect(foodPart(cereal, 25, 100), 20); // the label's 20 of 25 g
|
|
final zero = keepProduct(store, {...item, 'id': 20000000000018, 'name': 'Wafer', 'nova': 4, 'sugars_in': 'sugar', 'added_sugar': 0,
|
|
'per100': {'kcal': 500, 'sugar': 30}})!;
|
|
expect(foodPart(zero, 30, 100), 30); // "0 added" yet sugar in the ingredients: the 0 is ignored
|
|
});
|
|
}
|