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.
 
 
 
 
 
 

73 lines
2.2 KiB

import 'package:eaimar/data/models/appconfig_model.dart';
import 'package:flutter_test/flutter_test.dart';
/// `user_getappconfig` 响应的契约测试:服务端少下发字段、下发 null,
/// 客户端都要能解出来,而不是整个 fromJson 抛 TypeError。
void main() {
test('完整响应正常解析', () {
final resp = UserGetAppConfigResp.fromJson({
'env': {'AGENT_TYPE': 'default'},
'agents': [
{
'id': 'a1',
'name': 'Emma',
'avatarUrl': '',
'description': '',
'tag': '',
'isOnline': true,
'voice': 'v',
'welcomeMessage': null,
'voiceWelcomeMessage': null,
'systemPrompt': 'hi',
'tools': null,
}
],
'mcps': {
'm': {'servername': 'm', 'url': 'u', 'type': 1, 'tools': ''}
},
'products': [
{
'id': 45091,
'factoryid': 1,
'devicetype': 0,
'devicename': 'Echo-one',
'productimage': null,
'version': '0.0.3',
'isforceupdate': false,
'iscontinuouschat': null,
'wakeupenable': null,
'broadcastpeertranslate': null,
'updatedescription': null,
'updatepackageaddress': null,
}
],
});
expect(resp.products.single.devicename, 'Echo-one');
expect(resp.agents.single.systemPrompt, 'hi');
expect(resp.mcps['m']!.type, 1);
});
test('顶层键缺失时给空集合,不抛', () {
final resp = UserGetAppConfigResp.fromJson({});
expect(resp.env, isEmpty);
expect(resp.agents, isEmpty);
expect(resp.mcps, isEmpty);
expect(resp.products, isEmpty);
});
test('产品缺 devicetype / factoryid / devicename 时用默认值', () {
final p = DBProduct.fromJson({'id': 1, 'version': '1.0.0'});
expect(p.devicetype, 0);
expect(p.factoryid, 0);
expect(p.devicename, '');
expect(p.version, '1.0.0');
expect(p.updateonmismatch, isNull);
});
test('agent 缺非空字段时用默认值', () {
final a = DBAgent.fromJson({'id': 'x'});
expect(a.name, '');
expect(a.isOnline, isFalse);
expect(a.voice, '');
});
}