Skip to content

Commit

Permalink
Merge pull request #38934 from software-mansion-labs/ts-migration/res…
Browse files Browse the repository at this point in the history
…tore-32051-23055-tests
  • Loading branch information
francoisl authored Mar 27, 2024
2 parents 4001bf3 + bf03125 commit 685d4f9
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 100 deletions.
2 changes: 1 addition & 1 deletion workflow_tests/assertions/createNewVersionAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ function assertCreateNewVersionJobExecuted(workflowResult: Step[], semverLevel =
});
}

export {assertValidateActorJobExecuted, assertCreateNewVersionJobExecuted};
export default {assertValidateActorJobExecuted, assertCreateNewVersionJobExecuted};
2 changes: 1 addition & 1 deletion workflow_tests/assertions/deployAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@ function assertDeployProductionJobExecuted(workflowResult: Step[], didExecute =
});
}

export {assertDeployStagingJobExecuted, assertDeployProductionJobExecuted};
export default {assertDeployStagingJobExecuted, assertDeployProductionJobExecuted};
2 changes: 1 addition & 1 deletion workflow_tests/assertions/deployBlockerAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ function assertDeployBlockerJobExecuted(workflowResult: Step[], didExecute = tru
});
}

export {assertUpdateChecklistJobExecuted, assertDeployBlockerJobExecuted};
export default {assertUpdateChecklistJobExecuted, assertDeployBlockerJobExecuted};
2 changes: 1 addition & 1 deletion workflow_tests/assertions/finishReleaseCycleAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,4 @@ function assertUpdateStagingJobExecuted(workflowResult: Step[], didExecute = tru
});
}

export {assertValidateJobExecuted, assertUpdateProductionJobExecuted, assertCreateNewPatchVersionJobExecuted, assertUpdateStagingJobExecuted};
export default {assertValidateJobExecuted, assertUpdateProductionJobExecuted, assertCreateNewPatchVersionJobExecuted, assertUpdateStagingJobExecuted};
3 changes: 1 addition & 2 deletions workflow_tests/assertions/lintAssertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@ function assertLintJobExecuted(workflowResult: Step[], didExecute = true) {
});
}

// eslint-disable-next-line import/prefer-default-export
export {assertLintJobExecuted};
export default {assertLintJobExecuted};
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/createNewVersionAssertions');
const mocks = require('./mocks/createNewVersionMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/createNewVersionAssertions';
import mocks from './mocks/createNewVersionMocks';
import ExtendedAct from './utils/ExtendedAct';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000); // 90 sec
let mockGithub;
let mockGithub: MockGithub;

const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -16,15 +17,15 @@ const FILES_TO_COPY_INTO_TEST_REPO = [
];

describe('test workflow createNewVersion', () => {
beforeAll(async () => {
beforeAll(() => {
// 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
utils.removeMockRepoDir();
});

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testCreateNewVersionWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('test workflow createNewVersion', () => {
describe('actor is admin', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS;
it('executes full workflow', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand All @@ -79,7 +80,7 @@ describe('test workflow createNewVersion', () => {
describe('actor is writer', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__WRITER__STEP_MOCKS;
it('executes full workflow', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand All @@ -102,7 +103,7 @@ describe('test workflow createNewVersion', () => {
describe('actor is reader', () => {
const validateActorMockSteps = mocks.CREATENEWVERSION__VALIDATEACTOR__NO_PERMISSION__STEP_MOCKS;
it('stops after validation', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand All @@ -124,7 +125,7 @@ describe('test workflow createNewVersion', () => {

describe('one step fails', () => {
it('announces failure on Slack', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, inputs);
Expand All @@ -133,7 +134,7 @@ describe('test workflow createNewVersion', () => {
validateActor: mocks.CREATENEWVERSION__VALIDATEACTOR__ADMIN__STEP_MOCKS,
createNewVersion: utils.deepCopy(mocks.CREATENEWVERSION__CREATENEWVERSION__STEP_MOCKS),
};
testMockSteps.createNewVersion[5] = utils.createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], [], [], [], false);
testMockSteps.createNewVersion[5] = utils.createMockStep('Commit new version', 'Commit new version', 'CREATENEWVERSION', [], [], {}, {}, false);
const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml'),
mockSteps: testMockSteps,
Expand All @@ -146,7 +147,7 @@ describe('test workflow createNewVersion', () => {
});

it('chooses source branch depending on the SEMVER_LEVEL', async () => {
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testCreateNewVersionWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'createNewVersion.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, {}, secrets, githubToken, {}, {SEMVER_LEVEL: 'MAJOR'});
Expand Down
27 changes: 14 additions & 13 deletions workflow_tests/deploy.test.js → workflow_tests/deploy.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/deployAssertions');
const mocks = require('./mocks/deployMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/deployAssertions';
import mocks from './mocks/deployMocks';
import ExtendedAct from './utils/ExtendedAct';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000);
let mockGithub;
let mockGithub: MockGithub;

const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -16,15 +17,15 @@ const FILES_TO_COPY_INTO_TEST_REPO = [
];

describe('test workflow deploy', () => {
beforeAll(async () => {
beforeAll(() => {
// 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
utils.removeMockRepoDir();
});

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testDeployWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -48,7 +49,7 @@ describe('test workflow deploy', () => {
};
describe('push', () => {
it('to main - nothing triggered', async () => {
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand All @@ -75,7 +76,7 @@ describe('test workflow deploy', () => {
});

it('to staging - deployStaging triggered', async () => {
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand All @@ -102,7 +103,7 @@ describe('test workflow deploy', () => {
});

it('to production - deployProduction triggered', async () => {
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand Down Expand Up @@ -130,7 +131,7 @@ describe('test workflow deploy', () => {
});

it('different event than push - workflow does not execute', async () => {
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deploy.yml');
let act = new ExtendedAct(repoPath, workflowPath);
const testMockSteps = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/deployBlockerAssertions');
const mocks = require('./mocks/deployBlockerMocks');
const ExtendedAct = require('./utils/ExtendedAct').default;
/* eslint-disable @typescript-eslint/naming-convention */
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/deployBlockerAssertions';
import mocks from './mocks/deployBlockerMocks';
import ExtendedAct from './utils/ExtendedAct';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000);
let mockGithub;
let mockGithub: MockGithub;

const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -23,15 +25,15 @@ describe('test workflow deployBlocker', () => {
SLACK_WEBHOOK: 'dummy_slack_webhook',
};

beforeAll(async () => {
beforeAll(() => {
// 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
utils.removeMockRepoDir();
});

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testDeployBlockerWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand Down Expand Up @@ -64,7 +66,7 @@ describe('test workflow deployBlocker', () => {
const testEventOptions = utils.deepCopy(eventOptions);
testEventOptions.label = {name: 'DeployBlockerCash'};
it('runs the workflow and announces success on Slack', async () => {
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {});
Expand All @@ -90,7 +92,7 @@ describe('test workflow deployBlocker', () => {
});
describe('one step fails', () => {
it('announces failure on Slack', async () => {
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {});
Expand Down Expand Up @@ -130,7 +132,7 @@ describe('test workflow deployBlocker', () => {
const testEventOptions = utils.deepCopy(eventOptions);
testEventOptions.label = {name: 'Different Label'};
it('does not run workflow', async () => {
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testDeployBlockerWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'deployBlocker.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(act, event, testEventOptions, secrets, githubToken, {}, {});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
const path = require('path');
const kieMockGithub = require('@kie/mock-github');
const utils = require('./utils/utils');
const assertions = require('./assertions/finishReleaseCycleAssertions');
const mocks = require('./mocks/finishReleaseCycleMocks').default;
const ExtendedAct = require('./utils/ExtendedAct').default;
import {MockGithub} from '@kie/mock-github';
import path from 'path';
import assertions from './assertions/finishReleaseCycleAssertions';
import mocks from './mocks/finishReleaseCycleMocks';
import ExtendedAct from './utils/ExtendedAct';
import type {MockJobs} from './utils/JobMocker';
import * as utils from './utils/utils';

jest.setTimeout(90 * 1000);
let mockGithub;
let mockGithub: MockGithub;

const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -16,15 +18,15 @@ const FILES_TO_COPY_INTO_TEST_REPO = [
];

describe('test workflow finishReleaseCycle', () => {
beforeAll(async () => {
beforeAll(() => {
// 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
utils.removeMockRepoDir();
});

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testFinishReleaseCycleWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -50,7 +52,7 @@ describe('test workflow finishReleaseCycle', () => {
describe('actor is a team member', () => {
describe('no deploy blockers', () => {
it('production updated, new version created', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand All @@ -71,7 +73,7 @@ describe('test workflow finishReleaseCycle', () => {
updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS,
updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS,
};
const testMockJobs = {
const testMockJobs: MockJobs = {
createNewPatchVersion: {
steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS,
outputs: {
Expand All @@ -96,7 +98,7 @@ describe('test workflow finishReleaseCycle', () => {
});
describe('deploy blockers', () => {
it('production not updated, new version not created, issue reopened', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand Down Expand Up @@ -143,7 +145,7 @@ describe('test workflow finishReleaseCycle', () => {
});
describe('actor is not a team member', () => {
it('production not updated, new version not created, issue reopened', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand Down Expand Up @@ -190,7 +192,7 @@ describe('test workflow finishReleaseCycle', () => {
});
describe('issue does not have StagingDeployCash', () => {
it('validate job not run', async () => {
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') || '';
const repoPath = mockGithub.repo.getPath('testFinishReleaseCycleWorkflowRepo') ?? '';
const workflowPath = path.join(repoPath, '.github', 'workflows', 'finishReleaseCycle.yml');
let act = new ExtendedAct(repoPath, workflowPath);
act = utils.setUpActParams(
Expand Down
Loading

0 comments on commit 685d4f9

Please sign in to comment.