Files
rely/test/features/ai_digest/ai_digest_response_parser_test.dart
2026-05-19 19:17:35 +02:00

62 lines
2.3 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": "eventIdea",
"title": "Coffee tasting set",
"details": "Pick a small local sampler.",
"suggestedTiming": "2026-05-20T18:00:00Z",
"eventEndsAt": "2026-05-20T20:00:00Z",
"eventLocation": "Local roaster hall",
"eventUrl": "https://example.com/events/coffee",
"sourceUrls": ["https://example.com/events/coffee"],
"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.eventIdea);
expect(result.drafts.single.status, AiSuggestionStatus.pending);
expect(result.drafts.single.eventLocation, 'Local roaster hall');
expect(result.drafts.single.eventUrl, 'https://example.com/events/coffee');
expect(result.drafts.single.sourceUrls, <String>[
'https://example.com/events/coffee',
]);
});
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);
});
}