Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: cli unit tests #13343

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion server/src/services/cli.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -8,9 +9,18 @@ describe(CliService.name, () => {
let sut: CliService;

let userMock: Mocked<IUserRepository>;
let systemMock: Mocked<ISystemMetadataRepository>;

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', () => {
Expand Down Expand Up @@ -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 } });
});
});
});
Loading