62 lines
2.2 KiB
Dart
62 lines
2.2 KiB
Dart
import 'package:background_downloader/background_downloader.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:reelbox/data/models.dart';
|
|
import 'package:reelbox/media/download_service.dart';
|
|
import 'package:reelbox/state/app_state.dart';
|
|
|
|
void main() {
|
|
test(
|
|
'retry can replace an incompatible multipart task with a normal GET',
|
|
() {
|
|
final old = createDirectDownloadTask(
|
|
id: 'old-multipart',
|
|
title: const TitleRecord(
|
|
id: 81,
|
|
title: 'A local test film',
|
|
type: 'serie',
|
|
),
|
|
source: const MediaSource(
|
|
url: 'https://example.test/video.mp4',
|
|
quality: '720p',
|
|
),
|
|
episode: const EpisodeRecord(id: 9, title: 'Episode 1'),
|
|
preferences: AppSettings(
|
|
wifiOnlyDownloads: true,
|
|
downloadNotifications: false,
|
|
),
|
|
supportsParallel: true,
|
|
);
|
|
final entry = DownloadEntry.fromTask(old, taskStatus: TaskStatus.failed);
|
|
final retry = createRetryDownloadTask(entry, id: 'retry-single');
|
|
expect(retry, isNot(isA<ParallelDownloadTask>()));
|
|
expect(retry.taskId, 'retry-single');
|
|
expect(retry.url, old.url);
|
|
expect(retry.metaData, old.metaData);
|
|
expect(retry.requiresWiFi, isTrue);
|
|
expect(retry.notificationConfig, isNull);
|
|
expect(retry.retriesRemaining, old.retries);
|
|
expect(retry.filename, isNot(old.filename));
|
|
expect(DownloadEntry.fromTask(retry).episodeId, 9);
|
|
expect(DownloadEntry.fromTask(retry).titleKind, 'serie');
|
|
},
|
|
);
|
|
|
|
test('default download works without server HEAD or byte-range support', () {
|
|
final task = createDirectDownloadTask(
|
|
id: 'ordinary-get',
|
|
title: const TitleRecord(id: 81, title: 'A local test film'),
|
|
source: const MediaSource(
|
|
url: 'https://example.test/video.mp4',
|
|
type: 'mp4',
|
|
),
|
|
preferences: AppSettings(),
|
|
);
|
|
// Multipart workers require both HEAD and range headers. A normal GET
|
|
// download must be the safe default, not a server-dependent optimization.
|
|
expect(task, isNot(isA<ParallelDownloadTask>()));
|
|
expect(task.httpRequestMethod, 'GET');
|
|
expect(task.requiresWiFi, isFalse);
|
|
expect(task.updates, Updates.statusAndProgress);
|
|
});
|
|
}
|