Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TS migration] Migrate cla.test to typescript #38393

Merged
merged 7 commits into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 43 additions & 26 deletions workflow_tests/cla.test.js → workflow_tests/cla.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/claAssertions');
const mocks = require('./mocks/claMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
/* eslint-disable @typescript-eslint/naming-convention */
import type {Step} from '@kie/act-js';
import type {CreateRepositoryFile, MockGithub} from '@kie/mock-github';
import kieMockGithub from '@kie/mock-github';
import path from 'path';
import {assertCLAJobExecuted} from './assertions/claAssertions';
import {CLA__CLA__CHECK_MATCH__STEP_MOCKS, CLA__CLA__NO_MATCHES__STEP_MOCKS, CLA__CLA__RECHECK_MATCH__STEP_MOCKS} from './mocks/claMocks';
import ExtendedAct from './utils/ExtendedAct';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000);
let mockGithub;
const FILES_TO_COPY_INTO_TEST_REPO = [

let mockGithub: MockGithub | undefined;

const FILES_TO_COPY_INTO_TEST_REPO: CreateRepositoryFile[] = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
src: path.resolve(__dirname, '..', '.github', 'workflows', 'cla.yml'),
Expand All @@ -16,12 +21,13 @@ const FILES_TO_COPY_INTO_TEST_REPO = [
];

describe('test workflow cla', () => {
const secrets = {
const secrets: Record<string, string> = {
CLA_BOTIFY_TOKEN: 'dummy_cla_botify_token',
};
const githubToken = 'dummy_github_token';
const actor = 'Dummy Author';

// eslint-disable-next-line @typescript-eslint/require-await
beforeAll(async () => {
// in case of the tests being interrupted without cleanup the mock repo directory may be left behind
// which breaks the next test run, this removes any possible leftovers
Expand All @@ -42,7 +48,7 @@ describe('test workflow cla', () => {
});

afterEach(async () => {
await mockGithub.teardown();
await mockGithub?.teardown();
});
describe('event is issue_comment', () => {
const event = 'issue_comment';
Expand All @@ -60,21 +66,23 @@ describe('test workflow cla', () => {
},
};
it('workflow executes, CLA assistant step not run', async () => {
const repoPath = mockGithub.repo.getPath('testClaWorkflowRepo') || '';
const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventData, secrets, githubToken);

const testMockSteps = {
CLA: mocks.CLA__CLA__NO_MATCHES__STEP_MOCKS,
CLA: CLA__CLA__NO_MATCHES__STEP_MOCKS,
};

const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'),
mockSteps: testMockSteps,
actor,
logFile: utils.getLogFilePath('cla', expect.getState().currentTestName),
});

assertions.assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, false);
assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, false);
});
});
describe('check regex matches', () => {
Expand All @@ -91,21 +99,23 @@ describe('test workflow cla', () => {
},
};
it('workflow executes, CLA assistant step run', async () => {
const repoPath = mockGithub.repo.getPath('testClaWorkflowRepo') || '';
const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventData, secrets, githubToken);

const testMockSteps = {
CLA: mocks.CLA__CLA__CHECK_MATCH__STEP_MOCKS,
CLA: CLA__CLA__CHECK_MATCH__STEP_MOCKS,
};

const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'),
mockSteps: testMockSteps,
actor,
logFile: utils.getLogFilePath('cla', expect.getState().currentTestName),
});

assertions.assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, true);
assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, true);
});
});
describe('re-check regex matches', () => {
Expand All @@ -122,21 +132,23 @@ describe('test workflow cla', () => {
},
};
it('workflow executes, CLA assistant step run', async () => {
const repoPath = mockGithub.repo.getPath('testClaWorkflowRepo') || '';
const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventData, secrets, githubToken);

const testMockSteps = {
CLA: mocks.CLA__CLA__RECHECK_MATCH__STEP_MOCKS,
CLA: CLA__CLA__RECHECK_MATCH__STEP_MOCKS,
};

const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'),
mockSteps: testMockSteps,
actor,
logFile: utils.getLogFilePath('cla', expect.getState().currentTestName),
});

assertions.assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, true);
assertCLAJobExecuted(result, commentBody, `${repoPath}/remote/origin`, true, true);
});
});
});
Expand All @@ -152,21 +164,23 @@ describe('test workflow cla', () => {
},
};
it('workflow executes, CLA assistant step still run', async () => {
const repoPath = mockGithub.repo.getPath('testClaWorkflowRepo') || '';
const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventData, secrets, githubToken);

const testMockSteps = {
CLA: mocks.CLA__CLA__NO_MATCHES__STEP_MOCKS,
CLA: CLA__CLA__NO_MATCHES__STEP_MOCKS,
};

const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'),
mockSteps: testMockSteps,
actor,
logFile: utils.getLogFilePath('cla', expect.getState().currentTestName),
});

assertions.assertCLAJobExecuted(result, '', `${repoPath}/remote/origin`, true, true);
assertCLAJobExecuted(result, '', `${repoPath}/remote/origin`, true, true);
});
});
});
Expand All @@ -176,21 +190,24 @@ describe('test workflow cla', () => {
const eventData = {
ref: 'main',
};
const repoPath = mockGithub.repo.getPath('testClaWorkflowRepo') || '';

const repoPath = mockGithub?.repo.getPath('testClaWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'cla.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, eventData, secrets, githubToken);

const testMockSteps = {
CLA: mocks.CLA__CLA__NO_MATCHES__STEP_MOCKS,
CLA: CLA__CLA__NO_MATCHES__STEP_MOCKS,
};
const result = await act.runEvent(event, {

const result: Step[] = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'cla.yml'),
mockSteps: testMockSteps,
actor,
logFile: utils.getLogFilePath('cla', expect.getState().currentTestName),
});

assertions.assertCLAJobExecuted(result, '', `${repoPath}/remote/origin`, false);
assertCLAJobExecuted(result, '', `${repoPath}/remote/origin`, false);
});
});
});
Loading