testing for githubWebhook.test.ts
Signed-off-by: Tavi Nolan <Tavi.Nolan@fmr.com>
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user