Comment resolution

This commit is contained in:
iPromKnight
2024-02-10 00:15:20 +00:00
committed by iPromKnight
parent e04f2d01a4
commit 360bc20970
38 changed files with 377 additions and 366 deletions

View File

@@ -1,6 +1,8 @@
import "reflect-metadata"; // required
import {ILoggingService} from '@interfaces/logging_service';
import {CacheMethod, CacheService} from '@services/cache_service';
import {IocTypes} from "@setup/ioc_types";
import {Container} from "inversify";
jest.mock('@services/configuration_service', () => {
return {
@@ -49,9 +51,12 @@ describe('CacheService Tests', () => {
beforeEach(() => {
jest.clearAllMocks();
process.env.LOG_LEVEL = 'debug';
loggingService = jest.requireMock<ILoggingService>('@services/logging_service');
cacheMethod = jest.fn().mockResolvedValue({});
cacheService = new CacheService(loggingService);
loggingService = jest.requireMock<ILoggingService>('@services/logging_service');
const container = new Container();
container.bind<CacheService>(CacheService).toSelf();
container.bind<ILoggingService>(IocTypes.ILoggingService).toConstantValue(loggingService);
cacheService = container.get(CacheService);
});
afterEach(() => {
@@ -113,7 +118,6 @@ describe('CacheService Tests', () => {
}
});
cacheService = new CacheService(loggingService);
const result = await cacheService.cacheWrapImdbId('testKey', cacheMethod);
expect(result).toBeDefined();
});

View File

@@ -2,6 +2,8 @@ import "reflect-metadata"; // required
import {ICacheService} from "@interfaces/cache_service";
import {IMetadataResponse} from "@interfaces/metadata_response";
import {MetadataService} from "@services/metadata_service";
import {IocTypes} from "@setup/ioc_types";
import {Container} from "inversify";
import {setupServer} from "msw/node";
import * as responses from "./mock-responses/metadata_mock_responses";
@@ -38,7 +40,10 @@ describe('MetadataService Tests', () => {
beforeEach(() => {
mockCacheService = jest.requireMock<ICacheService>('@services/cache_service');
metadataService = new MetadataService(mockCacheService);
const container = new Container();
container.bind<MetadataService>(MetadataService).toSelf();
container.bind<ICacheService>(IocTypes.ICacheService).toConstantValue(mockCacheService);
metadataService = container.get(MetadataService);
});
it("should get kitsu id", async () => {
@@ -57,10 +62,10 @@ describe('MetadataService Tests', () => {
id: 'kitsu:11',
type: 'series'
});
expect(mockCacheService.cacheWrapMetadata).toHaveBeenCalledWith('kitsu:11', expect.any(Function));
expect(result).not.toBeNull();
const body = result as IMetadataResponse;
expect(body.videos).not.toBeNull();
expect(body.videos.length).toBe(220);

View File

@@ -3,7 +3,9 @@ import {ILoggingService} from '@interfaces/logging_service';
import {ITorrentProcessingService} from '@interfaces/torrent_processing_service';
import {ProcessTorrentsJob} from '@jobs/process_torrents_job';
import {configurationService} from '@services/configuration_service';
import {IocTypes} from "@setup/ioc_types";
import client, {ConsumeMessage} from 'amqplib';
import {Container} from "inversify";
jest.mock('@services/configuration_service', () => {
return {
@@ -56,7 +58,12 @@ describe('ProcessTorrentsJob Tests', () => {
jest.clearAllMocks();
loggingService = jest.requireMock<ILoggingService>('@services/logging_service');
torrentProcessingService = jest.requireMock('@services/torrent_processing_service');
processTorrentsJob = new ProcessTorrentsJob(torrentProcessingService, loggingService);
const container = new Container();
container.bind<ProcessTorrentsJob>(ProcessTorrentsJob).toSelf();
container.bind<ILoggingService>(IocTypes.ILoggingService).toConstantValue(loggingService);
container.bind<ITorrentProcessingService>(IocTypes.ITorrentProcessingService).toConstantValue(torrentProcessingService);
processTorrentsJob = container.get(ProcessTorrentsJob);
});
afterEach(() => {

View File

@@ -2,6 +2,8 @@ import "reflect-metadata"; // required
import {ILoggingService} from '@interfaces/logging_service';
import {IParsedTorrent} from "@interfaces/parsed_torrent";
import {TorrentDownloadService} from '@services/torrent_download_service';
import {IocTypes} from "@setup/ioc_types";
import {Container} from "inversify";
import torrentStream from 'torrent-stream';
jest.mock('@services/logging_service', () => {
@@ -27,7 +29,11 @@ describe('TorrentDownloadService', () => {
beforeEach(() => {
jest.clearAllMocks();
mockLoggingService = jest.requireMock<ILoggingService>('@services/logging_service');
torrentDownloadService = new TorrentDownloadService(mockLoggingService);
const container = new Container();
container.bind<TorrentDownloadService>(TorrentDownloadService).toSelf();
container.bind<ILoggingService>(IocTypes.ILoggingService).toConstantValue(mockLoggingService);
torrentDownloadService = container.get(TorrentDownloadService);
});
it('should get torrent files', async () => {

View File

@@ -6,11 +6,13 @@ import {IParsedTorrent} from "@interfaces/parsed_torrent";
import {ITorrentFileCollection} from "@interfaces/torrent_file_collection";
import {ITorrentFileService} from "@interfaces/torrent_file_service";
import {ITorrentSubtitleService} from "@interfaces/torrent_subtitle_service";
import {IDatabaseRepository} from "@repository/interfaces/database_repository";
import {IDatabaseRepository} from "@repository/interfaces/database_repository";
import {IFileAttributes} from "@repository/interfaces/file_attributes";
import {ITorrentCreationAttributes} from "@repository/interfaces/torrent_attributes";
import {Torrent} from "@repository/models/torrent";
import {TorrentEntriesService} from "@services/torrent_entries_service";
import {IocTypes} from "@setup/ioc_types";
import {Container} from "inversify";
jest.mock('@services/logging_service', () => {
return {
@@ -63,24 +65,32 @@ describe('TorrentEntriesService Tests', () => {
beforeEach(() => {
jest.clearAllMocks();
mockFileService = jest.requireMock<ITorrentFileService>('@services/torrent_file_service');
mockMetadataService = jest.requireMock<IMetadataService>('@services/metadata_service');
mockSubtitleService = jest.requireMock<ITorrentSubtitleService>('@services/torrent_subtitle_service');
mockLoggingService = jest.requireMock<ILoggingService>('@services/logging_service');
mockDatabaseRepository = jest.requireMock<IDatabaseRepository>('@repository/database_repository');
torrentEntriesService = new TorrentEntriesService(mockMetadataService, mockLoggingService, mockFileService , mockSubtitleService, mockDatabaseRepository);
const container = new Container();
container.bind<TorrentEntriesService>(TorrentEntriesService).toSelf();
container.bind<ILoggingService>(IocTypes.ILoggingService).toConstantValue(mockLoggingService);
container.bind<ITorrentFileService>(IocTypes.ITorrentFileService).toConstantValue(mockFileService);
container.bind<ITorrentSubtitleService>(IocTypes.ITorrentSubtitleService).toConstantValue(mockSubtitleService);
container.bind<IDatabaseRepository>(IocTypes.IDatabaseRepository).toConstantValue(mockDatabaseRepository);
container.bind<IMetadataService>(IocTypes.IMetadataService).toConstantValue(mockMetadataService);
torrentEntriesService = container.get(TorrentEntriesService);
});
it('should create a torrent entry', async () => {
const torrent : IParsedTorrent = {
const torrent: IParsedTorrent = {
title: 'Test title',
provider: 'Test provider',
infoHash: 'Test infoHash',
type: TorrentType.Movie,
};
const fileCollection : ITorrentFileCollection = {
const fileCollection: ITorrentFileCollection = {
videos: [{
fileIndex: 0,
title: 'Test video',
@@ -91,9 +101,9 @@ describe('TorrentEntriesService Tests', () => {
subtitles: [],
};
const fileCollectionWithSubtitles : ITorrentFileCollection = {
const fileCollectionWithSubtitles: ITorrentFileCollection = {
...fileCollection,
subtitles: [ {
subtitles: [{
fileId: 0,
title: 'Test subtitle',
fileIndex: 0,
@@ -109,7 +119,11 @@ describe('TorrentEntriesService Tests', () => {
await torrentEntriesService.createTorrentEntry(torrent);
expect(mockMetadataService.getImdbId).toHaveBeenCalledWith({ title: 'Test title', year: undefined, type: TorrentType.Movie });
expect(mockMetadataService.getImdbId).toHaveBeenCalledWith({
title: 'Test title',
year: undefined,
type: TorrentType.Movie
});
expect(mockFileService.parseTorrentFiles).toHaveBeenCalledWith(torrent);
expect(mockFileService.parseTorrentFiles).toHaveReturnedWith(Promise.resolve(fileCollection));
expect(mockSubtitleService.assignSubtitles).toHaveBeenCalledWith(fileCollection);
@@ -118,14 +132,14 @@ describe('TorrentEntriesService Tests', () => {
});
it('should assign imdbId correctly', async () => {
const torrent : IParsedTorrent = {
const torrent: IParsedTorrent = {
title: 'Test title',
provider: 'Test provider',
infoHash: 'Test infoHash',
type: TorrentType.Movie,
};
const fileCollection : ITorrentFileCollection = {
const fileCollection: ITorrentFileCollection = {
videos: [{
fileIndex: 0,
title: 'Test video',
@@ -136,9 +150,9 @@ describe('TorrentEntriesService Tests', () => {
subtitles: [],
};
const fileCollectionWithSubtitles : ITorrentFileCollection = {
const fileCollectionWithSubtitles: ITorrentFileCollection = {
...fileCollection,
subtitles: [ {
subtitles: [{
fileId: 0,
title: 'Test subtitle',
fileIndex: 0,
@@ -159,14 +173,14 @@ describe('TorrentEntriesService Tests', () => {
});
it('should assign kitsuId correctly', async () => {
const torrent : IParsedTorrent = {
const torrent: IParsedTorrent = {
title: 'Test title',
provider: 'Test provider',
infoHash: 'Test infoHash',
type: TorrentType.Anime,
};
const fileCollection : ITorrentFileCollection = {
const fileCollection: ITorrentFileCollection = {
videos: [{
fileIndex: 0,
title: 'Test video',
@@ -177,9 +191,9 @@ describe('TorrentEntriesService Tests', () => {
subtitles: [],
};
const fileCollectionWithSubtitles : ITorrentFileCollection = {
const fileCollectionWithSubtitles: ITorrentFileCollection = {
...fileCollection,
subtitles: [ {
subtitles: [{
fileId: 0,
title: 'Test subtitle',
fileIndex: 0,
@@ -208,9 +222,9 @@ describe('TorrentEntriesService Tests', () => {
};
(mockDatabaseRepository.createSkipTorrent as jest.Mock).mockResolvedValue([torrent, null]);
const result = await torrentEntriesService.createSkipTorrentEntry(torrent);
expect(mockDatabaseRepository.createSkipTorrent).toHaveBeenCalledWith(torrent);
expect(result).toEqual([torrent, null]);
});
@@ -240,7 +254,7 @@ describe('TorrentEntriesService Tests', () => {
});
it('should check and update torrent', async () => {
const torrent : IParsedTorrent = {
const torrent: IParsedTorrent = {
title: 'Test title',
provider: 'Test provider',
infoHash: 'Test infoHash',
@@ -248,13 +262,13 @@ describe('TorrentEntriesService Tests', () => {
seeders: 1,
};
const files : IFileAttributes[] = [{
const files: IFileAttributes[] = [{
infoHash: 'Test infoHash',
fileIndex: 0,
title: 'Test title',
path: 'Test path',
size: 123456,
},{
size: 123456,
}, {
infoHash: 'Test infoHash 2',
fileIndex: 1,
title: 'Test title 2',
@@ -264,16 +278,16 @@ describe('TorrentEntriesService Tests', () => {
const torrentInstance = {
...torrent,
dataValues:{ ...torrent},
dataValues: {...torrent},
save: jest.fn().mockResolvedValue(torrent),
};
const filesInstance = {
...files,
dataValues:{ ...files},
dataValues: {...files},
save: jest.fn().mockResolvedValue(files),
};
const seedersResponse = [1];
(mockDatabaseRepository.getTorrent as jest.Mock).mockResolvedValue(torrentInstance);
@@ -284,10 +298,10 @@ describe('TorrentEntriesService Tests', () => {
const result = await torrentEntriesService.checkAndUpdateTorrent(torrent);
expect(mockDatabaseRepository.getTorrent).toHaveBeenCalledWith({
infoHash: torrent.infoHash,
infoHash: torrent.infoHash,
provider: torrent.provider
});
expect(mockDatabaseRepository.getFiles).toHaveBeenCalledWith(torrent.infoHash);
expect(mockDatabaseRepository.setTorrentSeeders).toHaveBeenCalledWith(torrentInstance.dataValues, 1);
expect(result).toEqual(true);
@@ -307,7 +321,7 @@ describe('TorrentEntriesService Tests', () => {
}
} as Torrent;
const fileCollection : ITorrentFileCollection = {
const fileCollection: ITorrentFileCollection = {
videos: [{
id: 1,
title: 'Test video',
@@ -319,7 +333,7 @@ describe('TorrentEntriesService Tests', () => {
subtitles: [],
};
const fileCollectionWithContents : ITorrentFileCollection = {
const fileCollectionWithContents: ITorrentFileCollection = {
...fileCollection,
contents: [{
size: 123456,

View File

@@ -5,6 +5,8 @@ import {IMetadataService} from "@interfaces/metadata_service";
import {IParsedTorrent} from "@interfaces/parsed_torrent";
import {ITorrentDownloadService} from "@interfaces/torrent_download_service";
import {TorrentFileService} from "@services/torrent_file_service";
import {IocTypes} from "@setup/ioc_types";
import {Container} from "inversify";
jest.mock('@services/logging_service', () => {
return {
@@ -38,10 +40,17 @@ describe('TorrentFileService tests', () => {
beforeEach(() => {
jest.clearAllMocks();
mockLoggingService = jest.requireMock<ILoggingService>('@services/logging_service');
mockDownloadService = jest.requireMock<ITorrentDownloadService>('@services/torrent_download_service');
mockMetadataService = jest.requireMock<IMetadataService>('@services/metadata_service');
torrentFileService = new TorrentFileService(mockMetadataService, mockDownloadService, mockLoggingService);
const container = new Container();
container.bind<TorrentFileService>(TorrentFileService).toSelf();
container.bind<ILoggingService>(IocTypes.ILoggingService).toConstantValue(mockLoggingService);
container.bind<IMetadataService>(IocTypes.IMetadataService).toConstantValue(mockMetadataService);
container.bind<ITorrentDownloadService>(IocTypes.ITorrentDownloadService).toConstantValue(mockDownloadService);
torrentFileService = container.get(TorrentFileService);
});
@@ -56,7 +65,7 @@ describe('TorrentFileService tests', () => {
const result = torrentFileService.parseTorrentFiles(mockTorrent);
expect(result).toBeInstanceOf(Promise);
result.then(res => {
expect(res).toHaveProperty('videos');
expect(res).toHaveProperty('subtitles');

View File

@@ -12,9 +12,9 @@ describe('TorrentSubtitleService tests', () => {
it('should assign subtitles to a single video', () => {
const fileCollection: ITorrentFileCollection = {
videos: [{ title: 'Test video', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash' }],
videos: [{title: 'Test video', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash'}],
contents: [],
subtitles: [{ title: 'Test subtitle', fileIndex: 0, path: 'Test path', infoHash: 'Test infoHash' }],
subtitles: [{title: 'Test subtitle', fileIndex: 0, path: 'Test path', infoHash: 'Test infoHash'}],
};
const result = torrentSubtitleService.assignSubtitles(fileCollection);
@@ -27,7 +27,7 @@ describe('TorrentSubtitleService tests', () => {
const fileCollection: ITorrentFileCollection = {
videos: [],
contents: [],
subtitles: [{ title: 'Test subtitle', fileIndex: 0, path: 'Test path', infoHash: 'Test infoHash' }],
subtitles: [{title: 'Test subtitle', fileIndex: 0, path: 'Test path', infoHash: 'Test infoHash'}],
};
const result = torrentSubtitleService.assignSubtitles(fileCollection);
@@ -37,7 +37,7 @@ describe('TorrentSubtitleService tests', () => {
it('should not assign subtitles if there are no subtitles', () => {
const fileCollection: ITorrentFileCollection = {
videos: [{ title: 'Test video', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash' }],
videos: [{title: 'Test video', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash'}],
contents: [],
subtitles: [],
};
@@ -50,13 +50,13 @@ describe('TorrentSubtitleService tests', () => {
it('should assign subtitles to multiple videos', () => {
const fileCollection: ITorrentFileCollection = {
videos: [
{ title: 'Test video S01E01', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash' },
{ title: 'Test video S01E02', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash' }
{title: 'Test video S01E01', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash'},
{title: 'Test video S01E02', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash'}
],
contents: [],
subtitles: [
{ title: 'Test subtitle S01E01', fileIndex: 0, path: 'Test path', infoHash: 'Test infoHash' },
{ title: 'Test subtitle S01E02', fileIndex: 1, path: 'Test path', infoHash: 'Test infoHash' }
{title: 'Test subtitle S01E01', fileIndex: 0, path: 'Test path', infoHash: 'Test infoHash'},
{title: 'Test subtitle S01E02', fileIndex: 1, path: 'Test path', infoHash: 'Test infoHash'}
],
};
@@ -69,9 +69,9 @@ describe('TorrentSubtitleService tests', () => {
it('should not assign subtitles if there are no matching videos', () => {
const fileCollection: ITorrentFileCollection = {
videos: [{ title: 'Test video', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash' }],
videos: [{title: 'Test video', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash'}],
contents: [],
subtitles: [{ title: 'Non-matching subtitle', fileIndex: 0, path: 'Test path', infoHash: 'Non-matching infoHash' }],
subtitles: [{title: 'Non-matching subtitle', fileIndex: 0, path: 'Test path', infoHash: 'Non-matching infoHash'}],
};
const result = torrentSubtitleService.assignSubtitles(fileCollection);
@@ -83,13 +83,13 @@ describe('TorrentSubtitleService tests', () => {
it('should assign subtitles to the most probable videos based on filename, title, season, and episode', () => {
const fileCollection: ITorrentFileCollection = {
videos: [
{ title: 'Test video S01E01', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash' },
{ title: 'Test video S01E02', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash' }
{title: 'Test video S01E01', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash'},
{title: 'Test video S01E02', size: 123456, imdbId: 'tt1234567', infoHash: 'Test infoHash'}
],
contents: [],
subtitles: [
{ title: 'Test subtitle S01E01', fileIndex: 0, path: 'Test path', infoHash: 'Test infoHash' },
{ title: 'Test subtitle S01E02', fileIndex: 1, path: 'Test path', infoHash: 'Test infoHash' }
{title: 'Test subtitle S01E01', fileIndex: 0, path: 'Test path', infoHash: 'Test infoHash'},
{title: 'Test subtitle S01E02', fileIndex: 1, path: 'Test path', infoHash: 'Test infoHash'}
],
};

View File

@@ -2,6 +2,8 @@ import "reflect-metadata"; // required
import {ICacheService} from '@interfaces/cache_service';
import {ILoggingService} from '@interfaces/logging_service';
import {TrackerService} from '@services/tracker_service';
import {IocTypes} from "@setup/ioc_types";
import {Container} from "inversify";
import {setupServer} from 'msw/node';
import * as responses from "./mock-responses/trackers_mock_responses";
@@ -21,7 +23,6 @@ jest.mock('@services/cache_service', () => {
}
})
beforeAll(() => server.listen())
beforeEach(() => {
jest.clearAllMocks();
@@ -41,7 +42,12 @@ describe('TrackerService', () => {
beforeEach(() => {
mockCacheService = jest.requireMock<ICacheService>('@services/cache_service');
mockLoggingService = jest.requireMock<ILoggingService>('@services/logging_service');
trackerService = new TrackerService(mockCacheService, mockLoggingService);
const container = new Container();
container.bind<TrackerService>(TrackerService).toSelf();
container.bind<ILoggingService>(IocTypes.ILoggingService).toConstantValue(mockLoggingService);
container.bind<ICacheService>(IocTypes.ICacheService).toConstantValue(mockCacheService);
trackerService = container.get(TrackerService);
});
it('should get trackers', async () => {