From e769ae6deb2e001bce19519327fc970aa9d77b17 Mon Sep 17 00:00:00 2001 From: Thorsten Lanfer Date: Tue, 17 Sep 2024 22:01:37 +0200 Subject: [PATCH] Add tests to check if getClient was used correctly Signed-off-by: Thorsten Lanfer --- .../actions/gitlabGroupEnsureExists.test.ts | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.test.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.test.ts index b425a4fac8..1192052e6d 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.test.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabGroupEnsureExists.test.ts @@ -18,6 +18,7 @@ import { ConfigReader } from '@backstage/core-app-api'; import { ScmIntegrations } from '@backstage/integration'; import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils'; import { createGitlabGroupEnsureExistsAction } from './gitlabGroupEnsureExists'; +import { getClient } from '../util'; const mockGitlabClient = { Groups: { @@ -34,6 +35,11 @@ jest.mock('@gitbeaker/rest', () => ({ }, })); +jest.mock('../util', () => ({ + getClient: jest.fn().mockImplementation(() => mockGitlabClient), + parseRepoUrl: () => ({ host: 'gitlab.com', owner: 'owner', repo: 'repo' }), +})); + describe('gitlab:group:ensureExists', () => { beforeEach(() => { jest.clearAllMocks(); @@ -149,11 +155,11 @@ describe('gitlab:group:ensureExists', () => { }, }); - // expect(Gitlab).toHaveBeenCalledWith( - // expect.objectContaining({ - // 'token': 'tokenlols', - // }), - // ); + expect(getClient).toHaveBeenCalledWith( + expect.not.objectContaining({ + token: expect.anything(), + }), + ); }); it('should use a provided token as bearer authentication', async () => { @@ -173,10 +179,10 @@ describe('gitlab:group:ensureExists', () => { }, }); - // expect(Gitlab).toHaveBeenCalledWith( - // expect.objectContaining({ - // oauthToken: 'mysecrettoken', - // }), - // ); + expect(getClient).toHaveBeenCalledWith( + expect.objectContaining({ + token: 'mysecrettoken', + }), + ); }); });