Files
platforms/apps/user_app/test/domain/recharge_draft_test.dart
czl231 3ef33b531d 已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
2026-09-13 00:57:32 +08:00

40 lines
1.5 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 功能描述充值待确认请求的存储隔离和损坏保护版本1.0.0。
import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
import 'package:user_app/data/services/recharge_draft_store.dart';
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
const draft = PendingRecharge(
request: 'request-1',
amount: 29,
channel: 'alipay',
payType: 'wap',
);
test('重开存储恢复同一请求,环境和账号分别隔离', () async {
FlutterSecureStorage.setMockInitialValues({});
final store = SecureRechargeDraftStore();
await store.write('api-a#alice', draft);
expect((await SecureRechargeDraftStore().read('api-a#alice'))?.request, 'request-1');
expect((await store.read('api-a#alice'))?.amount, 29);
expect(await store.read('api-a#bob'), isNull);
expect(await store.read('api-b#alice'), isNull);
await store.delete('api-a#bob');
expect(await store.read('api-a#alice'), isNotNull);
await store.delete('api-a#alice');
expect(await store.read('api-a#alice'), isNull);
});
test('损坏请求不能静默当作未创建禁止Mock渠道和无效金额', () {
for (final patch in <Map<String, Object?>>[
{'schema': 2},
{'request': ''},
{'amount': 0},
{'amount': 1.5},
{'channel': 'mock'},
{'channel': 'wechat', 'pay_type': 'wap'},
]) {
expect(() => PendingRecharge.fromJson({...draft.toJson(), ...patch}), throwsFormatException);
}
});
}