feat(client): 对接详情/播放/进度续看/收藏(K1 看剧闭环)+ 三态 UI
后端接口从 6 个扩到 13 个,全部走真数据:
- 新增 api:playback_api(/app/episodes/{id}/play)、watch_api(/app/watch/*)、
library_api(/app/favorites*);票据从 CatalogApi 搬到 PlaybackApi
- 新增 repository:PlaybackRepository(含票据 TTL 缓存,默认 10 分钟,时钟可注入)、
FavoriteRepository、WatchHistoryRepository 换成服务端模型(每剧一条续看记录,删掉 demoProfileId)
- PlayerLogic:起播前取票(拿不到给三态 UI,失败可重试);accessType 驱动锁定文案,
不在前端猜;签名地址原样交给播放器(只补 host,不动 path/query);
进度上报节流 5s → 10s,切集/退出/切后台各补一次,播完带 finished
- 续看定位:服务端记录里的那一集才 seek(其它集从头播),续看位置进详情/播放页时读一次
- FavoriteController:收藏以服务端为准,乐观更新 + 失败回滚;退出登录清空
- UI 三态:详情页(加载/失败可重试/空剧集 + 续看进度条 + 收藏按钮)、
播放页(票据加载中/失败可重试/后端判定不可播)、我的页(续看失败可重试、收藏三态、最近观看)
- l10n 新增 8 个键(en/zh/id 三份):网络/进度/收藏失败、锁定提示、续看文案等
测试:flutter test 188 全过(存量 27 个测试文件未跑红);新增票据过期重取、进度节流、
续看定位、收藏回滚、签名 query 原样保留、真实后端端到端联调(live_watch_flow)
This commit is contained in:
1 parent
94ff9f1177
commit
d7eff4ca59
48 files changed
+2411
-377
No files matched your search
@@ -0,0 +1,114 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:fruitshorts/core/data/models/auth_session.dart';
|
||||
import 'package:fruitshorts/core/data/remote/api_client.dart';
|
||||
import 'package:fruitshorts/core/data/remote/catalog_api.dart';
|
||||
import 'package:fruitshorts/core/data/remote/library_api.dart';
|
||||
import 'package:fruitshorts/core/data/remote/playback_api.dart';
|
||||
import 'package:fruitshorts/core/data/remote/watch_api.dart';
|
||||
|
||||
/// K1 端到端联调:直连本机客户端接口服务(8081),把"首页 → 详情 → 播放票据 →
|
||||
/// 上报进度 → 读回续看位置 → 收藏 → 收藏列表 → 取消收藏"整条链路走一遍。
|
||||
///
|
||||
/// 用一个一次性邮箱注册(需要登录态的接口才会通);服务没起时自动跳过。
|
||||
void main() {
|
||||
const baseUrl = 'http://127.0.0.1:8081';
|
||||
final email = 'k1.selftest.${DateTime.now().millisecondsSinceEpoch}@example.com';
|
||||
const password = 'Passw0rd!23';
|
||||
|
||||
AuthSession? session;
|
||||
final client = ApiClient(
|
||||
baseUrl: baseUrl,
|
||||
accessTokenReader: () => session?.accessToken,
|
||||
deviceIdReader: () async => 'k1-live-device',
|
||||
);
|
||||
final catalog = CatalogApi(client);
|
||||
final playback = PlaybackApi(client);
|
||||
final watch = WatchApi(client);
|
||||
final library = LibraryApi(client);
|
||||
|
||||
tearDownAll(client.close);
|
||||
|
||||
Future<bool> register() async {
|
||||
try {
|
||||
final raw = await client.post(
|
||||
'/app/auth/register',
|
||||
body: {
|
||||
'targetType': 'EMAIL',
|
||||
'target': email,
|
||||
'password': password,
|
||||
'nickname': 'K1 联调',
|
||||
'deviceId': 'k1-live-device',
|
||||
},
|
||||
);
|
||||
if (raw is! Map<String, dynamic>) return false;
|
||||
session = AuthSession.fromJson(raw);
|
||||
return true;
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
test('should_complete_the_watch_flow_when_backend_is_running', () async {
|
||||
if (!await register()) {
|
||||
markTestSkipped('客户端接口服务未启动,已跳过联调测试');
|
||||
return;
|
||||
}
|
||||
expect(session?.user.uid, isNotEmpty);
|
||||
|
||||
// 1) 首页 → 取第一部剧
|
||||
final feed = await catalog.homeFeed();
|
||||
expect(feed.dramas, isNotEmpty);
|
||||
final card = feed.dramas.first;
|
||||
expect(card.id, isNotEmpty);
|
||||
|
||||
// 2) 详情:剧集列表按集号升序,可播剧集带已签名地址
|
||||
final detail = await catalog.dramaDetail(card.id);
|
||||
expect(detail.id, card.id);
|
||||
expect(detail.episodes, isNotEmpty);
|
||||
final playable = detail.episodes
|
||||
.where((episode) => episode.videoUrl.isNotEmpty)
|
||||
.toList();
|
||||
if (playable.isEmpty) {
|
||||
markTestSkipped('这部演示剧没有可播剧集,已跳过播放相关断言');
|
||||
return;
|
||||
}
|
||||
|
||||
// 3) 播放票据:签名地址带 e/s,客户端原样使用
|
||||
final ticket = await playback.ticket(playable.first.id);
|
||||
expect(ticket.accessible, isTrue);
|
||||
expect(ticket.accessType, isNotEmpty);
|
||||
expect(ticket.playUrl, startsWith('/files/'));
|
||||
expect(ticket.playUrl, contains('e='));
|
||||
expect(ticket.playUrl, contains('s='));
|
||||
|
||||
// 4) 上报进度 → 读回续看位置
|
||||
const position = Duration(seconds: 42);
|
||||
final saved = await watch.saveProgress(
|
||||
episodeId: playable.first.id,
|
||||
position: position,
|
||||
duration: Duration(seconds: ticket.durationSec),
|
||||
);
|
||||
expect(saved?.episodeId, playable.first.id);
|
||||
expect(saved?.position, position);
|
||||
|
||||
final resume = await watch.progressOfDrama(card.id);
|
||||
expect(resume?.episodeId, playable.first.id);
|
||||
expect(resume?.position, position);
|
||||
|
||||
// 最近观看里能看到这部剧
|
||||
final recent = await watch.recent(limit: 20);
|
||||
expect(recent.map((item) => item.dramaId), contains(card.id));
|
||||
|
||||
// 5) 收藏 → 出现在收藏列表 → 取消收藏
|
||||
final savedState = await library.toggleFavorite(card.id);
|
||||
expect(savedState, isTrue);
|
||||
final favorites = await library.favorites();
|
||||
expect(favorites.map((drama) => drama.id), contains(card.id));
|
||||
|
||||
await library.removeFavorite(card.id);
|
||||
final afterRemove = await library.favorites();
|
||||
expect(afterRemove.map((drama) => drama.id), isNot(contains(card.id)));
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user