testing for githubWebhook.test.ts

Signed-off-by: Tavi Nolan <Tavi.Nolan@fmr.com>
This commit is contained in:
Tavi Nolan
2024-04-04 14:14:55 +01:00
parent f0ae762081
commit 8de90c8358
2 changed files with 37 additions and 5 deletions
@@ -14,15 +14,16 @@
* limitations under the License.
*/
import { createGithubWebhookAction } from './githubWebhook';
import {
ScmIntegrations,
DefaultGithubCredentialsProvider,
GithubCredentialsProvider,
ScmIntegrations,
} from '@backstage/integration';
import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils';
import { ConfigReader } from '@backstage/config';
import { TemplateAction } from '@backstage/plugin-scaffolder-node';
import { createGithubWebhookAction } from './githubWebhook';
import { createMockActionContext } from '@backstage/plugin-scaffolder-node-test-utils';
const mockOctokit = {
rest: {
@@ -221,6 +222,39 @@ describe('github:repository:webhook:create', () => {
});
});
it('should call the githubApi for creating repository Webhook with dry run', async () => {
const repoUrl = 'github.com?repo=repo&owner=owner';
const webhookUrl = 'https://example.com/payload';
const ctx = Object.assign({}, mockContext, {
input: { repoUrl, webhookUrl },
});
ctx.isDryRun = true;
await action.handler(ctx);
const webhookSecret = 'yet_another_secret';
await action.handler({
...mockContext,
input: {
...mockContext.input,
webhookSecret,
events: ['push', 'pull_request'],
},
});
expect(mockOctokit.rest.repos.createWebhook).toHaveBeenCalledWith({
owner: 'owner',
repo: 'repo',
events: ['push', 'pull_request'],
active: true,
config: {
url: webhookUrl,
content_type: 'form',
secret: webhookSecret,
insecure_ssl: '0',
},
});
});
it('should validate input', async () => {
const Validator = require('jsonschema').Validator;
const v = new Validator();
@@ -152,8 +152,6 @@ export function createGithubWebhookAction(options: {
if (ctx.isDryRun) {
ctx.logger.info(
`Dry run arguments: ${{
repoUrl,
webhookUrl,
webhookSecret,
events,
...ctx.input,