f655adfbea
Migrate app code into canonical feature slices, add phone-only AI digest scheduling and review, wire local notification/background task support, and cover the flow with tests.
53 lines
1.8 KiB
Dart
53 lines
1.8 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:relationship_saver/features/ai_digest/application/ai_digest_response_parser.dart';
|
|
import 'package:relationship_saver/features/ai_digest/domain/ai_digest_models.dart';
|
|
|
|
void main() {
|
|
test('maps valid tokenized suggestions back to local person ids', () {
|
|
final AiDigestParseResult result = const AiDigestResponseParser().parse(
|
|
response: '''
|
|
{
|
|
"suggestions": [
|
|
{
|
|
"personToken": "person_001",
|
|
"kind": "giftIdea",
|
|
"title": "Coffee tasting set",
|
|
"details": "Pick a small local sampler.",
|
|
"suggestedTiming": "2026-05-20T18:00:00Z",
|
|
"confidence": 0.82,
|
|
"reason": "Matches known interests."
|
|
}
|
|
]
|
|
}
|
|
''',
|
|
tokenToPersonId: const <String, String>{'person_001': 'p-1'},
|
|
sourceRunId: 'run-1',
|
|
suggestedAt: DateTime(2026, 5, 16),
|
|
);
|
|
|
|
expect(result.success, isTrue);
|
|
expect(result.drafts, hasLength(1));
|
|
expect(result.drafts.single.personId, 'p-1');
|
|
expect(result.drafts.single.kind, AiSuggestionKind.giftIdea);
|
|
expect(result.drafts.single.status, AiSuggestionStatus.pending);
|
|
});
|
|
|
|
test('rejects unknown person tokens and malformed items', () {
|
|
final AiDigestParseResult result = const AiDigestResponseParser().parse(
|
|
response: '''
|
|
[
|
|
{"personToken": "person_404", "kind": "giftIdea", "title": "Bad"},
|
|
{"personToken": "person_001", "kind": "unknown", "title": "Bad"},
|
|
{"personToken": "person_001", "kind": "checkIn", "title": ""}
|
|
]
|
|
''',
|
|
tokenToPersonId: const <String, String>{'person_001': 'p-1'},
|
|
sourceRunId: 'run-1',
|
|
suggestedAt: DateTime(2026, 5, 16),
|
|
);
|
|
|
|
expect(result.success, isFalse);
|
|
expect(result.drafts, isEmpty);
|
|
});
|
|
}
|