mirror of
https://github.com/immich-app/immich.git
synced 2026-03-07 02:27:23 +03:00
refactor: test mocks (#16008)
This commit is contained in:
@@ -1,15 +1,13 @@
|
||||
import { SystemMetadataKey } from 'src/enum';
|
||||
import { SystemMetadataService } from 'src/services/system-metadata.service';
|
||||
import { ISystemMetadataRepository } from 'src/types';
|
||||
import { newTestService } from 'test/utils';
|
||||
import { Mocked } from 'vitest';
|
||||
import { newTestService, ServiceMocks } from 'test/utils';
|
||||
|
||||
describe(SystemMetadataService.name, () => {
|
||||
let sut: SystemMetadataService;
|
||||
let systemMock: Mocked<ISystemMetadataRepository>;
|
||||
let mocks: ServiceMocks;
|
||||
|
||||
beforeEach(() => {
|
||||
({ sut, systemMock } = newTestService(SystemMetadataService));
|
||||
({ sut, mocks } = newTestService(SystemMetadataService));
|
||||
});
|
||||
|
||||
it('should work', () => {
|
||||
@@ -18,32 +16,32 @@ describe(SystemMetadataService.name, () => {
|
||||
|
||||
describe('getAdminOnboarding', () => {
|
||||
it('should get isOnboarded state', async () => {
|
||||
systemMock.get.mockResolvedValue({ isOnboarded: true });
|
||||
mocks.systemMetadata.get.mockResolvedValue({ isOnboarded: true });
|
||||
await expect(sut.getAdminOnboarding()).resolves.toEqual({ isOnboarded: true });
|
||||
expect(systemMock.get).toHaveBeenCalledWith('admin-onboarding');
|
||||
expect(mocks.systemMetadata.get).toHaveBeenCalledWith('admin-onboarding');
|
||||
});
|
||||
|
||||
it('should default isOnboarded to false', async () => {
|
||||
await expect(sut.getAdminOnboarding()).resolves.toEqual({ isOnboarded: false });
|
||||
expect(systemMock.get).toHaveBeenCalledWith('admin-onboarding');
|
||||
expect(mocks.systemMetadata.get).toHaveBeenCalledWith('admin-onboarding');
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateAdminOnboarding', () => {
|
||||
it('should update isOnboarded to true', async () => {
|
||||
await expect(sut.updateAdminOnboarding({ isOnboarded: true })).resolves.toBeUndefined();
|
||||
expect(systemMock.set).toHaveBeenCalledWith(SystemMetadataKey.ADMIN_ONBOARDING, { isOnboarded: true });
|
||||
expect(mocks.systemMetadata.set).toHaveBeenCalledWith(SystemMetadataKey.ADMIN_ONBOARDING, { isOnboarded: true });
|
||||
});
|
||||
|
||||
it('should update isOnboarded to false', async () => {
|
||||
await expect(sut.updateAdminOnboarding({ isOnboarded: false })).resolves.toBeUndefined();
|
||||
expect(systemMock.set).toHaveBeenCalledWith(SystemMetadataKey.ADMIN_ONBOARDING, { isOnboarded: false });
|
||||
expect(mocks.systemMetadata.set).toHaveBeenCalledWith(SystemMetadataKey.ADMIN_ONBOARDING, { isOnboarded: false });
|
||||
});
|
||||
});
|
||||
|
||||
describe('getReverseGeocodingState', () => {
|
||||
it('should get reverse geocoding state', async () => {
|
||||
systemMock.get.mockResolvedValue({ lastUpdate: '2024-01-01', lastImportFileName: 'foo.bar' });
|
||||
mocks.systemMetadata.get.mockResolvedValue({ lastUpdate: '2024-01-01', lastImportFileName: 'foo.bar' });
|
||||
await expect(sut.getReverseGeocodingState()).resolves.toEqual({
|
||||
lastUpdate: '2024-01-01',
|
||||
lastImportFileName: 'foo.bar',
|
||||
|
||||
Reference in New Issue
Block a user