mirror of
https://github.com/immich-app/immich.git
synced 2025-12-23 01:11:36 +03:00
* Add new cli * Remove old readme * Add documentation to readme file * Add github workflow tests for cli * Fix typo in docs * Add usage info to readme * Add package-lock.json * Fix tsconfig * Cleanup * Fix lint * Cleanup package.json * Fix accidental server change * Remove rootdir from cli * Remove tsbuildinfo * Add prettierignore * Make CLI use internal openapi specs * Add ignore and dry-run features * Sort paths alphabetically * Don't remove substring * Remove shorthand for delete * Remove unused import * Remove chokidar * Set correct openapi cli generator script * Add progress bar * Rename target to asset * Add deletion progress bar * Ignore require statement * Use read streams instead of readfile * Fix github feedback * Fix upload requires * More github comments * Cleanup messages * Cleaner pattern concats * Github comments --------- Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
236 lines
7.1 KiB
TypeScript
236 lines
7.1 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
import { CrawlService } from './crawl.service';
|
|
import mockfs from 'mock-fs';
|
|
import { toIncludeSameMembers } from 'jest-extended';
|
|
import { CrawlOptionsDto } from '../cores/dto/crawl-options-dto';
|
|
|
|
const matchers = require('jest-extended');
|
|
expect.extend(matchers);
|
|
|
|
const crawlService = new CrawlService();
|
|
|
|
describe('CrawlService', () => {
|
|
beforeAll(() => {
|
|
// Write a dummy output before mock-fs to prevent some annoying errors
|
|
console.log();
|
|
});
|
|
|
|
it('should crawl a single directory', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg']);
|
|
});
|
|
|
|
it('should crawl a single file', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/image.jpg'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg']);
|
|
});
|
|
|
|
it('should crawl a file and a directory', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/images/photo.jpg': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/image.jpg', '/images/'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg', '/images/photo.jpg']);
|
|
});
|
|
|
|
it('should exclude by file extension', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/photos/image.tif': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/'];
|
|
options.excludePatterns = ['**/*.tif'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg']);
|
|
});
|
|
|
|
it('should exclude by file extension without case sensitivity', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/photos/image.tif': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/'];
|
|
options.excludePatterns = ['**/*.TIF'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg']);
|
|
});
|
|
|
|
it('should exclude by folder', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/photos/raw/image.jpg': '',
|
|
'/photos/raw2/image.jpg': '',
|
|
'/photos/folder/raw/image.jpg': '',
|
|
'/photos/crawl/image.jpg': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/'];
|
|
options.excludePatterns = ['**/raw/**'];
|
|
options.recursive = true;
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg', '/photos/raw2/image.jpg', '/photos/crawl/image.jpg']);
|
|
});
|
|
|
|
it('should crawl multiple paths', async () => {
|
|
mockfs({
|
|
'/photos/image1.jpg': '',
|
|
'/images/image2.jpg': '',
|
|
'/albums/image3.jpg': '',
|
|
});
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/', '/images/', '/albums/'];
|
|
options.recursive = false;
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image1.jpg', '/images/image2.jpg', '/albums/image3.jpg']);
|
|
});
|
|
|
|
it('should crawl a single path without trailing slash', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
});
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg']);
|
|
});
|
|
|
|
it('should crawl a single path without recursion', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/photos/subfolder/image1.jpg': '',
|
|
'/photos/subfolder/image2.jpg': '',
|
|
'/image1.jpg': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg']);
|
|
});
|
|
|
|
it('should crawl a single path with recursion', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/photos/subfolder/image1.jpg': '',
|
|
'/photos/subfolder/image2.jpg': '',
|
|
'/image1.jpg': '',
|
|
});
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/'];
|
|
options.recursive = true;
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers([
|
|
'/photos/image.jpg',
|
|
'/photos/subfolder/image1.jpg',
|
|
'/photos/subfolder/image2.jpg',
|
|
]);
|
|
});
|
|
|
|
it('should filter file extensions', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/photos/image.txt': '',
|
|
'/photos/1': '',
|
|
});
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers(['/photos/image.jpg']);
|
|
});
|
|
|
|
it('should include photo and video extensions', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/photos/image.jpeg': '',
|
|
'/photos/image.heic': '',
|
|
'/photos/image.heif': '',
|
|
'/photos/image.png': '',
|
|
'/photos/image.gif': '',
|
|
'/photos/image.tif': '',
|
|
'/photos/image.tiff': '',
|
|
'/photos/image.webp': '',
|
|
'/photos/image.dng': '',
|
|
'/photos/image.nef': '',
|
|
'/videos/video.mp4': '',
|
|
'/videos/video.mov': '',
|
|
'/videos/video.webm': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/', '/videos/'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
|
|
expect(paths).toIncludeSameMembers([
|
|
'/photos/image.jpg',
|
|
'/photos/image.jpeg',
|
|
'/photos/image.heic',
|
|
'/photos/image.heif',
|
|
'/photos/image.png',
|
|
'/photos/image.gif',
|
|
'/photos/image.tif',
|
|
'/photos/image.tiff',
|
|
'/photos/image.webp',
|
|
'/photos/image.dng',
|
|
'/photos/image.nef',
|
|
'/videos/video.mp4',
|
|
'/videos/video.mov',
|
|
'/videos/video.webm',
|
|
]);
|
|
});
|
|
|
|
it('should check file extensions without case sensitivity', async () => {
|
|
mockfs({
|
|
'/photos/image.jpg': '',
|
|
'/photos/image.Jpg': '',
|
|
'/photos/image.jpG': '',
|
|
'/photos/image.JPG': '',
|
|
'/photos/image.jpEg': '',
|
|
'/photos/image.TIFF': '',
|
|
'/photos/image.tif': '',
|
|
'/photos/image.dng': '',
|
|
'/photos/image.NEF': '',
|
|
});
|
|
|
|
const options = new CrawlOptionsDto();
|
|
options.pathsToCrawl = ['/photos/'];
|
|
const paths: string[] = await crawlService.crawl(options);
|
|
expect(paths).toIncludeSameMembers([
|
|
'/photos/image.jpg',
|
|
'/photos/image.Jpg',
|
|
'/photos/image.jpG',
|
|
'/photos/image.JPG',
|
|
'/photos/image.jpEg',
|
|
'/photos/image.TIFF',
|
|
'/photos/image.tif',
|
|
'/photos/image.dng',
|
|
'/photos/image.NEF',
|
|
]);
|
|
});
|
|
|
|
afterEach(() => {
|
|
mockfs.restore();
|
|
});
|
|
});
|