From d7b27f68599378171e9397389fd6b2dfb521ec70 Mon Sep 17 00:00:00 2001 From: ElaineDeMattosSilvaB Date: Thu, 26 Mar 2026 22:06:40 +0100 Subject: [PATCH] fix: tests again Signed-off-by: ElaineDeMattosSilvaB --- .../src/actions/gitlabRepoPush.test.ts | 103 ++++++++++++++++-- 1 file changed, 96 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.test.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.test.ts index 559f41ddcd..c0fef779cd 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.test.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/gitlabRepoPush.test.ts @@ -57,6 +57,11 @@ describe('createGitLabCommit', () => { beforeEach(() => { mockDir.clear(); + jest.clearAllMocks(); + + mockGitlabClient.Commits.create.mockResolvedValue({ + id: 'bb6bce457ed069a38ef8d16ef38602972c7735c5', + }); const config = new ConfigReader({ integrations: { @@ -107,7 +112,6 @@ describe('createGitLabCommit', () => { execute_filemode: false, }, ], - undefined, ); expect(ctx.output).toHaveBeenCalledWith( 'commitHash', @@ -147,7 +151,6 @@ describe('createGitLabCommit', () => { execute_filemode: false, }, ], - undefined, ); expect(ctx.output).toHaveBeenCalledWith( 'commitHash', @@ -185,7 +188,6 @@ describe('createGitLabCommit', () => { execute_filemode: false, }, ], - undefined, ); expect(ctx.output).toHaveBeenCalledWith( 'commitHash', @@ -223,7 +225,6 @@ describe('createGitLabCommit', () => { execute_filemode: false, }, ], - undefined, ); expect(ctx.output).toHaveBeenCalledWith( 'commitHash', @@ -267,7 +268,6 @@ describe('createGitLabCommit', () => { execute_filemode: false, }, ], - undefined, ); expect(ctx.output).toHaveBeenCalledWith( 'commitHash', @@ -310,7 +310,6 @@ describe('createGitLabCommit', () => { execute_filemode: false, }, ], - undefined, ); expect(ctx.output).toHaveBeenCalledWith( 'commitHash', @@ -375,7 +374,6 @@ describe('createGitLabCommit', () => { execute_filemode: false, }, ], - undefined, ); expect(ctx.output).toHaveBeenCalledWith( 'commitHash', @@ -454,4 +452,95 @@ describe('createGitLabCommit', () => { ); }); }); + + describe('allowEmpty parameter', () => { + it('passes allowEmpty: true to Commits.create when specified', async () => { + const input = { + repoUrl: 'gitlab.com?repo=repo&owner=owner', + commitMessage: 'Empty commit', + branchName: 'some-branch', + allowEmpty: true, + }; + mockDir.setContent({ + [workspacePath]: {}, + }); + + const ctx = createMockActionContext({ input, workspacePath }); + await instance.handler(ctx); + + expect(mockGitlabClient.Commits.create).toHaveBeenCalledWith( + 'owner/repo', + 'some-branch', + 'Empty commit', + [], + { allowEmpty: true }, + ); + }); + + it('does not pass 5th argument when allowEmpty is not specified', async () => { + const input = { + repoUrl: 'gitlab.com?repo=repo&owner=owner', + commitMessage: 'Normal commit', + branchName: 'some-branch', + }; + mockDir.setContent({ + [workspacePath]: { + 'foo.txt': 'content', + }, + }); + + const ctx = createMockActionContext({ input, workspacePath }); + await instance.handler(ctx); + + expect(mockGitlabClient.Commits.create).toHaveBeenCalledWith( + 'owner/repo', + 'some-branch', + 'Normal commit', + [ + { + action: 'create', + filePath: 'foo.txt', + content: 'Y29udGVudA==', + encoding: 'base64', + execute_filemode: false, + }, + ], + ); + // Verify only 4 arguments were passed (no 5th) + expect(mockGitlabClient.Commits.create.mock.calls[0]).toHaveLength(4); + }); + + it('passes allowEmpty: false to Commits.create when explicitly set', async () => { + const input = { + repoUrl: 'gitlab.com?repo=repo&owner=owner', + commitMessage: 'Commit with files', + branchName: 'some-branch', + allowEmpty: false, + }; + mockDir.setContent({ + [workspacePath]: { + 'foo.txt': 'content', + }, + }); + + const ctx = createMockActionContext({ input, workspacePath }); + await instance.handler(ctx); + + expect(mockGitlabClient.Commits.create).toHaveBeenCalledWith( + 'owner/repo', + 'some-branch', + 'Commit with files', + [ + { + action: 'create', + filePath: 'foo.txt', + content: 'Y29udGVudA==', + encoding: 'base64', + execute_filemode: false, + }, + ], + { allowEmpty: false }, + ); + }); + }); });