refactor(watch): 观看历史改用分页契约

This commit is contained in:
Zhou Weidong authored and trae-solo-agent committed 2026-10-22 13:21:27 +08:00
1 parent 1924b8626f
commit 5b2d8445dc
2 files changed
+34 -33

No files matched your search

+26 -30
View File
@@ -51,23 +51,13 @@ void main() {
expect(page.list.single.totalEpisodes, 68);
});
test('should_parse_recent_when_server_returns_legacy_list', () async {
test('should_return_empty_page_when_recent_list_is_empty', () async {
final adapter = FakeHttpAdapter(
(_) async => FakeHttpResponse(
jsonEncode({
'code': 0,
'message': 'ok',
'data': [
{
'dramaId': '5',
'episodeId': '7',
'positionMs': '203904',
'durationMs': '227882',
'finished': false,
'playCount': 8,
'updatedAt': '2026-10-21T15:17:05.419',
},
],
'data': {'total': '0', 'list': <Object>[]},
}),
),
);
@@ -77,25 +67,31 @@ void main() {
final page = await api.recent();
expect(page.total, 1);
expect(page.list.single.dramaId, '5');
expect(page.list.single.episodeId, '7');
expect(page.list.single.position.inMilliseconds, 203904);
});
test('should_return_empty_recent_when_data_is_null', () async {
final adapter = FakeHttpAdapter(
(_) async => FakeHttpResponse(
jsonEncode({'code': 0, 'message': 'ok', 'data': null}),
),
);
final api = WatchApi(
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
);
final page = await api.recent();
expect(page.total, 0);
expect(page.list, isEmpty);
});
test('should_throw_api_exception_when_recent_response_is_error', () async {
final adapter = FakeHttpAdapter(
(_) async => FakeHttpResponse(
jsonEncode({'code': 401, 'message': 'unauthorized', 'data': null}),
),
);
final api = WatchApi(
ApiClient(
baseUrl: 'http://127.0.0.1:8081',
adapter: adapter,
tokenRefresher: null,
),
);
await expectLater(
() => api.recent(),
throwsA(
isA<ApiException>()
.having((e) => e.code, 'code', 401)
.having((e) => e.message, 'message', 'unauthorized'),
),
);
});
}