parser logic added

This commit is contained in:
davmar
2026-08-30 12:24:29 +02:00
parent 35d5c90d81
commit 3b698a3667
28 changed files with 3018 additions and 346 deletions
+42 -2
View File
@@ -3,8 +3,8 @@ import 'package:receipity/services/backup_format.dart';
void main() {
test('round-trips a backup document', () {
final original = const BackupDocument(
version: 1,
const original = BackupDocument(
version: 2,
exportedAt: '2026-08-29T12:00:00.000',
darkMode: true,
supermarkets: [
@@ -46,6 +46,24 @@ void main() {
'unit_price': 1.5,
},
],
shoppingLists: [
{
'id': 1,
'name': 'Weekly',
'created_at': '2026-08-29T12:00:00.000',
'updated_at': '2026-08-29T12:00:00.000',
},
],
shoppingListItems: [
{
'id': 1,
'list_id': 1,
'product_id': 1,
'name': 'Milk',
'checked': 0,
'sort_order': 0,
},
],
images: {'products/product_1.jpg': 'abc123'},
);
@@ -54,9 +72,31 @@ void main() {
expect(parsed.products.single['name'], 'Milk');
expect(parsed.shops.single['id'], 8);
expect(parsed.shopItems.single['product_id'], 1);
expect(parsed.shoppingLists.single['name'], 'Weekly');
expect(parsed.shoppingListItems.single['name'], 'Milk');
expect(parsed.images['products/product_1.jpg'], 'abc123');
});
test('accepts a version 1 backup without shopping lists', () {
const json = '''
{
"format": "receipity-backup",
"version": 1,
"exportedAt": "2026-08-29T12:00:00.000",
"darkMode": false,
"supermarkets": [],
"products": [],
"shops": [],
"shopItems": [],
"images": {}
}
''';
final parsed = BackupDocument.parse(json);
expect(parsed.version, 1);
expect(parsed.shoppingLists, isEmpty);
expect(parsed.shoppingListItems, isEmpty);
});
test('rejects a file that is not a Receipity backup', () {
expect(
() => BackupDocument.parse('{"hello":"world"}'),