79 lines
2.2 KiB
Dart
79 lines
2.2 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:receipity/services/backup_format.dart';
|
|
|
|
void main() {
|
|
test('round-trips a backup document', () {
|
|
final original = const BackupDocument(
|
|
version: 1,
|
|
exportedAt: '2026-08-29T12:00:00.000',
|
|
darkMode: true,
|
|
supermarkets: [
|
|
{'id': 1, 'name': 'Jumbo', 'color': 0xFFEEC21B, 'sort_order': 0},
|
|
],
|
|
products: [
|
|
{
|
|
'id': 1,
|
|
'name': 'Milk',
|
|
'normalized_name': 'MILK',
|
|
'last_price': 1.5,
|
|
'times_seen': 2,
|
|
'favourite': 1,
|
|
'image_path': 'products/product_1.jpg',
|
|
'supermarket': 'Jumbo',
|
|
'notes': 'Organic',
|
|
'created_at': '2026-08-29T12:00:00.000',
|
|
'updated_at': '2026-08-29T12:00:00.000',
|
|
},
|
|
],
|
|
shops: [
|
|
{
|
|
'id': 8,
|
|
'supermarket': 'Jumbo',
|
|
'shopped_at': '2026-08-29T12:00:00.000',
|
|
'receipt_image_path': 'receipts/shop_8.jpg',
|
|
'total': 1.5,
|
|
'created_at': '2026-08-29T12:00:00.000',
|
|
},
|
|
],
|
|
shopItems: [
|
|
{
|
|
'id': 1,
|
|
'shop_id': 8,
|
|
'product_id': 1,
|
|
'name': 'Milk',
|
|
'price': 1.5,
|
|
'quantity': 1,
|
|
'unit_price': 1.5,
|
|
},
|
|
],
|
|
images: {'products/product_1.jpg': 'abc123'},
|
|
);
|
|
|
|
final parsed = BackupDocument.parse(original.encode());
|
|
expect(parsed.darkMode, isTrue);
|
|
expect(parsed.products.single['name'], 'Milk');
|
|
expect(parsed.shops.single['id'], 8);
|
|
expect(parsed.shopItems.single['product_id'], 1);
|
|
expect(parsed.images['products/product_1.jpg'], 'abc123');
|
|
});
|
|
|
|
test('rejects a file that is not a Receipity backup', () {
|
|
expect(
|
|
() => BackupDocument.parse('{"hello":"world"}'),
|
|
throwsFormatException,
|
|
);
|
|
});
|
|
|
|
test('maps stored photo paths to backup keys', () {
|
|
expect(
|
|
backupImageKey('/data/app_flutter/products/product_12.jpg'),
|
|
'products/product_12.jpg',
|
|
);
|
|
expect(
|
|
backupImageKey('/data/app_flutter/receipts/shop_3.jpg'),
|
|
'receipts/shop_3.jpg',
|
|
);
|
|
expect(backupImageKey(null), isNull);
|
|
});
|
|
}
|