后端接口从 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)
79 lines
2.5 KiB
Dart
79 lines
2.5 KiB
Dart
import 'package:flutter_test/flutter_test.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/playback_api.dart';
|
|
|
|
/// 联调测试:直连本机客户端接口服务(8081)。
|
|
/// 服务没启动时自动跳过,不影响日常 `flutter test`。
|
|
void main() {
|
|
final client = ApiClient(baseUrl: 'http://127.0.0.1:8081');
|
|
final api = CatalogApi(client);
|
|
final playback = PlaybackApi(client);
|
|
|
|
tearDownAll(client.close);
|
|
|
|
Future<bool> serverUp() async {
|
|
try {
|
|
await api.homeFeed();
|
|
return true;
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
test('should_parse_banner_and_sections_when_home_feed_is_fetched', () async {
|
|
if (!await serverUp()) {
|
|
markTestSkipped('客户端接口服务未启动,已跳过联调测试');
|
|
return;
|
|
}
|
|
final feed = await api.homeFeed();
|
|
expect(feed.sections, isNotEmpty);
|
|
expect(feed.dramas, isNotEmpty);
|
|
final card = feed.dramas.first;
|
|
expect(card.id, isNotEmpty);
|
|
expect(card.title, isNotEmpty);
|
|
expect(card.posterUrl, startsWith('/files/'));
|
|
});
|
|
|
|
test('should_order_episodes_by_number_and_attach_url_when_detail_is_fetched', () async {
|
|
if (!await serverUp()) {
|
|
markTestSkipped('客户端接口服务未启动,已跳过联调测试');
|
|
return;
|
|
}
|
|
final feed = await api.homeFeed();
|
|
final card = feed.dramas.first;
|
|
final detail = await api.dramaDetail(card.id);
|
|
|
|
expect(detail.id, card.id);
|
|
expect(detail.episodes, isNotEmpty);
|
|
final numbers = detail.episodes.map((episode) => episode.number).toList();
|
|
expect(numbers, orderedEquals([...numbers]..sort()));
|
|
for (final episode in detail.episodes) {
|
|
if (episode.locked) {
|
|
expect(episode.videoUrl, isEmpty);
|
|
} else {
|
|
expect(episode.videoUrl, startsWith('/files/'));
|
|
}
|
|
}
|
|
});
|
|
|
|
test('should_return_play_url_when_episode_is_playable', () async {
|
|
if (!await serverUp()) {
|
|
markTestSkipped('客户端接口服务未启动,已跳过联调测试');
|
|
return;
|
|
}
|
|
final feed = await api.homeFeed();
|
|
final detail = await api.dramaDetail(feed.dramas.first.id);
|
|
final playable = detail.episodes
|
|
.where((episode) => episode.videoUrl.isNotEmpty)
|
|
.toList();
|
|
if (playable.isEmpty) {
|
|
return;
|
|
}
|
|
|
|
final ticket = await playback.ticket(playable.first.id);
|
|
expect(ticket.accessible, isTrue);
|
|
expect(ticket.playUrl, startsWith('/files/'));
|
|
});
|
|
}
|