test(plugins/scaffolder-backend-module-github): adding missing author data priority test

Signed-off-by: Matheus Castiglioni <mahenrique94@users.noreply.github.com>
This commit is contained in:
Matheus Castiglioni
2024-05-05 22:39:44 -03:00
parent b000ee6fa2
commit e5486988c0
@@ -689,7 +689,7 @@ describe('createPublishGithubPullRequestAction', () => {
ctx = createMockActionContext({ input, workspacePath });
});
it('creates a pull request with author name', async () => {
it('creates a pull request', async () => {
await instance.handler(ctx);
expect(fakeClient.createPullRequest).toHaveBeenCalledWith({
@@ -738,7 +738,7 @@ describe('createPublishGithubPullRequestAction', () => {
ctx = createMockActionContext({ input, workspacePath });
});
it('creates a pull request with author name', async () => {
it('creates a pull request', async () => {
await instance.handler(ctx);
expect(fakeClient.createPullRequest).toHaveBeenCalledWith({
@@ -787,7 +787,7 @@ describe('createPublishGithubPullRequestAction', () => {
ctx = createMockActionContext({ input, workspacePath });
});
it('creates a pull request with author name', async () => {
it('creates a pull request', async () => {
await instance.handler(ctx);
expect(fakeClient.createPullRequest).toHaveBeenCalledWith({
@@ -835,7 +835,7 @@ describe('createPublishGithubPullRequestAction', () => {
ctx = createMockActionContext({ input, workspacePath });
});
it('creates a pull request with author name', async () => {
it('creates a pull request with default config attributes', async () => {
config = new ConfigReader({
scaffolder: {
defaultAuthor: {
@@ -884,4 +884,75 @@ describe('createPublishGithubPullRequestAction', () => {
});
});
});
describe('with author attributes and config file', () => {
let input: GithubPullRequestActionInput;
let ctx: ActionContext<GithubPullRequestActionInput>;
beforeEach(() => {
input = {
repoUrl: 'github.com?owner=myorg&repo=myrepo',
title: 'Create my new app',
branchName: 'new-app',
description: 'This PR is really good',
gitAuthorEmail: 'foo@bar.example',
gitAuthorName: 'Foo Bar',
};
mockDir.setContent({
[workspacePath]: { 'file.txt': 'Hello there!' },
});
ctx = createMockActionContext({ input, workspacePath });
});
it('creates a pull request with using author name and email from input', async () => {
config = new ConfigReader({
scaffolder: {
defaultAuthor: {
name: 'Config',
email: 'config@file.example',
},
},
});
const clientFactory = jest.fn(async () => fakeClient as any);
const githubCredentialsProvider: GithubCredentialsProvider = {
getCredentials: jest.fn(),
};
const instanceWithConfig = createPublishGithubPullRequestAction({
integrations,
githubCredentialsProvider,
clientFactory,
config,
});
await instanceWithConfig.handler(ctx);
expect(fakeClient.createPullRequest).toHaveBeenCalledWith({
owner: 'myorg',
repo: 'myrepo',
title: 'Create my new app',
head: 'new-app',
body: 'This PR is really good',
changes: [
{
commit: 'Create my new app',
files: {
'file.txt': {
content: Buffer.from('Hello there!').toString('base64'),
encoding: 'base64',
mode: '100644',
},
},
author: {
email: 'foo@bar.example',
name: 'Foo Bar',
},
},
],
});
});
});
});