add
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
// 支付模块模型解析单测
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
import 'package:video_app/services/payment_service.dart';
|
||||
|
||||
void main() {
|
||||
group('PackagesResult', () {
|
||||
test('fromJson 解析', () {
|
||||
final r = PackagesResult.fromJson(const {
|
||||
'packages': [
|
||||
{'id': 1, 'amount_yuan': 10, 'points': 100, 'bonus': 0},
|
||||
{'id': 3, 'amount_yuan': 100, 'points': 1000, 'bonus': 50},
|
||||
],
|
||||
'custom': {
|
||||
'enabled': true,
|
||||
'min_yuan': 1,
|
||||
'max_yuan': 10000,
|
||||
'points_per_yuan': 10,
|
||||
},
|
||||
'pay_methods': [
|
||||
{'method': 1, 'name': '支付宝'},
|
||||
{'method': 3, 'name': 'USDT (TRC20)'},
|
||||
],
|
||||
'usdt_rate': 7.2,
|
||||
});
|
||||
expect(r.packages.length, 2);
|
||||
expect(r.packages[1].totalPoints, 1050); // 1000 + 50
|
||||
expect(r.custom.enabled, isTrue);
|
||||
expect(r.custom.inRange(500), isTrue);
|
||||
expect(r.custom.inRange(20000), isFalse);
|
||||
expect(r.payMethods[1].isUsdt, isTrue);
|
||||
expect(r.usdtRate, 7.2);
|
||||
});
|
||||
|
||||
test('缺省兜底', () {
|
||||
final r = PackagesResult.fromJson(const {});
|
||||
expect(r.packages, isEmpty);
|
||||
expect(r.custom.enabled, isFalse);
|
||||
expect(r.custom.pointsPerYuan, 10);
|
||||
});
|
||||
});
|
||||
|
||||
group('RechargeOrderInfo', () {
|
||||
test('支付宝响应解析', () {
|
||||
final o = RechargeOrderInfo.fromJson(const {
|
||||
'order_no': 'R20261014123000001',
|
||||
'pay_method': 1,
|
||||
'amount_yuan': 30,
|
||||
'points': 300,
|
||||
'expire_at': '2026-10-14 13:00:00',
|
||||
'pay_params': {'order_string': 'alipay_sdk=...'},
|
||||
});
|
||||
expect(o.isUsdt, isFalse);
|
||||
expect(o.payParams['order_string'], 'alipay_sdk=...');
|
||||
expect(o.usdtAmount, isNull);
|
||||
});
|
||||
|
||||
test('USDT 响应解析', () {
|
||||
final o = RechargeOrderInfo.fromJson(const {
|
||||
'order_no': 'R20261014123000002',
|
||||
'pay_method': 3,
|
||||
'amount_yuan': 30,
|
||||
'points': 300,
|
||||
'usdt_rate': 7.2,
|
||||
'usdt_amount': '4.167',
|
||||
'receive_address': 'TXyz...abc',
|
||||
'network': 'TRC20',
|
||||
'expire_at': '2026-10-14 13:00:00',
|
||||
});
|
||||
expect(o.isUsdt, isTrue);
|
||||
expect(o.usdtAmount, '4.167');
|
||||
expect(o.network, 'TRC20');
|
||||
expect(o.payParams, isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('OrderStatusInfo', () {
|
||||
test('状态解析', () {
|
||||
final paid = OrderStatusInfo.fromJson(const {
|
||||
'order_no': 'R1',
|
||||
'status': 1,
|
||||
'status_text': '已支付',
|
||||
'points': 300,
|
||||
'paid_at': '2026-10-14 12:35:20',
|
||||
'wallet_points': 386,
|
||||
});
|
||||
expect(paid.isPaid, isTrue);
|
||||
expect(paid.isPending, isFalse);
|
||||
expect(paid.walletPoints, 386);
|
||||
|
||||
final pending = OrderStatusInfo.fromJson(const {
|
||||
'order_no': 'R2',
|
||||
'status': 0,
|
||||
});
|
||||
expect(pending.isPending, isTrue);
|
||||
expect(pending.points, 0);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user