You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
2.3 KiB
44 lines
2.3 KiB
import 'package:eaimar/data/models/appconfig.dart';
|
|
import 'package:eaimar/data/models/appconfig_model.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
/// AppConfig.cred 的取值口径:thirdsvcs 的 (服务 id, 字段) 优先,退回 env[老键名],两边都没有 → null。
|
|
/// 各业务服务 2026-09-14 起都改走它;口径错了表现为「某个能力鉴权失败」,不报配置错误。
|
|
void main() {
|
|
UserGetAppConfigResp build({Map<String, String> env = const {}, List<ThirdSvc> svcs = const []}) =>
|
|
UserGetAppConfigResp(env: env, agents: const [], mcps: const {}, products: const [], thirdsvcs: svcs);
|
|
|
|
test('thirdsvcs 有值时优先于 env', () {
|
|
AppConfig.initialize(build(
|
|
env: {'AZURE_SPEECH_KEY': 'from-env'},
|
|
svcs: [ThirdSvc(id: 'stt_azure', name: '', provider: 'azure', categories: '1', fields: {'subscription_key': 'from-svc'})],
|
|
));
|
|
expect(AppConfig.cred('stt_azure', 'subscription_key', 'AZURE_SPEECH_KEY'), 'from-svc');
|
|
expect(AppConfig.usingThirdSvcs, isTrue);
|
|
});
|
|
|
|
test('thirdsvcs 没有该服务/字段或为空串 → 退回 env', () {
|
|
AppConfig.initialize(build(
|
|
env: {'AZURE_SPEECH_KEY': 'from-env'},
|
|
svcs: [ThirdSvc(id: 'stt_azure', name: '', provider: 'azure', categories: '1', fields: {'subscription_key': ' '})],
|
|
));
|
|
expect(AppConfig.cred('stt_azure', 'subscription_key', 'AZURE_SPEECH_KEY'), 'from-env');
|
|
expect(AppConfig.cred('mt_azure', 'subscription_key', 'AZURE_SPEECH_KEY'), 'from-env');
|
|
});
|
|
|
|
test('两边都没有 → null(空串也算没有),调用方的 ?? 默认值才能生效', () {
|
|
AppConfig.initialize(build(env: {'AZURE_TRANSLATION_ENDPOINT': ''}));
|
|
expect(AppConfig.cred('mt_azure', 'endpoint', 'AZURE_TRANSLATION_ENDPOINT'), isNull);
|
|
expect(AppConfig.cred('mt_azure', 'endpoint', 'AZURE_TRANSLATION_ENDPOINT') ?? 'default', 'default');
|
|
expect(AppConfig.usingThirdSvcs, isFalse);
|
|
});
|
|
|
|
test('svcsByCategory 按逗号整项比对', () {
|
|
AppConfig.initialize(build(svcs: [
|
|
ThirdSvc(id: 'a', name: '', provider: '', categories: '1', fields: {}),
|
|
ThirdSvc(id: 'b', name: '', provider: '', categories: '10,11', fields: {}),
|
|
]));
|
|
expect(AppConfig.svcsByCategory(1).map((s) => s.id), ['a']);
|
|
expect(AppConfig.svcsByCategory(11).map((s) => s.id), ['b']);
|
|
});
|
|
}
|
|
|