40 lines
1.5 KiB
Dart
40 lines
1.5 KiB
Dart
// 功能描述:充值待确认请求的存储隔离和损坏保护;版本: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);
|
||
}
|
||
});
|
||
}
|