mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-07 09:00:47 +00:00
refactor(downloader): remove opts parameter from Resolve (#1595)
This commit is contained in:
45 files changed
+1589
-384
No files matched your search
@@ -3,30 +3,49 @@ import 'dart:convert';
|
||||
import 'package:dio/dio.dart' as dio;
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:gopeed/api/api.dart' as api;
|
||||
import 'package:gopeed/api/model/create_task.dart';
|
||||
import 'package:gopeed/api/model/options.dart';
|
||||
import 'package:gopeed/api/model/patch_task.dart';
|
||||
import 'package:gopeed/api/model/request.dart';
|
||||
import 'package:gopeed/api/model/resolve_task.dart';
|
||||
import 'package:gopeed/core/network/gopeed/gopeed_transport.dart';
|
||||
|
||||
void main() {
|
||||
test('resolve sends the complete resolve task for magnet links', () async {
|
||||
test('resolve omits download options and creation submits them separately', () async {
|
||||
final transport = _RecordingTransport();
|
||||
api.setTransportForTesting(transport);
|
||||
final result = await api.resolve(
|
||||
ResolveTask(
|
||||
req: Request(url: 'magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567'),
|
||||
opts: Options(path: '/downloads', selectFiles: const []),
|
||||
),
|
||||
ResolveTask(req: Request(url: 'magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567')),
|
||||
);
|
||||
|
||||
expect(result.id, 'resolved-id');
|
||||
final requestBody = transport.data as Map<String, dynamic>;
|
||||
expect(requestBody.keys, containsAll(<String>['req', 'opts']));
|
||||
expect(requestBody.keys, equals(<String>['req']));
|
||||
expect(
|
||||
(requestBody['req'] as Map<String, dynamic>)['url'],
|
||||
'magnet:?xt=urn:btih:0123456789abcdef0123456789abcdef01234567',
|
||||
);
|
||||
expect((requestBody['opts'] as Map<String, dynamic>)['path'], '/downloads');
|
||||
expect(requestBody, isNot(contains('opts')));
|
||||
|
||||
final id = await api.createTask(
|
||||
CreateTask(
|
||||
rid: result.id,
|
||||
opts: Options(path: '/chosen-after-resolve', selectFiles: [1]),
|
||||
),
|
||||
);
|
||||
expect(id, 'created-id');
|
||||
final createBody = transport.data as Map<String, dynamic>;
|
||||
expect(createBody['rid'], 'resolved-id');
|
||||
expect((createBody['opts'] as Map<String, dynamic>)['path'], '/chosen-after-resolve');
|
||||
expect((createBody['opts'] as Map<String, dynamic>)['selectFiles'], [1]);
|
||||
});
|
||||
|
||||
test('patch preserves options in its independent request model', () async {
|
||||
final transport = _RecordingTransport();
|
||||
api.setTransportForTesting(transport);
|
||||
await api.patchTask('task-id', PatchTask(opts: Options(selectFiles: [1])));
|
||||
final requestBody = transport.data as Map<String, dynamic>;
|
||||
expect((requestBody['opts'] as Map<String, dynamic>)['selectFiles'], [1]);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -41,6 +60,12 @@ class _RecordingTransport implements GopeedTransport {
|
||||
Map<String, dynamic>? queryParameters,
|
||||
}) async {
|
||||
this.data = jsonDecode(jsonEncode(data));
|
||||
if (path == 'api/v1/tasks') {
|
||||
return {'code': 0, 'data': 'created-id'};
|
||||
}
|
||||
if (method == 'PATCH') {
|
||||
return {'code': 0, 'data': null};
|
||||
}
|
||||
return {
|
||||
'code': 0,
|
||||
'data': {
|
||||
|
||||
Reference in new issue
Block a user