102 lines
2.9 KiB
Dart
102 lines
2.9 KiB
Dart
// 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/watch_api.dart';
|
|
|
|
import '../support/fake_http_adapter.dart';
|
|
|
|
void main() {
|
|
test('should_request_recent_with_page_and_parse_display_fields', () async {
|
|
final adapter = FakeHttpAdapter(
|
|
(_) async => FakeHttpResponse(
|
|
jsonEncode({
|
|
'code': 0,
|
|
'message': 'ok',
|
|
'data': {
|
|
'total': '18',
|
|
'list': [
|
|
{
|
|
'dramaId': '12',
|
|
'episodeId': '88',
|
|
'dramaTitle': '剧名',
|
|
'dramaCover': '/files/12.png',
|
|
'episodeNumber': 6,
|
|
'totalEpisodes': 68,
|
|
'positionMs': '80000',
|
|
'durationMs': '120000',
|
|
},
|
|
],
|
|
},
|
|
}),
|
|
),
|
|
);
|
|
final api = WatchApi(
|
|
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
|
);
|
|
|
|
final page = await api.recent(pageIndex: 2, pageSize: 10);
|
|
|
|
final request = adapter.requests.single;
|
|
expect(request.uri.path, '/app/watch/recent');
|
|
expect(request.queryParameters['pageIndex'], '2');
|
|
expect(request.queryParameters['pageSize'], '10');
|
|
expect(request.queryParameters.containsKey('limit'), isFalse);
|
|
expect(page.total, 18);
|
|
expect(page.list.single.dramaTitle, '剧名');
|
|
expect(page.list.single.dramaCover, '/files/12.png');
|
|
expect(page.list.single.episodeNumber, 6);
|
|
expect(page.list.single.totalEpisodes, 68);
|
|
});
|
|
|
|
test('should_parse_recent_when_server_returns_legacy_list', () 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',
|
|
},
|
|
],
|
|
}),
|
|
),
|
|
);
|
|
final api = WatchApi(
|
|
ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter),
|
|
);
|
|
|
|
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);
|
|
});
|
|
}
|