1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-10 13:56:47 +01:00
immich/server/src/services/server-info.service.spec.ts

249 lines
7.5 KiB
TypeScript
Raw Normal View History

import { ILoggerRepository } from 'src/interfaces/logger.interface';
import { IStorageRepository } from 'src/interfaces/storage.interface';
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
import { IUserRepository } from 'src/interfaces/user.interface';
import { ServerInfoService } from 'src/services/server-info.service';
import { newLoggerRepositoryMock } from 'test/repositories/logger.repository.mock';
import { newStorageRepositoryMock } from 'test/repositories/storage.repository.mock';
import { newSystemMetadataRepositoryMock } from 'test/repositories/system-metadata.repository.mock';
import { newUserRepositoryMock } from 'test/repositories/user.repository.mock';
import { Mocked } from 'vitest';
2023-03-22 03:49:19 +01:00
describe(ServerInfoService.name, () => {
let sut: ServerInfoService;
let storageMock: Mocked<IStorageRepository>;
let userMock: Mocked<IUserRepository>;
let systemMock: Mocked<ISystemMetadataRepository>;
let loggerMock: Mocked<ILoggerRepository>;
2023-03-22 03:49:19 +01:00
beforeEach(() => {
storageMock = newStorageRepositoryMock();
userMock = newUserRepositoryMock();
systemMock = newSystemMetadataRepositoryMock();
loggerMock = newLoggerRepositoryMock();
sut = new ServerInfoService(userMock, storageMock, systemMock, loggerMock);
2023-03-22 03:49:19 +01:00
});
it('should work', () => {
expect(sut).toBeDefined();
});
describe('getStorage', () => {
2023-03-22 03:49:19 +01:00
it('should return the disk space as B', async () => {
storageMock.checkDiskUsage.mockResolvedValue({ free: 200, available: 300, total: 500 });
await expect(sut.getStorage()).resolves.toEqual({
2023-03-22 03:49:19 +01:00
diskAvailable: '300 B',
diskAvailableRaw: 300,
diskSize: '500 B',
diskSizeRaw: 500,
diskUsagePercentage: 60,
diskUse: '300 B',
diskUseRaw: 300,
});
expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library');
2023-03-22 03:49:19 +01:00
});
it('should return the disk space as KiB', async () => {
storageMock.checkDiskUsage.mockResolvedValue({ free: 200_000, available: 300_000, total: 500_000 });
await expect(sut.getStorage()).resolves.toEqual({
2023-03-22 03:49:19 +01:00
diskAvailable: '293.0 KiB',
diskAvailableRaw: 300_000,
2023-03-22 03:49:19 +01:00
diskSize: '488.3 KiB',
diskSizeRaw: 500_000,
2023-03-22 03:49:19 +01:00
diskUsagePercentage: 60,
diskUse: '293.0 KiB',
diskUseRaw: 300_000,
2023-03-22 03:49:19 +01:00
});
expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library');
2023-03-22 03:49:19 +01:00
});
it('should return the disk space as MiB', async () => {
storageMock.checkDiskUsage.mockResolvedValue({ free: 200_000_000, available: 300_000_000, total: 500_000_000 });
await expect(sut.getStorage()).resolves.toEqual({
2023-03-22 03:49:19 +01:00
diskAvailable: '286.1 MiB',
diskAvailableRaw: 300_000_000,
2023-03-22 03:49:19 +01:00
diskSize: '476.8 MiB',
diskSizeRaw: 500_000_000,
2023-03-22 03:49:19 +01:00
diskUsagePercentage: 60,
diskUse: '286.1 MiB',
diskUseRaw: 300_000_000,
2023-03-22 03:49:19 +01:00
});
expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library');
2023-03-22 03:49:19 +01:00
});
it('should return the disk space as GiB', async () => {
storageMock.checkDiskUsage.mockResolvedValue({
free: 200_000_000_000,
available: 300_000_000_000,
total: 500_000_000_000,
});
await expect(sut.getStorage()).resolves.toEqual({
2023-03-22 03:49:19 +01:00
diskAvailable: '279.4 GiB',
diskAvailableRaw: 300_000_000_000,
2023-03-22 03:49:19 +01:00
diskSize: '465.7 GiB',
diskSizeRaw: 500_000_000_000,
2023-03-22 03:49:19 +01:00
diskUsagePercentage: 60,
diskUse: '279.4 GiB',
diskUseRaw: 300_000_000_000,
2023-03-22 03:49:19 +01:00
});
expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library');
2023-03-22 03:49:19 +01:00
});
it('should return the disk space as TiB', async () => {
storageMock.checkDiskUsage.mockResolvedValue({
free: 200_000_000_000_000,
available: 300_000_000_000_000,
total: 500_000_000_000_000,
});
await expect(sut.getStorage()).resolves.toEqual({
2023-03-22 03:49:19 +01:00
diskAvailable: '272.8 TiB',
diskAvailableRaw: 300_000_000_000_000,
2023-03-22 03:49:19 +01:00
diskSize: '454.7 TiB',
diskSizeRaw: 500_000_000_000_000,
2023-03-22 03:49:19 +01:00
diskUsagePercentage: 60,
diskUse: '272.8 TiB',
diskUseRaw: 300_000_000_000_000,
2023-03-22 03:49:19 +01:00
});
expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library');
2023-03-22 03:49:19 +01:00
});
it('should return the disk space as PiB', async () => {
storageMock.checkDiskUsage.mockResolvedValue({
free: 200_000_000_000_000_000,
available: 300_000_000_000_000_000,
total: 500_000_000_000_000_000,
});
await expect(sut.getStorage()).resolves.toEqual({
2023-03-22 03:49:19 +01:00
diskAvailable: '266.5 PiB',
diskAvailableRaw: 300_000_000_000_000_000,
2023-03-22 03:49:19 +01:00
diskSize: '444.1 PiB',
diskSizeRaw: 500_000_000_000_000_000,
2023-03-22 03:49:19 +01:00
diskUsagePercentage: 60,
diskUse: '266.5 PiB',
diskUseRaw: 300_000_000_000_000_000,
2023-03-22 03:49:19 +01:00
});
expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library');
2023-03-22 03:49:19 +01:00
});
});
describe('ping', () => {
it('should respond with pong', () => {
expect(sut.ping()).toEqual({ res: 'pong' });
});
});
describe('getFeatures', () => {
it('should respond the server features', async () => {
await expect(sut.getFeatures()).resolves.toEqual({
smartSearch: true,
duplicateDetection: true,
facialRecognition: true,
map: true,
reverseGeocoding: true,
oauth: false,
oauthAutoLaunch: false,
passwordLogin: true,
search: true,
sidecar: true,
configFile: false,
feat(server): trash asset (#4015) * refactor(server): delete assets endpoint * fix: formatting * chore: cleanup * chore: open api * chore(mobile): replace DeleteAssetDTO with BulkIdsDTOs * feat: trash an asset * chore(server): formatting * chore: open api * chore: wording * chore: open-api * feat(server): add withDeleted to getAssets queries * WIP: mobile-recycle-bin * feat(server): recycle-bin to system config * feat(web): use recycle-bin system config * chore(server): domain assetcore removed * chore(server): rename recycle-bin to trash * chore(web): rename recycle-bin to trash * chore(server): always send soft deleted assets for getAllByUserId * chore(web): formatting * feat(server): permanent delete assets older than trashed period * feat(web): trash empty placeholder image * feat(server): empty trash * feat(web): empty trash * WIP: mobile-recycle-bin * refactor(server): empty / restore trash to separate endpoint * test(server): handle failures * test(server): fix e2e server-info test * test(server): deletion test refactor * feat(mobile): use map settings from server-config to enable / disable map * feat(mobile): trash asset * fix(server): operations on assets in trash * feat(web): show trash statistics * fix(web): handle trash enabled * fix(mobile): restore updates from trash * fix(server): ignore trashed assets for person * fix(server): add / remove search index when trashed / restored * chore(web): format * fix(server): asset service test * fix(server): include trashed assts for duplicates from uploads * feat(mobile): no dialog for trash, always dialog for permanent delete * refactor(mobile): use isar where instead of dart filter * refactor(mobile): asset provide - handle deletes in single db txn * chore(mobile): review changes * feat(web): confirmation before empty trash * server: review changes * fix(server): handle library changes * fix: filter external assets from getting trashed / deleted * fix(server): empty-bin * feat: broadcast config update events through ws * change order of trash button on mobile * styling * fix(mobile): do not show trashed toast for local only assets --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-10-06 09:01:14 +02:00
trash: true,
feat(server): email notifications (#8447) * feat(server): add `react-mail` as mail template engine and `nodemailer` * feat(server): add `smtp` related configs to `SystemConfig` * feat(web): add page for SMTP settings * feat(server): add `react-email.adapter` This adapter render the React-Email into HTML and plain/text email. The output is set as the body of the email. * feat(server): add `MailRepository` and `MailService` Allow to use the NestJS-modules-mailer module to send SMTP emails. This is the base transport for the `NotificationRepository` * feat(server): register the job dispatcher and Job for async email This allows to queue email sending jobs for the `EmailService`. * feat(server): add `NotificationRepository` and `NotificationService` This act as a middleware to properly route the notification to the right transport. As POC I've only implemented a simple SMTP transport. * feat(server): add `welcome` email template * feat(server): add the first notification on `createUser` in `UserService` This trigger an event for the `NotificationRepository` that once processes by using the global config and per-user config will carry the payload to the right notification transport. * chore: clean up * chore: clean up web * fix: type errors" * fix package lock * fix mail sending, option to ignore certs * chore: open api * chore: clean up * remove unused import * feat: email feature flag * chore: remove unused interface * small styling --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Daniel Dietzler <mail@ddietzler.dev> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2024-05-02 16:43:18 +02:00
email: false,
});
expect(systemMock.get).toHaveBeenCalled();
});
});
describe('getConfig', () => {
it('should respond the server configuration', async () => {
await expect(sut.getConfig()).resolves.toEqual({
loginPageMessage: '',
oauthButtonText: 'Login with OAuth',
feat(server): trash asset (#4015) * refactor(server): delete assets endpoint * fix: formatting * chore: cleanup * chore: open api * chore(mobile): replace DeleteAssetDTO with BulkIdsDTOs * feat: trash an asset * chore(server): formatting * chore: open api * chore: wording * chore: open-api * feat(server): add withDeleted to getAssets queries * WIP: mobile-recycle-bin * feat(server): recycle-bin to system config * feat(web): use recycle-bin system config * chore(server): domain assetcore removed * chore(server): rename recycle-bin to trash * chore(web): rename recycle-bin to trash * chore(server): always send soft deleted assets for getAllByUserId * chore(web): formatting * feat(server): permanent delete assets older than trashed period * feat(web): trash empty placeholder image * feat(server): empty trash * feat(web): empty trash * WIP: mobile-recycle-bin * refactor(server): empty / restore trash to separate endpoint * test(server): handle failures * test(server): fix e2e server-info test * test(server): deletion test refactor * feat(mobile): use map settings from server-config to enable / disable map * feat(mobile): trash asset * fix(server): operations on assets in trash * feat(web): show trash statistics * fix(web): handle trash enabled * fix(mobile): restore updates from trash * fix(server): ignore trashed assets for person * fix(server): add / remove search index when trashed / restored * chore(web): format * fix(server): asset service test * fix(server): include trashed assts for duplicates from uploads * feat(mobile): no dialog for trash, always dialog for permanent delete * refactor(mobile): use isar where instead of dart filter * refactor(mobile): asset provide - handle deletes in single db txn * chore(mobile): review changes * feat(web): confirmation before empty trash * server: review changes * fix(server): handle library changes * fix: filter external assets from getting trashed / deleted * fix(server): empty-bin * feat: broadcast config update events through ws * change order of trash button on mobile * styling * fix(mobile): do not show trashed toast for local only assets --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com> Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
2023-10-06 09:01:14 +02:00
trashDays: 30,
userDeleteDelay: 7,
isInitialized: undefined,
isOnboarded: false,
externalDomain: '',
});
expect(systemMock.get).toHaveBeenCalled();
});
2023-03-22 03:49:19 +01:00
});
describe('getStats', () => {
it('should total up usage by user', async () => {
userMock.getUserStats.mockResolvedValue([
{
userId: 'user1',
userName: '1 User',
2023-03-22 03:49:19 +01:00
photos: 10,
videos: 11,
usage: 12_345,
quotaSizeInBytes: 0,
2023-03-22 03:49:19 +01:00
},
{
userId: 'user2',
userName: '2 User',
2023-03-22 03:49:19 +01:00
photos: 10,
videos: 20,
usage: 123_456,
quotaSizeInBytes: 0,
2023-03-22 03:49:19 +01:00
},
{
userId: 'user3',
userName: '3 User',
2023-03-22 03:49:19 +01:00
photos: 100,
videos: 0,
usage: 987_654,
quotaSizeInBytes: 0,
2023-03-22 03:49:19 +01:00
},
]);
await expect(sut.getStatistics()).resolves.toEqual({
2023-03-22 03:49:19 +01:00
photos: 120,
videos: 31,
usage: 1_123_455,
2023-03-22 03:49:19 +01:00
usageByUser: [
{
photos: 10,
quotaSizeInBytes: 0,
usage: 12_345,
userName: '1 User',
2023-03-22 03:49:19 +01:00
userId: 'user1',
videos: 11,
},
{
photos: 10,
quotaSizeInBytes: 0,
usage: 123_456,
userName: '2 User',
2023-03-22 03:49:19 +01:00
userId: 'user2',
videos: 20,
},
{
photos: 100,
quotaSizeInBytes: 0,
usage: 987_654,
userName: '3 User',
2023-03-22 03:49:19 +01:00
userId: 'user3',
videos: 0,
},
],
});
expect(userMock.getUserStats).toHaveBeenCalled();
});
});
});