057c11eee2
- RoutingProfile/RoutingRule/Builtin 手写 fromJson/toJson/copyWith,对齐服务端 GET/POST /v1/me/routing 契约;enabled 缺省容错默认 true,toJson 恒输出该字段 - AccountApi.routingProfile()/saveRoutingProfile() 封装两端点 - RoutingProfileNotifier(AsyncNotifier):addRule/removeRule/updateRule/reorder/ setMode/setBuiltin 均本地乐观更新后落盘;save() 失败整体回退到变更前 state 并 rethrow(不静默吞,交调用方处理)——Riverpod asyncTransition 的 seamless copyWithPrevious 会用当前已存 state 覆盖手动挂的错误值,故不用 AsyncError 路径,改走显式回退
40 lines
1.5 KiB
Dart
40 lines
1.5 KiB
Dart
// routing_profile_model_test.dart — RoutingProfile/RoutingRule JSON 无损往返。
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pangolin_vpn/models/routing_profile.dart';
|
|
|
|
void main() {
|
|
test('RoutingProfile round-trips json', () {
|
|
const j = {
|
|
'mode': 'rule',
|
|
'builtin': {'china_direct': true, 'lan_direct': true, 'private_via_tunnel': true},
|
|
'rules': [
|
|
{'type': 'domain_suffix', 'value': 'x.com', 'action': 'direct', 'note': 'ci', 'enabled': true}
|
|
],
|
|
'final': 'proxy',
|
|
};
|
|
final p = RoutingProfile.fromJson(j);
|
|
expect(p.mode, 'rule');
|
|
expect(p.rules.single.value, 'x.com');
|
|
expect(p.toJson(), j); // 无损往返
|
|
});
|
|
|
|
test('RoutingRule enabled 缺省容错默认 true', () {
|
|
final r = RoutingRule.fromJson({'type': 'domain', 'value': 'a.com', 'action': 'proxy'});
|
|
expect(r.enabled, isTrue);
|
|
});
|
|
|
|
test('RoutingRule 构造默认 enabled=true 且 toJson 恒输出 enabled 字段', () {
|
|
const r = RoutingRule(type: 'domain', value: 'a.com', action: 'proxy');
|
|
expect(r.enabled, isTrue);
|
|
expect(r.toJson().containsKey('enabled'), isTrue);
|
|
expect(r.toJson()['enabled'], isTrue);
|
|
});
|
|
|
|
test('RoutingProfile.fromJson 无档案默认(builtin 缺省)容错', () {
|
|
final p = RoutingProfile.fromJson({'mode': 'global', 'rules': [], 'final': 'direct'});
|
|
expect(p.builtin.chinaDirect, isTrue);
|
|
expect(p.builtin.lanDirect, isTrue);
|
|
expect(p.builtin.privateViaTunnel, isTrue);
|
|
});
|
|
}
|