test: Add additional test coverage for video download handling
This commit is contained in:
@@ -2,13 +2,13 @@ import { Request, Response } from 'express';
|
||||
import fs from 'fs-extra';
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import {
|
||||
deleteVideo,
|
||||
downloadVideo,
|
||||
getVideoById,
|
||||
getVideos,
|
||||
rateVideo,
|
||||
searchVideos,
|
||||
updateVideoDetails,
|
||||
deleteVideo,
|
||||
downloadVideo,
|
||||
getVideoById,
|
||||
getVideos,
|
||||
rateVideo,
|
||||
searchVideos,
|
||||
updateVideoDetails,
|
||||
} from '../../controllers/videoController';
|
||||
import downloadManager from '../../services/downloadManager';
|
||||
import * as downloadService from '../../services/downloadService';
|
||||
@@ -167,7 +167,8 @@ describe('VideoController', () => {
|
||||
it('should handle Bilibili single part download failure', async () => {
|
||||
req.body = { youtubeUrl: 'https://www.bilibili.com/video/BV1xx' };
|
||||
(downloadService.downloadSingleBilibiliPart as any).mockResolvedValue({ success: false, error: 'Failed' });
|
||||
(downloadManager.addDownload as any).mockImplementation((fn: Function) => fn());
|
||||
(storageService.checkVideoDownloadBySourceId as any).mockReturnValue({ found: false });
|
||||
(downloadManager.addDownload as any).mockReturnValue(Promise.resolve());
|
||||
|
||||
await downloadVideo(req as Request, res as Response);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ describe('DownloadService', () => {
|
||||
describe('Bilibili', () => {
|
||||
it('should call BilibiliDownloader.downloadVideo', async () => {
|
||||
await downloadService.downloadBilibiliVideo('url', 'path', 'thumb');
|
||||
expect(BilibiliDownloader.downloadVideo).toHaveBeenCalledWith('url', 'path', 'thumb');
|
||||
expect(BilibiliDownloader.downloadVideo).toHaveBeenCalledWith('url', 'path', 'thumb', undefined);
|
||||
});
|
||||
|
||||
it('should call BilibiliDownloader.checkVideoParts', async () => {
|
||||
@@ -41,7 +41,7 @@ describe('DownloadService', () => {
|
||||
|
||||
it('should call BilibiliDownloader.downloadSinglePart', async () => {
|
||||
await downloadService.downloadSingleBilibiliPart('url', 1, 2, 'title');
|
||||
expect(BilibiliDownloader.downloadSinglePart).toHaveBeenCalledWith('url', 1, 2, 'title');
|
||||
expect(BilibiliDownloader.downloadSinglePart).toHaveBeenCalledWith('url', 1, 2, 'title', undefined);
|
||||
});
|
||||
|
||||
it('should call BilibiliDownloader.downloadCollection', async () => {
|
||||
|
||||
Reference in New Issue
Block a user