feat(app): 完成 P0 钱包解锁、下载落盘与手机号登录

This commit is contained in:
Zhou Weidong committed 2026-10-19 23:46:47 +08:00
1 parent de941c841c
commit 136ee74618
47 files changed
+3264 -70

No files matched your search

+81
View File
@@ -0,0 +1,81 @@
// Author: fruit.com.cn
import 'dart:convert';
import 'package:flutter_test/flutter_test.dart';
import 'package:fruitshorts/core/data/remote/api_client.dart';
import 'package:fruitshorts/core/data/remote/commerce_api.dart';
import '../support/fake_http_adapter.dart';
void main() {
test('should_parse_wallet_and_ledger_when_server_returns_string_ids', () async {
final adapter = FakeHttpAdapter(
(options) async => FakeHttpResponse(
jsonEncode({
'code': 0,
'message': 'ok',
'data': {
'wallet': {
'id': '2111012753262120962',
'coinBalance': '320',
'totalRechargedCoin': '500',
'totalConsumedCoin': '180',
'totalRefundedCoin': '0',
},
'ledger': [
{
'id': '2111012753262120963',
'changeAmount': '-50',
'balanceAfter': '320',
'bizType': 'UNLOCK',
'remark': '解锁第 3 集',
'createdAt': '2026-10-19 10:00:00',
},
],
},
}),
),
);
final api = CommerceApi(
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
);
final snapshot = await api.wallet();
expect(adapter.requests.single.uri.path, '/app/wallet');
expect(snapshot.wallet.coinBalance, 320);
expect(snapshot.ledger.single.id, '2111012753262120963');
expect(snapshot.ledger.single.changeAmount, -50);
});
test('should_post_unlock_for_episode_when_requested', () async {
final adapter = FakeHttpAdapter(
(options) async => FakeHttpResponse(
jsonEncode({
'code': 0,
'message': 'ok',
'data': {
'episodeId': '12',
'dramaId': '5',
'unlocked': true,
'accessType': 'UNLOCKED',
'coinCost': '50',
'coinBalance': '270',
},
}),
),
);
final api = CommerceApi(
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
);
final result = await api.unlock('12');
expect(adapter.requests.single.method, 'POST');
expect(adapter.requests.single.uri.path, '/app/episodes/12/unlock');
expect(result.unlocked, isTrue);
expect(result.coinCost, 50);
expect(result.coinBalance, 270);
});
}