2024-05-20 18:09:10 -04:00
|
|
|
import { LibraryResponseDto, LoginResponseDto, ScanLibraryDto, getAllLibraries, scanLibrary } from '@immich/sdk';
|
2024-04-12 15:15:41 -04:00
|
|
|
import { cpSync, existsSync } from 'node:fs';
|
2024-03-15 09:16:08 -04:00
|
|
|
import { Socket } from 'socket.io-client';
|
2024-02-29 15:10:08 -05:00
|
|
|
import { userDto, uuidDto } from 'src/fixtures';
|
|
|
|
|
import { errorDto } from 'src/responses';
|
2024-03-15 09:16:08 -04:00
|
|
|
import { app, asBearerAuth, testAssetDir, testAssetDirInternal, utils } from 'src/utils';
|
2024-02-29 15:10:08 -05:00
|
|
|
import request from 'supertest';
|
2024-04-12 15:15:41 -04:00
|
|
|
import { utimes } from 'utimes';
|
2024-03-15 09:16:08 -04:00
|
|
|
import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
|
|
|
|
|
|
const scan = async (accessToken: string, id: string, dto: ScanLibraryDto = {}) =>
|
|
|
|
|
scanLibrary({ id, scanLibraryDto: dto }, { headers: asBearerAuth(accessToken) });
|
2024-02-29 15:10:08 -05:00
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('/libraries', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
let admin: LoginResponseDto;
|
|
|
|
|
let user: LoginResponseDto;
|
|
|
|
|
let library: LibraryResponseDto;
|
2024-03-15 09:16:08 -04:00
|
|
|
let websocket: Socket;
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
2024-03-07 10:14:36 -05:00
|
|
|
await utils.resetDatabase();
|
|
|
|
|
admin = await utils.adminSetup();
|
2024-04-15 23:05:08 -04:00
|
|
|
await utils.resetAdminConfig(admin.accessToken);
|
2024-03-07 10:14:36 -05:00
|
|
|
user = await utils.userSetup(admin.accessToken, userDto.user1);
|
2024-05-20 18:09:10 -04:00
|
|
|
library = await utils.createLibrary(admin.accessToken, { ownerId: admin.userId });
|
2024-03-15 09:16:08 -04:00
|
|
|
websocket = await utils.connectWebsocket(admin.accessToken);
|
2024-04-12 15:15:41 -04:00
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryA/assetA.png`);
|
|
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryB/assetB.png`);
|
2024-03-15 09:16:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
|
utils.disconnectWebsocket(websocket);
|
2024-04-15 23:05:08 -04:00
|
|
|
utils.resetTempFolder();
|
2024-03-15 09:16:08 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
utils.resetEvents();
|
2024-02-29 15:10:08 -05:00
|
|
|
});
|
|
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('GET /libraries', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).get('/libraries');
|
2024-02-29 15:10:08 -05:00
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('POST /libraries', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).post('/libraries').send({});
|
2024-02-29 15:10:08 -05:00
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should require admin authentication', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.post('/libraries')
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${user.accessToken}`)
|
2024-05-20 18:09:10 -04:00
|
|
|
.send({ ownerId: admin.userId });
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
expect(status).toBe(403);
|
|
|
|
|
expect(body).toEqual(errorDto.forbidden);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should create an external library with defaults', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.post('/libraries')
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
2024-05-20 18:09:10 -04:00
|
|
|
.send({ ownerId: admin.userId });
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
expect(status).toBe(201);
|
|
|
|
|
expect(body).toEqual(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
name: 'New External Library',
|
|
|
|
|
refreshedAt: null,
|
|
|
|
|
assetCount: 0,
|
|
|
|
|
importPaths: [],
|
|
|
|
|
exclusionPatterns: [],
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should create an external library with options', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.post('/libraries')
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({
|
2024-03-18 15:59:53 -05:00
|
|
|
ownerId: admin.userId,
|
2024-02-29 15:10:08 -05:00
|
|
|
name: 'My Awesome Library',
|
|
|
|
|
importPaths: ['/path/to/import'],
|
|
|
|
|
exclusionPatterns: ['**/Raw/**'],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(201);
|
|
|
|
|
expect(body).toEqual(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
name: 'My Awesome Library',
|
|
|
|
|
importPaths: ['/path/to/import'],
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not create an external library with duplicate import paths', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.post('/libraries')
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({
|
2024-03-18 15:59:53 -05:00
|
|
|
ownerId: admin.userId,
|
2024-02-29 15:10:08 -05:00
|
|
|
name: 'My Awesome Library',
|
|
|
|
|
importPaths: ['/path', '/path'],
|
|
|
|
|
exclusionPatterns: ['**/Raw/**'],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(400);
|
|
|
|
|
expect(body).toEqual(errorDto.badRequest(["All importPaths's elements must be unique"]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not create an external library with duplicate exclusion patterns', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.post('/libraries')
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({
|
2024-03-18 15:59:53 -05:00
|
|
|
ownerId: admin.userId,
|
2024-02-29 15:10:08 -05:00
|
|
|
name: 'My Awesome Library',
|
|
|
|
|
importPaths: ['/path/to/import'],
|
|
|
|
|
exclusionPatterns: ['**/Raw/**', '**/Raw/**'],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(400);
|
|
|
|
|
expect(body).toEqual(errorDto.badRequest(["All exclusionPatterns's elements must be unique"]));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('PUT /libraries/:id', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).put(`/libraries/${uuidDto.notFound}`).send({});
|
2024-02-29 15:10:08 -05:00
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should change the library name', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.put(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ name: 'New Library Name' });
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
name: 'New Library Name',
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not set an empty name', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.put(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ name: '' });
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(400);
|
|
|
|
|
expect(body).toEqual(errorDto.badRequest(['name should not be empty']));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should change the import paths', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.put(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ importPaths: [testAssetDirInternal] });
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
importPaths: [testAssetDirInternal],
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should reject an empty import path', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.put(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ importPaths: [''] });
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(400);
|
|
|
|
|
expect(body).toEqual(errorDto.badRequest(['each value in importPaths should not be empty']));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should reject duplicate import paths', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.put(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ importPaths: ['/path', '/path'] });
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(400);
|
|
|
|
|
expect(body).toEqual(errorDto.badRequest(["All importPaths's elements must be unique"]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should change the exclusion pattern', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.put(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ exclusionPatterns: ['**/Raw/**'] });
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
exclusionPatterns: ['**/Raw/**'],
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should reject duplicate exclusion patterns', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.put(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ exclusionPatterns: ['**/*.jpg', '**/*.jpg'] });
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(400);
|
|
|
|
|
expect(body).toEqual(errorDto.badRequest(["All exclusionPatterns's elements must be unique"]));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should reject an empty exclusion pattern', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.put(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send({ exclusionPatterns: [''] });
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(400);
|
|
|
|
|
expect(body).toEqual(errorDto.badRequest(['each value in exclusionPatterns should not be empty']));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('GET /libraries/:id', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).get(`/libraries/${uuidDto.notFound}`);
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should require admin access', async () => {
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.get(`/libraries/${uuidDto.notFound}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${user.accessToken}`);
|
|
|
|
|
expect(status).toBe(403);
|
|
|
|
|
expect(body).toEqual(errorDto.forbidden);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should get library by id', async () => {
|
2024-05-20 18:09:10 -04:00
|
|
|
const library = await utils.createLibrary(admin.accessToken, { ownerId: admin.userId });
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.get(`/libraries/${library.id}`)
|
2024-02-29 15:10:08 -05:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(200);
|
|
|
|
|
expect(body).toEqual(
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
name: 'New External Library',
|
|
|
|
|
refreshedAt: null,
|
|
|
|
|
assetCount: 0,
|
|
|
|
|
importPaths: [],
|
|
|
|
|
exclusionPatterns: [],
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('GET /libraries/:id/statistics', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).get(`/libraries/${uuidDto.notFound}/statistics`);
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('POST /libraries/:id/scan', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).post(`/libraries/${uuidDto.notFound}/scan`).send({});
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
2024-03-15 09:16:08 -04:00
|
|
|
|
|
|
|
|
it('should scan external library', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
2024-03-18 15:59:53 -05:00
|
|
|
ownerId: admin.userId,
|
2024-03-15 09:16:08 -04:00
|
|
|
importPaths: [`${testAssetDirInternal}/temp/directoryA`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForWebsocketEvent({ event: 'assetUpload', total: 1 });
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, {
|
|
|
|
|
originalPath: `${testAssetDirInternal}/temp/directoryA/assetA.png`,
|
|
|
|
|
});
|
|
|
|
|
expect(assets.count).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should scan external library with exclusion pattern', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
2024-03-18 15:59:53 -05:00
|
|
|
ownerId: admin.userId,
|
2024-03-15 09:16:08 -04:00
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
exclusionPatterns: ['**/directoryA'],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForWebsocketEvent({ event: 'assetUpload', total: 1 });
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
|
|
|
|
|
expect(assets.count).toBe(1);
|
|
|
|
|
expect(assets.items[0].originalPath.includes('directoryB'));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should scan multiple import paths', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
2024-03-18 15:59:53 -05:00
|
|
|
ownerId: admin.userId,
|
2024-03-15 09:16:08 -04:00
|
|
|
importPaths: [`${testAssetDirInternal}/temp/directoryA`, `${testAssetDirInternal}/temp/directoryB`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForWebsocketEvent({ event: 'assetUpload', total: 2 });
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
|
|
|
|
|
expect(assets.count).toBe(2);
|
|
|
|
|
expect(assets.items.find((asset) => asset.originalPath.includes('directoryA'))).toBeDefined();
|
|
|
|
|
expect(assets.items.find((asset) => asset.originalPath.includes('directoryB'))).toBeDefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should pick up new files', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
2024-03-18 15:59:53 -05:00
|
|
|
ownerId: admin.userId,
|
2024-03-15 09:16:08 -04:00
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForWebsocketEvent({ event: 'assetUpload', total: 2 });
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
|
|
|
|
|
expect(assets.count).toBe(2);
|
|
|
|
|
|
|
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryA/assetB.png`);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForWebsocketEvent({ event: 'assetUpload', total: 3 });
|
|
|
|
|
|
|
|
|
|
const { assets: newAssets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
|
|
|
|
|
expect(newAssets.count).toBe(3);
|
2024-04-12 15:15:41 -04:00
|
|
|
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetB.png`);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should offline missing files', async () => {
|
|
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryA/assetB.png`);
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetB.png`);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
|
|
|
|
|
expect(assets.items).toEqual(
|
|
|
|
|
expect.arrayContaining([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
isOffline: true,
|
|
|
|
|
originalFileName: 'assetB.png',
|
|
|
|
|
}),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should scan new files', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryA/assetC.png`);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetC.png`);
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
|
|
|
|
|
expect(assets.items).toEqual(
|
|
|
|
|
expect.arrayContaining([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
originalFileName: 'assetC.png',
|
|
|
|
|
}),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('with refreshModifiedFiles=true', () => {
|
|
|
|
|
it('should reimport modified files', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_000);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
cpSync(`${testAssetDir}/albums/nature/tanners_ridge.jpg`, `${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_001);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id, { refreshModifiedFiles: true });
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');
|
|
|
|
|
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, {
|
|
|
|
|
libraryId: library.id,
|
|
|
|
|
model: 'NIKON D750',
|
|
|
|
|
});
|
|
|
|
|
expect(assets.count).toBe(1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not reimport unmodified files', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_000);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
cpSync(`${testAssetDir}/albums/nature/tanners_ridge.jpg`, `${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_000);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id, { refreshModifiedFiles: true });
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');
|
|
|
|
|
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, {
|
|
|
|
|
libraryId: library.id,
|
|
|
|
|
model: 'NIKON D750',
|
|
|
|
|
});
|
|
|
|
|
expect(assets.count).toBe(0);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
describe('with refreshAllFiles=true', () => {
|
|
|
|
|
it('should reimport all files', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_000);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
cpSync(`${testAssetDir}/albums/nature/tanners_ridge.jpg`, `${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
await utimes(`${testAssetDir}/temp/directoryA/assetB.jpg`, 447_775_200_000);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id, { refreshAllFiles: true });
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'metadataExtraction');
|
|
|
|
|
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetB.jpg`);
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, {
|
|
|
|
|
libraryId: library.id,
|
|
|
|
|
model: 'NIKON D750',
|
|
|
|
|
});
|
|
|
|
|
expect(assets.count).toBe(1);
|
|
|
|
|
});
|
2024-03-15 09:16:08 -04:00
|
|
|
});
|
2024-02-29 15:10:08 -05:00
|
|
|
});
|
|
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('POST /libraries/:id/removeOffline', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).post(`/libraries/${uuidDto.notFound}/removeOffline`).send({});
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
2024-04-12 15:15:41 -04:00
|
|
|
|
|
|
|
|
it('should remove offline files', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
utils.createImageFile(`${testAssetDir}/temp/directoryA/assetB.png`);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
const { assets: initialAssets } = await utils.metadataSearch(admin.accessToken, {
|
|
|
|
|
libraryId: library.id,
|
|
|
|
|
});
|
|
|
|
|
expect(initialAssets.count).toBe(3);
|
|
|
|
|
|
|
|
|
|
utils.removeImageFile(`${testAssetDir}/temp/directoryA/assetB.png`);
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
const { assets: offlineAssets } = await utils.metadataSearch(admin.accessToken, {
|
|
|
|
|
libraryId: library.id,
|
|
|
|
|
isOffline: true,
|
|
|
|
|
});
|
|
|
|
|
expect(offlineAssets.count).toBe(1);
|
|
|
|
|
|
|
|
|
|
const { status } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.post(`/libraries/${library.id}/removeOffline`)
|
2024-04-12 15:15:41 -04:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send();
|
|
|
|
|
expect(status).toBe(204);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'backgroundTask');
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
|
|
|
|
|
expect(assets.count).toBe(2);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not remove online files', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
const { assets: assetsBefore } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
expect(assetsBefore.count).toBeGreaterThan(1);
|
|
|
|
|
|
|
|
|
|
const { status } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.post(`/libraries/${library.id}/removeOffline`)
|
2024-04-12 15:15:41 -04:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`)
|
|
|
|
|
.send();
|
|
|
|
|
expect(status).toBe(204);
|
|
|
|
|
await utils.waitForQueueFinish(admin.accessToken, 'library');
|
|
|
|
|
|
|
|
|
|
const { assets } = await utils.metadataSearch(admin.accessToken, { libraryId: library.id });
|
|
|
|
|
|
|
|
|
|
expect(assets).toEqual(assetsBefore);
|
|
|
|
|
});
|
2024-02-29 15:10:08 -05:00
|
|
|
});
|
|
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('POST /libraries/:id/validate', () => {
|
2024-02-29 15:10:08 -05:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).post(`/libraries/${uuidDto.notFound}/validate`).send({});
|
2024-02-29 15:10:08 -05:00
|
|
|
|
|
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should pass with no import paths', async () => {
|
2024-03-07 10:14:36 -05:00
|
|
|
const response = await utils.validateLibrary(admin.accessToken, library.id, { importPaths: [] });
|
2024-02-29 15:10:08 -05:00
|
|
|
expect(response.importPaths).toEqual([]);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should fail if path does not exist', async () => {
|
|
|
|
|
const pathToTest = `${testAssetDirInternal}/does/not/exist`;
|
|
|
|
|
|
2024-03-07 10:14:36 -05:00
|
|
|
const response = await utils.validateLibrary(admin.accessToken, library.id, {
|
2024-02-29 15:10:08 -05:00
|
|
|
importPaths: [pathToTest],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(response.importPaths?.length).toEqual(1);
|
|
|
|
|
const pathResponse = response?.importPaths?.at(0);
|
|
|
|
|
|
|
|
|
|
expect(pathResponse).toEqual({
|
|
|
|
|
importPath: pathToTest,
|
|
|
|
|
isValid: false,
|
|
|
|
|
message: `Path does not exist (ENOENT)`,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should fail if path is a file', async () => {
|
|
|
|
|
const pathToTest = `${testAssetDirInternal}/albums/nature/el_torcal_rocks.jpg`;
|
|
|
|
|
|
2024-03-07 10:14:36 -05:00
|
|
|
const response = await utils.validateLibrary(admin.accessToken, library.id, {
|
2024-02-29 15:10:08 -05:00
|
|
|
importPaths: [pathToTest],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(response.importPaths?.length).toEqual(1);
|
|
|
|
|
const pathResponse = response?.importPaths?.at(0);
|
|
|
|
|
|
|
|
|
|
expect(pathResponse).toEqual({
|
|
|
|
|
importPath: pathToTest,
|
|
|
|
|
isValid: false,
|
|
|
|
|
message: `Not a directory`,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-04-12 15:15:41 -04:00
|
|
|
|
2024-05-22 13:24:57 -04:00
|
|
|
describe('DELETE /libraries/:id', () => {
|
2024-04-12 15:15:41 -04:00
|
|
|
it('should require authentication', async () => {
|
2024-05-22 13:24:57 -04:00
|
|
|
const { status, body } = await request(app).delete(`/libraries/${uuidDto.notFound}`);
|
2024-04-12 15:15:41 -04:00
|
|
|
|
|
|
|
|
expect(status).toBe(401);
|
|
|
|
|
expect(body).toEqual(errorDto.unauthorized);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should delete an external library', async () => {
|
2024-05-20 18:09:10 -04:00
|
|
|
const library = await utils.createLibrary(admin.accessToken, { ownerId: admin.userId });
|
2024-04-12 15:15:41 -04:00
|
|
|
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.delete(`/libraries/${library.id}`)
|
2024-04-12 15:15:41 -04:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(204);
|
|
|
|
|
expect(body).toEqual({});
|
|
|
|
|
|
2024-05-20 18:09:10 -04:00
|
|
|
const libraries = await getAllLibraries({ headers: asBearerAuth(admin.accessToken) });
|
2024-04-12 15:15:41 -04:00
|
|
|
expect(libraries).not.toEqual(
|
|
|
|
|
expect.arrayContaining([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
id: library.id,
|
|
|
|
|
}),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should delete an external library with assets', async () => {
|
|
|
|
|
const library = await utils.createLibrary(admin.accessToken, {
|
|
|
|
|
ownerId: admin.userId,
|
|
|
|
|
importPaths: [`${testAssetDirInternal}/temp`],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await scan(admin.accessToken, library.id);
|
|
|
|
|
await utils.waitForWebsocketEvent({ event: 'assetUpload', total: 2 });
|
|
|
|
|
|
|
|
|
|
const { status, body } = await request(app)
|
2024-05-22 13:24:57 -04:00
|
|
|
.delete(`/libraries/${library.id}`)
|
2024-04-12 15:15:41 -04:00
|
|
|
.set('Authorization', `Bearer ${admin.accessToken}`);
|
|
|
|
|
|
|
|
|
|
expect(status).toBe(204);
|
|
|
|
|
expect(body).toEqual({});
|
|
|
|
|
|
2024-05-20 18:09:10 -04:00
|
|
|
const libraries = await getAllLibraries({ headers: asBearerAuth(admin.accessToken) });
|
2024-04-12 15:15:41 -04:00
|
|
|
expect(libraries).not.toEqual(
|
|
|
|
|
expect.arrayContaining([
|
|
|
|
|
expect.objectContaining({
|
|
|
|
|
id: library.id,
|
|
|
|
|
}),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// ensure no files get deleted
|
|
|
|
|
expect(existsSync(`${testAssetDir}/temp/directoryA/assetA.png`)).toBe(true);
|
|
|
|
|
expect(existsSync(`${testAssetDir}/temp/directoryB/assetB.png`)).toBe(true);
|
|
|
|
|
});
|
|
|
|
|
});
|
2024-02-29 15:10:08 -05:00
|
|
|
});
|