refactor: test mocks (#16008)

This commit is contained in:
Jason Rasmussen
2025-02-10 18:47:42 -05:00
committed by GitHub
parent 8794c84e9d
commit 735f8d661e
74 changed files with 3820 additions and 4043 deletions

View File

@@ -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',