working test for githubPullRequest

Signed-off-by: Tavi Nolan <Tavi.Nolan@fmr.com>
This commit is contained in:
Tavi Nolan
2024-04-04 13:49:49 +01:00
parent dae724d913
commit f0ae762081
2 changed files with 22 additions and 13 deletions
@@ -14,20 +14,21 @@
* limitations under the License.
*/
import { createRootLogger } from '@backstage/backend-common';
import { ConfigReader } from '@backstage/config';
import {
GithubCredentialsProvider,
ScmIntegrations,
} from '@backstage/integration';
import {
ActionContext,
TemplateAction,
} from '@backstage/plugin-scaffolder-node';
import fs from 'fs-extra';
import { createPublishGithubPullRequestAction } from './githubPullRequest';
import { createMockDirectory } from '@backstage/backend-test-utils';
import {
GithubCredentialsProvider,
ScmIntegrations,
} from '@backstage/integration';
import { ConfigReader } from '@backstage/config';
import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils';
import { createMockDirectory } from '@backstage/backend-test-utils';
import { createPublishGithubPullRequestAction } from './githubPullRequest';
import { createRootLogger } from '@backstage/backend-common';
import fs from 'fs-extra';
// Make sure root logger is initialized ahead of FS mock
createRootLogger();
@@ -227,6 +228,18 @@ describe('createPublishGithubPullRequestAction', () => {
);
expect(ctx.output).toHaveBeenCalledWith('pullRequestNumber', 123);
});
it('handles dry run correctly', async () => {
ctx.isDryRun = true;
await instance.handler(ctx);
expect(ctx.output).toHaveBeenCalledWith('targetBranchName', 'new-app');
expect(ctx.output).toHaveBeenCalledWith(
'remoteUrl',
'github.com?owner=myorg&repo=myrepo',
);
expect(ctx.output).toHaveBeenCalledWith('pullRequestNumber', 43);
});
});
describe('with sourcePath', () => {
@@ -324,10 +324,6 @@ export const createPublishGithubPullRequestAction = (
if (ctx.isDryRun) {
ctx.logger.info(
`Dry run arguments: ${{
repoUrl,
branchName,
title,
description,
...ctx.input,
}}`,
);