feat(library): 支持设备追剧与观看历史
This commit is contained in:
1 parent
4c3acb047c
commit
0d785bf1f8
12 files changed
+232
-76
No files matched your search
@@ -5,6 +5,7 @@ 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 'package:fruitshorts/core/data/repositories/watch_history_repository.dart';
|
||||
|
||||
import '../support/fake_http_adapter.dart';
|
||||
|
||||
@@ -94,4 +95,60 @@ void main() {
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('should_allow_guest_watch_read_save_and_clear', () async {
|
||||
final adapter = FakeHttpAdapter((options) async {
|
||||
if (options.method == 'GET' && options.uri.path.endsWith('/progress')) {
|
||||
return FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': {
|
||||
'dramaId': '12',
|
||||
'episodeId': '88',
|
||||
'positionMs': '8000',
|
||||
'durationMs': '60000',
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
if (options.method == 'GET') {
|
||||
return FakeHttpResponse(
|
||||
jsonEncode({
|
||||
'code': 0,
|
||||
'message': 'ok',
|
||||
'data': {'total': '0', 'list': <Object>[]},
|
||||
}),
|
||||
);
|
||||
}
|
||||
return FakeHttpResponse(
|
||||
jsonEncode({'code': 0, 'message': 'ok', 'data': null}),
|
||||
);
|
||||
});
|
||||
final repository = HttpWatchHistoryRepository(
|
||||
WatchApi(ApiClient(baseUrl: 'http://127.0.0.1:8081', adapter: adapter)),
|
||||
);
|
||||
|
||||
expect((await repository.progressFor('12'))?.episodeId, '88');
|
||||
expect((await repository.recent()).list, isEmpty);
|
||||
await repository.save(
|
||||
episodeId: '88',
|
||||
position: const Duration(seconds: 8),
|
||||
);
|
||||
await repository.remove('12');
|
||||
await repository.clear();
|
||||
|
||||
expect(
|
||||
adapter.requests.map(
|
||||
(request) => '${request.method} ${request.uri.path}',
|
||||
),
|
||||
[
|
||||
'GET /app/watch/progress',
|
||||
'GET /app/watch/recent',
|
||||
'POST /app/watch/progress',
|
||||
'DELETE /app/watch/progress/12',
|
||||
'DELETE /app/watch/progress',
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user