2024-03-21 04:15:09 +01:00
|
|
|
import { serverVersion } from 'src/constants';
|
2024-03-20 22:02:51 +01:00
|
|
|
import { SystemMetadataKey } from 'src/entities/system-metadata.entity';
|
2024-03-22 23:24:02 +01:00
|
|
|
import { IEventRepository } from 'src/interfaces/event.interface';
|
2024-03-21 12:59:49 +01:00
|
|
|
import { IServerInfoRepository } from 'src/interfaces/server-info.interface';
|
|
|
|
import { IStorageRepository } from 'src/interfaces/storage.interface';
|
|
|
|
import { ISystemConfigRepository } from 'src/interfaces/system-config.interface';
|
|
|
|
import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface';
|
|
|
|
import { IUserRepository } from 'src/interfaces/user.interface';
|
2024-03-21 00:07:30 +01:00
|
|
|
import { ServerInfoService } from 'src/services/server-info.service';
|
2024-03-22 23:24:02 +01:00
|
|
|
import { newEventRepositoryMock } from 'test/repositories/event.repository.mock';
|
2024-03-20 19:32:04 +01:00
|
|
|
import { newStorageRepositoryMock } from 'test/repositories/storage.repository.mock';
|
|
|
|
import { newSystemConfigRepositoryMock } from 'test/repositories/system-config.repository.mock';
|
|
|
|
import { newServerInfoRepositoryMock } from 'test/repositories/system-info.repository.mock';
|
|
|
|
import { newSystemMetadataRepositoryMock } from 'test/repositories/system-metadata.repository.mock';
|
|
|
|
import { newUserRepositoryMock } from 'test/repositories/user.repository.mock';
|
2023-03-22 03:49:19 +01:00
|
|
|
|
|
|
|
describe(ServerInfoService.name, () => {
|
|
|
|
let sut: ServerInfoService;
|
2024-03-22 23:24:02 +01:00
|
|
|
let eventMock: jest.Mocked<IEventRepository>;
|
2023-08-18 06:55:26 +02:00
|
|
|
let configMock: jest.Mocked<ISystemConfigRepository>;
|
2023-10-24 17:05:42 +02:00
|
|
|
let serverInfoMock: jest.Mocked<IServerInfoRepository>;
|
2023-03-22 03:49:19 +01:00
|
|
|
let storageMock: jest.Mocked<IStorageRepository>;
|
|
|
|
let userMock: jest.Mocked<IUserRepository>;
|
2024-01-04 06:28:32 +01:00
|
|
|
let systemMetadataMock: jest.Mocked<ISystemMetadataRepository>;
|
2023-03-22 03:49:19 +01:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2023-08-18 06:55:26 +02:00
|
|
|
configMock = newSystemConfigRepositoryMock();
|
2024-03-22 23:24:02 +01:00
|
|
|
eventMock = newEventRepositoryMock();
|
2023-10-24 17:05:42 +02:00
|
|
|
serverInfoMock = newServerInfoRepositoryMock();
|
2023-03-22 03:49:19 +01:00
|
|
|
storageMock = newStorageRepositoryMock();
|
|
|
|
userMock = newUserRepositoryMock();
|
2024-01-04 06:28:32 +01:00
|
|
|
systemMetadataMock = newSystemMetadataRepositoryMock();
|
|
|
|
|
2024-03-22 23:24:02 +01:00
|
|
|
sut = new ServerInfoService(eventMock, configMock, userMock, serverInfoMock, storageMock, systemMetadataMock);
|
2023-03-22 03:49:19 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should work', () => {
|
|
|
|
expect(sut).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('getInfo', () => {
|
|
|
|
it('should return the disk space as B', async () => {
|
|
|
|
storageMock.checkDiskUsage.mockResolvedValue({ free: 200, available: 300, total: 500 });
|
|
|
|
|
|
|
|
await expect(sut.getInfo()).resolves.toEqual({
|
|
|
|
diskAvailable: '300 B',
|
|
|
|
diskAvailableRaw: 300,
|
|
|
|
diskSize: '500 B',
|
|
|
|
diskSizeRaw: 500,
|
|
|
|
diskUsagePercentage: 60,
|
|
|
|
diskUse: '300 B',
|
|
|
|
diskUseRaw: 300,
|
|
|
|
});
|
|
|
|
|
2023-05-25 04:05:31 +02:00
|
|
|
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.getInfo()).resolves.toEqual({
|
|
|
|
diskAvailable: '293.0 KiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskAvailableRaw: 300_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskSize: '488.3 KiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskSizeRaw: 500_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskUsagePercentage: 60,
|
|
|
|
diskUse: '293.0 KiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskUseRaw: 300_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
});
|
|
|
|
|
2023-05-25 04:05:31 +02: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.getInfo()).resolves.toEqual({
|
|
|
|
diskAvailable: '286.1 MiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskAvailableRaw: 300_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskSize: '476.8 MiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskSizeRaw: 500_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskUsagePercentage: 60,
|
|
|
|
diskUse: '286.1 MiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskUseRaw: 300_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
});
|
|
|
|
|
2023-05-25 04:05:31 +02: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.getInfo()).resolves.toEqual({
|
|
|
|
diskAvailable: '279.4 GiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskAvailableRaw: 300_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskSize: '465.7 GiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskSizeRaw: 500_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskUsagePercentage: 60,
|
|
|
|
diskUse: '279.4 GiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskUseRaw: 300_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
});
|
|
|
|
|
2023-05-25 04:05:31 +02: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.getInfo()).resolves.toEqual({
|
|
|
|
diskAvailable: '272.8 TiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskAvailableRaw: 300_000_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskSize: '454.7 TiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskSizeRaw: 500_000_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskUsagePercentage: 60,
|
|
|
|
diskUse: '272.8 TiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskUseRaw: 300_000_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
});
|
|
|
|
|
2023-05-25 04:05:31 +02: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.getInfo()).resolves.toEqual({
|
|
|
|
diskAvailable: '266.5 PiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskAvailableRaw: 300_000_000_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskSize: '444.1 PiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskSizeRaw: 500_000_000_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
diskUsagePercentage: 60,
|
|
|
|
diskUse: '266.5 PiB',
|
2024-02-02 04:18:00 +01:00
|
|
|
diskUseRaw: 300_000_000_000_000_000,
|
2023-03-22 03:49:19 +01:00
|
|
|
});
|
|
|
|
|
2023-05-25 04:05:31 +02: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('getVersion', () => {
|
|
|
|
it('should respond the server version', () => {
|
|
|
|
expect(sut.getVersion()).toEqual(serverVersion);
|
|
|
|
});
|
2023-09-09 04:51:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('getFeatures', () => {
|
|
|
|
it('should respond the server features', async () => {
|
|
|
|
await expect(sut.getFeatures()).resolves.toEqual({
|
2024-01-29 15:51:22 +01:00
|
|
|
smartSearch: true,
|
2023-09-09 04:51:46 +02:00
|
|
|
facialRecognition: true,
|
|
|
|
map: true,
|
2023-09-26 09:03:57 +02:00
|
|
|
reverseGeocoding: true,
|
2023-09-09 04:51:46 +02:00
|
|
|
oauth: false,
|
|
|
|
oauthAutoLaunch: false,
|
|
|
|
passwordLogin: true,
|
|
|
|
search: true,
|
|
|
|
sidecar: true,
|
|
|
|
configFile: false,
|
2023-10-06 09:01:14 +02:00
|
|
|
trash: true,
|
2023-09-09 04:51:46 +02:00
|
|
|
});
|
|
|
|
expect(configMock.load).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2023-08-18 06:55:26 +02:00
|
|
|
|
2023-09-09 04:51:46 +02:00
|
|
|
describe('getConfig', () => {
|
|
|
|
it('should respond the server configuration', async () => {
|
|
|
|
await expect(sut.getConfig()).resolves.toEqual({
|
|
|
|
loginPageMessage: '',
|
|
|
|
oauthButtonText: 'Login with OAuth',
|
2023-10-06 09:01:14 +02:00
|
|
|
trashDays: 30,
|
2024-03-06 06:45:40 +01:00
|
|
|
userDeleteDelay: 7,
|
2024-01-04 06:28:32 +01:00
|
|
|
isInitialized: undefined,
|
|
|
|
isOnboarded: false,
|
2024-01-04 03:54:48 +01:00
|
|
|
externalDomain: '',
|
2023-08-18 06:55:26 +02:00
|
|
|
});
|
2023-09-09 04:51:46 +02:00
|
|
|
expect(configMock.load).toHaveBeenCalled();
|
2023-08-18 06:55:26 +02:00
|
|
|
});
|
2023-03-22 03:49:19 +01:00
|
|
|
});
|
|
|
|
|
2024-01-04 06:28:32 +01:00
|
|
|
describe('setAdminOnboarding', () => {
|
|
|
|
it('should set admin onboarding to true', async () => {
|
|
|
|
await sut.setAdminOnboarding();
|
|
|
|
expect(systemMetadataMock.set).toHaveBeenCalledWith(SystemMetadataKey.ADMIN_ONBOARDING, { isOnboarded: true });
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-03-22 03:49:19 +01:00
|
|
|
describe('getStats', () => {
|
|
|
|
it('should total up usage by user', async () => {
|
|
|
|
userMock.getUserStats.mockResolvedValue([
|
|
|
|
{
|
|
|
|
userId: 'user1',
|
2023-11-12 02:03:32 +01:00
|
|
|
userName: '1 User',
|
2023-03-22 03:49:19 +01:00
|
|
|
photos: 10,
|
|
|
|
videos: 11,
|
2024-02-02 04:18:00 +01:00
|
|
|
usage: 12_345,
|
2024-01-13 01:43:36 +01:00
|
|
|
quotaSizeInBytes: 0,
|
2023-03-22 03:49:19 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: 'user2',
|
2023-11-12 02:03:32 +01:00
|
|
|
userName: '2 User',
|
2023-03-22 03:49:19 +01:00
|
|
|
photos: 10,
|
|
|
|
videos: 20,
|
2024-02-02 04:18:00 +01:00
|
|
|
usage: 123_456,
|
2024-01-13 01:43:36 +01:00
|
|
|
quotaSizeInBytes: 0,
|
2023-03-22 03:49:19 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
userId: 'user3',
|
2023-11-12 02:03:32 +01:00
|
|
|
userName: '3 User',
|
2023-03-22 03:49:19 +01:00
|
|
|
photos: 100,
|
|
|
|
videos: 0,
|
2024-02-02 04:18:00 +01:00
|
|
|
usage: 987_654,
|
2024-01-13 01:43:36 +01:00
|
|
|
quotaSizeInBytes: 0,
|
2023-03-22 03:49:19 +01:00
|
|
|
},
|
|
|
|
]);
|
|
|
|
|
2023-11-04 02:33:15 +01:00
|
|
|
await expect(sut.getStatistics()).resolves.toEqual({
|
2023-03-22 03:49:19 +01:00
|
|
|
photos: 120,
|
|
|
|
videos: 31,
|
2024-02-02 04:18:00 +01:00
|
|
|
usage: 1_123_455,
|
2023-03-22 03:49:19 +01:00
|
|
|
usageByUser: [
|
|
|
|
{
|
|
|
|
photos: 10,
|
2024-01-13 01:43:36 +01:00
|
|
|
quotaSizeInBytes: 0,
|
2024-02-02 04:18:00 +01:00
|
|
|
usage: 12_345,
|
2023-11-12 02:03:32 +01:00
|
|
|
userName: '1 User',
|
2023-03-22 03:49:19 +01:00
|
|
|
userId: 'user1',
|
|
|
|
videos: 11,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
photos: 10,
|
2024-01-13 01:43:36 +01:00
|
|
|
quotaSizeInBytes: 0,
|
2024-02-02 04:18:00 +01:00
|
|
|
usage: 123_456,
|
2023-11-12 02:03:32 +01:00
|
|
|
userName: '2 User',
|
2023-03-22 03:49:19 +01:00
|
|
|
userId: 'user2',
|
|
|
|
videos: 20,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
photos: 100,
|
2024-01-13 01:43:36 +01:00
|
|
|
quotaSizeInBytes: 0,
|
2024-02-02 04:18:00 +01:00
|
|
|
usage: 987_654,
|
2023-11-12 02:03:32 +01:00
|
|
|
userName: '3 User',
|
2023-03-22 03:49:19 +01:00
|
|
|
userId: 'user3',
|
|
|
|
videos: 0,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(userMock.getUserStats).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|