testsAndMisc-archive/billsplit/test/eparagon_parser_test.dart
Krzysztof Rudnicki 4dd582a1df Move billsplit Flutter app into the monorepo
billsplit was a standalone Flutter app in ~/Downloads with one commit and no
git remote — that directory was the only copy of its history.

Three things the move needed beyond copying the tree:

- The root .gitignore silently swallowed 32 of its files (*.png, *.ico,
  *.manifest). Ignored files do not error on `git add`, they just vanish, so
  this would have committed an app that cannot build. Added a trailing block
  of ! overrides plus .binary-allowlist (which did not exist yet) — the
  documented in-repo exception for binaries a build genuinely needs. The
  ../testsAndMisc_binaries/ symlink scheme does not apply: those directories
  are gone, and a symlinked PNG breaks a fresh clone.

- billsplit/.github/workflows/ci.yaml was inert once nested; GitHub only reads
  workflows at the repository root. Relocated with a working-directory and a
  billsplit/** path filter.

- The app's coverage gate moved to python_pkg/billsplit_coverage/ so every
  Python file stays under python_pkg/, and gained a test suite at 100% branch
  coverage as that location requires. billsplit/ now holds only Dart.

Also replaces the stock Flutter icon with a family icon from the shared
generator. The glyph is a filled silhouette because the family's 72px stroke
cannot carry a fine torn edge, and the split is an evenodd-cut perforation so
the holes stay transparent on the foreground and monochrome layers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-03 12:22:22 +02:00

83 lines
2.8 KiB
Dart

import 'dart:io';
import 'package:billsplit/domain/eparagon_parser.dart';
import 'package:billsplit/domain/models.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
final fixture = File('test/fixtures/sample_receipt.json').readAsStringSync();
test('parses the real Biedronka e-paragon wrapper', () {
final res = parseEParagonDetailed(fixture);
final r = res.receipt;
// 49 goods lines + 1 deposit line.
expect(r.items.length, 50);
final deposit =
r.items.where((i) => i.category == Categories.deposit).toList();
expect(deposit.length, 1);
expect(deposit.single.totalGr, 700);
expect(deposit.single.qty, 14);
// Goods sum matches receipt sumaBrutto; paid total includes deposit.
final goods = r.items
.where((i) => i.category != Categories.deposit)
.fold(0, (s, i) => s + i.totalGr);
expect(goods, 59055);
expect(r.paidTotalGr, 59755);
expect(res.warnings, isEmpty);
// Alcohol detection: exactly vodka + beer, drinkers-only by default.
final alcohol =
r.items.where((i) => i.category == Categories.alcohol).toList();
expect(alcohol.length, 2);
expect(
alcohol.map((i) => i.name).join(' | ').toLowerCase(),
allOf(contains('wódka'), contains('piwo')),
);
for (final a in alcohol) {
expect(a.assignment.mode, AssignMode.drinkers);
}
expect(alcohol.fold(0, (s, i) => s + i.totalGr), 10872);
// Mixers tagged but split among everyone.
final mixers =
r.items.where((i) => i.category == Categories.mixer).toList();
expect(mixers.length, greaterThanOrEqualTo(4));
for (final m in mixers) {
expect(m.assignment.mode, AssignMode.everyone);
}
// Name cleanup: VAT letter stripped, spaces collapsed.
expect(r.items.first.name, 'Tonic');
// Weight-based quantity with comma decimal.
final kielbasa =
r.items.firstWhere((i) => i.name.startsWith('KiełbBrocka'));
expect(kielbasa.qty, closeTo(0.871, 1e-9));
// Discount captured (vodka -28.00).
final vodka = r.items.firstWhere((i) => i.name.startsWith('WódkaB'));
expect(vodka.discountGr, -2800);
expect(vodka.totalGr, 7998);
});
test('accepts bare JPK payload and bare JWS token', () {
final res = parseEParagonDetailed(fixture);
expect(res.receipt.items, isNotEmpty);
// Raw JWS from the wrapper should parse identically.
final jws = RegExp('"data":"([^"]+)"').firstMatch(fixture)!.group(1)!;
final fromJws = parseEParagon(jws);
expect(fromJws.items.length, res.receipt.items.length);
});
test('rejects garbage input with a clear error', () {
expect(
() => parseEParagon('not json'),
throwsA(isA<EParagonParseException>()),
);
expect(
() => parseEParagon('{"foo": 1}'),
throwsA(isA<EParagonParseException>()),
);
});
}