mirror of
https://github.com/immich-app/immich.git
synced 2025-12-22 17:24:56 +03:00
46
server/src/services/storage.service.spec.ts
Normal file
46
server/src/services/storage.service.spec.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { IStorageRepository } from 'src/interfaces/storage.repository';
|
||||
import { StorageService } from 'src/services/storage.service';
|
||||
import { newStorageRepositoryMock } from 'test/repositories/storage.repository.mock';
|
||||
|
||||
describe(StorageService.name, () => {
|
||||
let sut: StorageService;
|
||||
let storageMock: jest.Mocked<IStorageRepository>;
|
||||
|
||||
beforeEach(() => {
|
||||
storageMock = newStorageRepositoryMock();
|
||||
sut = new StorageService(storageMock);
|
||||
});
|
||||
|
||||
it('should work', () => {
|
||||
expect(sut).toBeDefined();
|
||||
});
|
||||
|
||||
describe('init', () => {
|
||||
it('should create the library folder on initialization', () => {
|
||||
sut.init();
|
||||
expect(storageMock.mkdirSync).toHaveBeenCalledWith('upload/library');
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleDeleteFiles', () => {
|
||||
it('should handle null values', async () => {
|
||||
await sut.handleDeleteFiles({ files: [undefined, null] });
|
||||
|
||||
expect(storageMock.unlink).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should handle an error removing a file', async () => {
|
||||
storageMock.unlink.mockRejectedValue(new Error('something-went-wrong'));
|
||||
|
||||
await sut.handleDeleteFiles({ files: ['path/to/something'] });
|
||||
|
||||
expect(storageMock.unlink).toHaveBeenCalledWith('path/to/something');
|
||||
});
|
||||
|
||||
it('should remove the file', async () => {
|
||||
await sut.handleDeleteFiles({ files: ['path/to/something'] });
|
||||
|
||||
expect(storageMock.unlink).toHaveBeenCalledWith('path/to/something');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user