Files
OnBudget/test/features/notification_parsing/parser/draft_codec_test.dart
T
2026-05-30 00:18:06 +03:00

68 lines
2.5 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:new_budget/src/core/database/converters/enum_converters.dart';
import 'package:new_budget/src/features/notification_parsing/data/parser/draft_codec.dart';
import 'package:new_budget/src/features/notification_parsing/domain/entities/parse_draft.dart';
import 'package:new_budget/src/features/notification_parsing/domain/entities/rule_suggestion.dart';
import 'package:new_budget/src/features/notification_parsing/domain/enums.dart';
void main() {
group('draft codec round-trip', () {
test('full draft + suggestion survives encode/decode', () {
final draft = ParseDraft(
rawMessageId: 'm1',
type: TransactionType.expense,
amount: 124000,
currency: 'RUB',
cardLast4: '3456',
merchantRaw: 'PYATEROCHKA 14',
counterpartyPhone: '+79991234567',
dateTime: DateTime(2026, 5, 29, 14, 5),
kind: TxKind.purchase,
accountId: 'a1',
merchantCanonical: 'PYATEROCHKA',
categoryId: 'c1',
source: ParseSource.regex,
);
const sugg = RuleSuggestion(
merchantRaw: 'PYATEROCHKA 14',
merchantCanonical: 'PYATEROCHKA',
categoryId: 'c1',
categoryName: 'Продукты',
accountId: 'a1',
);
final decoded = decodeDraftBundle(encodeDraftBundle(draft, sugg));
expect(decoded, isNotNull);
expect(decoded!.draft.amount, 124000);
expect(decoded.draft.type, TransactionType.expense);
expect(decoded.draft.kind, TxKind.purchase);
expect(decoded.draft.cardLast4, '3456');
expect(decoded.draft.merchantRaw, 'PYATEROCHKA 14');
expect(decoded.draft.dateTime, DateTime(2026, 5, 29, 14, 5));
expect(decoded.draft.source, ParseSource.regex);
expect(decoded.suggestion, isNotNull);
expect(decoded.suggestion!.merchantCanonical, 'PYATEROCHKA');
expect(decoded.suggestion!.categoryName, 'Продукты');
});
test('draft without suggestion', () {
final draft = ParseDraft(
rawMessageId: 'm1',
type: TransactionType.income,
amount: 500000,
source: ParseSource.regex,
);
final decoded = decodeDraftBundle(encodeDraftBundle(draft, null));
expect(decoded, isNotNull);
expect(decoded!.suggestion, isNull);
expect(decoded.draft.type, TransactionType.income);
expect(decoded.draft.currency, 'RUB');
});
test('null / empty json → null', () {
expect(decodeDraftBundle(null), isNull);
expect(decodeDraftBundle(''), isNull);
});
});
}