109 lines
3.5 KiB
Dart
109 lines
3.5 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:meeyao_qianwen/features/divination/data/apis/divination_api.dart';
|
|
import 'package:meeyao_qianwen/features/divination/data/models/divination_params.dart';
|
|
|
|
void main() {
|
|
test('buildDivinationRunPayload contains required AG-UI fields', () {
|
|
final params = DivinationParams(
|
|
method: DivinationMethod.auto,
|
|
questionType: QuestionType.career,
|
|
question: '什么时候找到工作',
|
|
divinationTime: DateTime(2026, 4, 3, 18, 0, 2),
|
|
coinBalance: 0,
|
|
userId: 'u_test',
|
|
);
|
|
final payload = buildDivinationRunPayload(
|
|
params: params,
|
|
yaoStates: const <YaoType>[
|
|
YaoType.youngYang,
|
|
YaoType.youngYang,
|
|
YaoType.youngYang,
|
|
YaoType.oldYang,
|
|
YaoType.oldYin,
|
|
YaoType.youngYang,
|
|
],
|
|
threadId: 'de44f2fb-de0a-46b9-bbf2-e99ee36f2a2d',
|
|
runId: 'run_1775210431957',
|
|
clientNow: DateTime(2026, 4, 3, 18, 0, 31, 958),
|
|
);
|
|
|
|
expect(payload['state'], isA<Map<String, dynamic>>());
|
|
expect(payload['tools'], isA<List<dynamic>>());
|
|
expect(payload['context'], isA<List<dynamic>>());
|
|
|
|
final forwardedProps = payload['forwardedProps'] as Map<String, dynamic>;
|
|
expect(forwardedProps['runtime_mode'], 'chat');
|
|
final clientTime = forwardedProps['client_time'] as Map<String, dynamic>;
|
|
expect((clientTime['client_now_iso'] as String).endsWith('Z'), isTrue);
|
|
|
|
final divinationPayload =
|
|
forwardedProps['divinationPayload'] as Map<String, dynamic>;
|
|
expect(
|
|
(divinationPayload['divinationTimeIso'] as String).endsWith('Z'),
|
|
isTrue,
|
|
);
|
|
expect((divinationPayload['yaoLines'] as List<dynamic>).length, 6);
|
|
|
|
final messages = payload['messages'] as List<dynamic>;
|
|
expect(messages.length, 1);
|
|
final userMessage = messages.first as Map<String, dynamic>;
|
|
expect(userMessage['id'], isNotEmpty);
|
|
expect(userMessage['role'], 'user');
|
|
expect(userMessage['content'], '什么时候找到工作');
|
|
});
|
|
|
|
test('buildDivinationRunPayload throws when yaoStates length is not 6', () {
|
|
final params = DivinationParams(
|
|
method: DivinationMethod.auto,
|
|
questionType: QuestionType.career,
|
|
question: '测试',
|
|
divinationTime: DateTime(2026, 4, 3, 18, 0, 2),
|
|
coinBalance: 0,
|
|
userId: 'u_test',
|
|
);
|
|
|
|
expect(
|
|
() => buildDivinationRunPayload(
|
|
params: params,
|
|
yaoStates: const <YaoType>[YaoType.youngYang],
|
|
threadId: 'de44f2fb-de0a-46b9-bbf2-e99ee36f2a2d',
|
|
runId: 'run_1775210431957',
|
|
clientNow: DateTime(2026, 4, 3, 18, 0, 31, 958),
|
|
),
|
|
throwsArgumentError,
|
|
);
|
|
});
|
|
|
|
test(
|
|
'buildDivinationRunPayload throws when yaoStates contains undetermined',
|
|
() {
|
|
final params = DivinationParams(
|
|
method: DivinationMethod.auto,
|
|
questionType: QuestionType.career,
|
|
question: '测试',
|
|
divinationTime: DateTime(2026, 4, 3, 18, 0, 2),
|
|
coinBalance: 0,
|
|
userId: 'u_test',
|
|
);
|
|
|
|
expect(
|
|
() => buildDivinationRunPayload(
|
|
params: params,
|
|
yaoStates: const <YaoType>[
|
|
YaoType.youngYang,
|
|
YaoType.youngYang,
|
|
YaoType.youngYang,
|
|
YaoType.oldYang,
|
|
YaoType.oldYin,
|
|
YaoType.undetermined,
|
|
],
|
|
threadId: 'de44f2fb-de0a-46b9-bbf2-e99ee36f2a2d',
|
|
runId: 'run_1775210431957',
|
|
clientNow: DateTime(2026, 4, 3, 18, 0, 31, 958),
|
|
),
|
|
throwsArgumentError,
|
|
);
|
|
},
|
|
);
|
|
}
|