Files
video/app/test/asset_models_test.dart
2026-10-15 20:36:59 +08:00

104 lines
2.8 KiB
Dart

// 收益提现模块模型解析单测
import 'package:flutter_test/flutter_test.dart';
import 'package:video_app/screens/assets/assets_screen.dart';
import 'package:video_app/services/asset_service.dart';
void main() {
group('AssetWallet', () {
test('fromJson 解析(服务端字段)', () {
final w = AssetWallet.fromJson(const {
'assets': 1234.5,
'assets_value_yuan': 123.45,
'total_earned': 2000.0,
'total_withdrawn': 765.5,
'min_withdraw_assets': 100,
'has_pending_withdraw': true,
});
expect(w.assets, 1234.5);
expect(w.assetsValueYuan, 123.45);
expect(w.minWithdrawAssets, 100);
expect(w.hasPendingWithdraw, isTrue);
});
test('缺省兜底', () {
final w = AssetWallet.fromJson(const {});
expect(w.assets, 0);
expect(w.minWithdrawAssets, 100);
expect(w.hasPendingWithdraw, isFalse);
});
});
group('AssetRecord', () {
test('fromJson + 类型标签', () {
final r = AssetRecord.fromJson(const {
'id': 1,
'change_amount': 50.0,
'balance_after': 150.0,
'biz_type': 2,
'remark': '完整观看收益',
'created_at': '2026-10-15 10:00:00',
});
expect(r.bizTypeLabel, '观看收益');
expect(r.isExpense, isFalse);
final w = AssetRecord.fromJson(const {
'id': 2,
'change_amount': -100.0,
'balance_after': 50.0,
'biz_type': 4,
});
expect(w.bizTypeLabel, '提现');
expect(w.isExpense, isTrue);
// 未知类型
expect(
AssetRecord.fromJson(const {'id': 3, 'biz_type': 99}).bizTypeLabel,
'其他',
);
});
});
group('提现', () {
test('WithdrawResult 解析', () {
final r = WithdrawResult.fromJson(const {
'withdraw_no': 'W20261015001',
'assets': 100.0,
'amount_yuan': 10.0,
'status': 0,
'status_text': '待审核',
});
expect(r.withdrawNo, 'W20261015001');
expect(r.amountYuan, 10.0);
expect(r.statusText, '待审核');
});
test('WithdrawRecord 解析 + 渠道标签', () {
final r = WithdrawRecord.fromJson(const {
'withdraw_no': 'W1',
'assets': 500.0,
'amount_yuan': 50.0,
'channel': 3,
'status': 1,
'status_text': '已打款',
'created_at': '2026-10-15 11:00:00',
});
expect(r.channelLabel, 'USDT');
expect(r.status, 1);
expect(
WithdrawRecord.fromJson(const {'channel': 99}).channelLabel,
'未知',
);
});
});
group('fmtAssets', () {
test('整数不带小数点', () {
expect(fmtAssets(100.0), '100');
expect(fmtAssets(1234.5), '1234.50');
expect(fmtAssets(0), '0');
});
});
}