From c71bc7ac71159712eac25b2f12bb8e12c17c2138 Mon Sep 17 00:00:00 2001 From: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> Date: Thu, 10 Oct 2024 15:04:44 +0200 Subject: [PATCH] chore: cli unit tests (#13343) --- server/src/services/cli.service.spec.ts | 40 ++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/server/src/services/cli.service.spec.ts b/server/src/services/cli.service.spec.ts index 3ccc122eceeb0..ef520070eaeb5 100644 --- a/server/src/services/cli.service.spec.ts +++ b/server/src/services/cli.service.spec.ts @@ -1,3 +1,4 @@ +import { ISystemMetadataRepository } from 'src/interfaces/system-metadata.interface'; import { IUserRepository } from 'src/interfaces/user.interface'; import { CliService } from 'src/services/cli.service'; import { userStub } from 'test/fixtures/user.stub'; @@ -8,9 +9,18 @@ describe(CliService.name, () => { let sut: CliService; let userMock: Mocked; + let systemMock: Mocked; beforeEach(() => { - ({ sut, userMock } = newTestService(CliService)); + ({ sut, userMock, systemMock } = newTestService(CliService)); + }); + + describe('listUsers', () => { + it('should list users', async () => { + userMock.getList.mockResolvedValue([userStub.admin]); + await expect(sut.listUsers()).resolves.toEqual([expect.objectContaining({ isAdmin: true })]); + expect(userMock.getList).toHaveBeenCalledWith({ withDeleted: true }); + }); }); describe('resetAdminPassword', () => { @@ -51,4 +61,32 @@ describe(CliService.name, () => { expect(update.password).toBeDefined(); }); }); + + describe('disablePasswordLogin', () => { + it('should disable password login', async () => { + await sut.disablePasswordLogin(); + expect(systemMock.set).toHaveBeenCalledWith('system-config', { passwordLogin: { enabled: false } }); + }); + }); + + describe('enablePasswordLogin', () => { + it('should enable password login', async () => { + await sut.enablePasswordLogin(); + expect(systemMock.set).toHaveBeenCalledWith('system-config', {}); + }); + }); + + describe('disableOAuthLogin', () => { + it('should disable oauth login', async () => { + await sut.disableOAuthLogin(); + expect(systemMock.set).toHaveBeenCalledWith('system-config', {}); + }); + }); + + describe('enableOAuthLogin', () => { + it('should enable oauth login', async () => { + await sut.enableOAuthLogin(); + expect(systemMock.set).toHaveBeenCalledWith('system-config', { oauth: { enabled: true } }); + }); + }); });