merge: 观看历史改用分页契约
This commit is contained in:
commit
295c21513c
2 files changed
+34
-33
No files matched your search
@@ -40,7 +40,7 @@ class WatchApi {
|
|||||||
return data is Map<String, dynamic> ? WatchProgress.fromJson(data) : null;
|
return data is Map<String, dynamic> ? WatchProgress.fromJson(data) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 最近观看分页(服务端已按更新时间倒序)。
|
/// 最近观看分页:`pageIndex`/`pageSize`,解包 `PageResult`。
|
||||||
Future<PageResult<WatchProgress>> recent({
|
Future<PageResult<WatchProgress>> recent({
|
||||||
int pageIndex = 1,
|
int pageIndex = 1,
|
||||||
int pageSize = 20,
|
int pageSize = 20,
|
||||||
@@ -49,8 +49,13 @@ class WatchApi {
|
|||||||
'/app/watch/recent',
|
'/app/watch/recent',
|
||||||
query: {'pageIndex': '$pageIndex', 'pageSize': '$pageSize'},
|
query: {'pageIndex': '$pageIndex', 'pageSize': '$pageSize'},
|
||||||
);
|
);
|
||||||
// 线上可能仍返回 List;分页壳与纯数组都要能渲染。
|
if (data is! Map) {
|
||||||
return PageResult.parse(data, WatchProgress.fromJson);
|
return const PageResult();
|
||||||
|
}
|
||||||
|
return PageResult.fromJson(
|
||||||
|
Map<String, dynamic>.from(data),
|
||||||
|
WatchProgress.fromJson,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 删除某部剧的观看记录(记录页清单条用)。
|
/// 删除某部剧的观看记录(记录页清单条用)。
|
||||||
|
|||||||
@@ -51,23 +51,13 @@ void main() {
|
|||||||
expect(page.list.single.totalEpisodes, 68);
|
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(
|
final adapter = FakeHttpAdapter(
|
||||||
(_) async => FakeHttpResponse(
|
(_) async => FakeHttpResponse(
|
||||||
jsonEncode({
|
jsonEncode({
|
||||||
'code': 0,
|
'code': 0,
|
||||||
'message': 'ok',
|
'message': 'ok',
|
||||||
'data': [
|
'data': {'total': '0', 'list': <Object>[]},
|
||||||
{
|
|
||||||
'dramaId': '5',
|
|
||||||
'episodeId': '7',
|
|
||||||
'positionMs': '203904',
|
|
||||||
'durationMs': '227882',
|
|
||||||
'finished': false,
|
|
||||||
'playCount': 8,
|
|
||||||
'updatedAt': '2026-10-21T15:17:05.419',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -77,25 +67,31 @@ void main() {
|
|||||||
|
|
||||||
final page = await api.recent();
|
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.total, 0);
|
||||||
expect(page.list, isEmpty);
|
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'),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user