已完成用户APP首期功能开发
交付用户端首期页面、配套接口、后台资源及测试文档。用户APP构建、静态分析和三个管理后台构建通过;完整测试仍有2项失败,后端模型注释检查未通过,详见交付记录。
This commit is contained in:
49
apps/user_app/test/domain/recharge_test.dart
Normal file
49
apps/user_app/test/domain/recharge_test.dart
Normal file
@@ -0,0 +1,49 @@
|
||||
// 功能描述:充值金额精度、协议完整性和到账事实校验;版本:1.0.0。
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:user_app/domain/models/recharge.dart';
|
||||
|
||||
void main() {
|
||||
test('金额按十进制精确转分,拒绝超精度和指数输入', () {
|
||||
expect(parseRechargeAmount('0.29'), 29);
|
||||
expect(parseRechargeAmount(' 100.1 '), 10010);
|
||||
expect(parseRechargeAmount('999999999.99'), 99999999999);
|
||||
for (final value in ['-1', '1e2', '1.001', '.5', '1.', 'NaN', '']) {
|
||||
expect(parseRechargeAmount(value), isNull, reason: value);
|
||||
}
|
||||
});
|
||||
|
||||
test('只有钱包充值完成状态才表示到账', () {
|
||||
RechargeRecord record(int status, int? paymentStatus) => RechargeRecord.fromJson({
|
||||
'identity': 'recharge-1',
|
||||
'amount': 10000,
|
||||
'recharge_status': status,
|
||||
'payment_status': paymentStatus,
|
||||
'created_at': '2026-09-11T00:00:00Z',
|
||||
});
|
||||
expect(record(10, 23).credited, isFalse);
|
||||
expect(record(10, 30).statusText, '支付已关闭,未入账');
|
||||
expect(record(23, null).credited, isTrue);
|
||||
expect(record(23, 30).statusText, '已到账');
|
||||
});
|
||||
|
||||
test('缺少协议允许读取配置,残缺协议必须拒绝', () {
|
||||
final json = <String, Object?>{'min_amount': 1, 'max_amount': 500000, 'channels': <Object>[]};
|
||||
expect(RechargeOptions.fromJson(json).agreement, isNull);
|
||||
for (final identity in ['', ' ']) {
|
||||
expect(
|
||||
() => RechargeOptions.fromJson({
|
||||
...json,
|
||||
'agreement': {
|
||||
'identity': identity,
|
||||
'version': 1,
|
||||
'body': '协议正文',
|
||||
},
|
||||
}),
|
||||
throwsFormatException,
|
||||
);
|
||||
}
|
||||
expect(() => RechargeOptions.fromJson({...json, 'min_amount': 0}), throwsFormatException);
|
||||
expect(() => RechargeOptions.fromJson({...json, 'max_amount': 0}), throwsFormatException);
|
||||
expect(() => rechargeCents(1.5), throwsFormatException);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user