Update tests
Signed-off-by: Aisha Saini <asaini1@jaguarlandrover.com> Signed-off-by: asaini1 <asaini1@jaguarlandrover.com>
This commit is contained in:
+6
-178
@@ -79,20 +79,6 @@ jest.mock('@gitbeaker/node', () => ({
|
||||
},
|
||||
}));
|
||||
|
||||
jest.mock('globby', () =>
|
||||
jest.fn(async (_: any) => {
|
||||
return ['foo/bar5'];
|
||||
}),
|
||||
);
|
||||
|
||||
jest.mock('fs-extra', () => {
|
||||
return {
|
||||
readFile: jest.fn(async (_: any) => {
|
||||
return Buffer.from('some content');
|
||||
}),
|
||||
};
|
||||
});
|
||||
|
||||
describe('createGitLabMergeRequest', () => {
|
||||
let instance: TemplateAction<any>;
|
||||
|
||||
@@ -129,6 +115,7 @@ describe('createGitLabMergeRequest', () => {
|
||||
branchName: 'new-mr',
|
||||
description: 'This MR is really good',
|
||||
draft: true,
|
||||
targetPath: 'Subdirectory',
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
@@ -147,7 +134,7 @@ describe('createGitLabMergeRequest', () => {
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.MergeRequests.create).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
'owner/repo',
|
||||
'new-mr',
|
||||
'main',
|
||||
'Create my new MR',
|
||||
@@ -165,6 +152,7 @@ describe('createGitLabMergeRequest', () => {
|
||||
description: 'MR description',
|
||||
removeSourceBranch: true,
|
||||
draft: true,
|
||||
targetPath: 'Subdirectory',
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
@@ -184,7 +172,7 @@ describe('createGitLabMergeRequest', () => {
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.MergeRequests.create).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
'owner/repo',
|
||||
'new-mr',
|
||||
'main',
|
||||
'Create my new MR',
|
||||
@@ -200,6 +188,7 @@ describe('createGitLabMergeRequest', () => {
|
||||
description: 'other MR description',
|
||||
removeSourceBranch: false,
|
||||
draft: true,
|
||||
targetPath: 'Subdirectory',
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
@@ -219,7 +208,7 @@ describe('createGitLabMergeRequest', () => {
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.MergeRequests.create).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
'owner/repo',
|
||||
'new-mr',
|
||||
'main',
|
||||
'Create my new MR',
|
||||
@@ -230,165 +219,4 @@ describe('createGitLabMergeRequest', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createGitLabMergeRequestWithoutGitlabAction', () => {
|
||||
it('gitlabAction is create by default when not passed in options', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
title: 'Create my new MR',
|
||||
branchName: 'new-mr',
|
||||
description: 'This MR is really good',
|
||||
draft: true,
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
source: { 'foo.txt': 'Hello there!' },
|
||||
irrelevant: { 'bar.txt': 'Nothing to see here' },
|
||||
},
|
||||
});
|
||||
const ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.Commits.create).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
'new-mr',
|
||||
'Create my new MR',
|
||||
[
|
||||
{
|
||||
action: 'create',
|
||||
filePath: 'foo/bar5',
|
||||
content: 'some content',
|
||||
},
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('createGitLabMergeRequestWithGitlabAction', () => {
|
||||
it('gitlabAction is create when create is passed in options', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
title: 'Create my new MR',
|
||||
branchName: 'new-mr',
|
||||
description: 'MR description',
|
||||
gitlabAction: 'create',
|
||||
draft: true,
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
source: { 'foo.txt': 'Hello there!' },
|
||||
irrelevant: { 'bar.txt': 'Nothing to see here' },
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.Commits.create).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
'new-mr',
|
||||
'Create my new MR',
|
||||
[
|
||||
{
|
||||
action: 'create',
|
||||
filePath: 'foo/bar5',
|
||||
content: 'some content',
|
||||
},
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
it('gitlabAction is update when update is passed in options', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
title: 'Create my new MR',
|
||||
branchName: 'new-mr',
|
||||
description: 'MR description',
|
||||
gitlabAction: 'update',
|
||||
draft: true,
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
source: { 'foo.txt': 'Hello there!' },
|
||||
irrelevant: { 'bar.txt': 'Nothing to see here' },
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.Commits.create).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
'new-mr',
|
||||
'Create my new MR',
|
||||
[
|
||||
{
|
||||
action: 'update',
|
||||
filePath: 'foo/bar5',
|
||||
content: 'some content',
|
||||
},
|
||||
],
|
||||
);
|
||||
});
|
||||
|
||||
it('gitlabAction is delete when delete is passed in options', async () => {
|
||||
const input = {
|
||||
repoUrl: 'gitlab.com?repo=repo&owner=owner',
|
||||
title: 'Create my new MR',
|
||||
branchName: 'new-mr',
|
||||
description: 'other MR description',
|
||||
gitlabAction: 'delete',
|
||||
draft: true,
|
||||
};
|
||||
mockFs({
|
||||
[workspacePath]: {
|
||||
source: { 'foo.txt': 'Hello there!' },
|
||||
irrelevant: { 'bar.txt': 'Nothing to see here' },
|
||||
},
|
||||
});
|
||||
|
||||
const ctx = {
|
||||
createTemporaryDirectory: jest.fn(),
|
||||
output: jest.fn(),
|
||||
logger: getRootLogger(),
|
||||
logStream: new Writable(),
|
||||
input,
|
||||
workspacePath,
|
||||
};
|
||||
await instance.handler(ctx);
|
||||
|
||||
expect(mockGitlabClient.Commits.create).toHaveBeenCalledWith(
|
||||
undefined,
|
||||
'new-mr',
|
||||
'Create my new MR',
|
||||
[
|
||||
{
|
||||
action: 'delete',
|
||||
filePath: 'foo/bar5',
|
||||
},
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user