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

Revert "[No QA][TS migration] Migrate workflow_tests, adjust utils migration" #38857

Merged
merged 1 commit into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
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
14 changes: 0 additions & 14 deletions src/types/modules/act.d.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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';
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;

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

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

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

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new MockGithub({
mockGithub = new kieMockGithub.MockGithub({
repo: {
testCreateNewVersionWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand Down Expand Up @@ -57,7 +56,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 @@ -80,7 +79,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 @@ -103,7 +102,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 @@ -125,7 +124,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 @@ -134,7 +133,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 @@ -147,7 +146,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: 13 additions & 14 deletions workflow_tests/deploy.test.ts → workflow_tests/deploy.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
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';
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;

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

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

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

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new MockGithub({
mockGithub = new kieMockGithub.MockGithub({
repo: {
testDeployWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -49,7 +48,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 @@ -76,7 +75,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 @@ -103,7 +102,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 @@ -131,7 +130,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,13 +1,12 @@
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';
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;

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

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

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

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new MockGithub({
mockGithub = new kieMockGithub.MockGithub({
repo: {
testDeployBlockerWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -58,15 +57,14 @@ describe('test workflow deployBlocker', () => {
issue: {
title: 'Labeled issue title',
number: '1234',
// eslint-disable-next-line @typescript-eslint/naming-convention
html_url: 'http://issue.html.url',
},
};
describe('label is DeployBlockerCash', () => {
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 @@ -92,7 +90,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 @@ -132,7 +130,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,13 +1,12 @@
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';
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');
const ExtendedAct = require('./utils/ExtendedAct').default;

jest.setTimeout(90 * 1000);
let mockGithub: MockGithub;
let mockGithub;
const FILES_TO_COPY_INTO_TEST_REPO = [
...utils.deepCopy(utils.FILES_TO_COPY_INTO_TEST_REPO),
{
Expand All @@ -17,15 +16,15 @@ const FILES_TO_COPY_INTO_TEST_REPO = [
];

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

beforeEach(async () => {
// create a local repository and copy required files
mockGithub = new MockGithub({
mockGithub = new kieMockGithub.MockGithub({
repo: {
testFinishReleaseCycleWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,
Expand All @@ -51,7 +50,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 @@ -72,7 +71,7 @@ describe('test workflow finishReleaseCycle', () => {
updateProduction: mocks.FINISHRELEASECYCLE__UPDATEPRODUCTION__STEP_MOCKS,
updateStaging: mocks.FINISHRELEASECYCLE__UPDATESTAGING__STEP_MOCKS,
};
const testMockJobs: MockJobs = {
const testMockJobs = {
createNewPatchVersion: {
steps: mocks.FINISHRELEASECYCLE__CREATENEWPATCHVERSION__STEP_MOCKS,
outputs: {
Expand All @@ -97,7 +96,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 @@ -144,7 +143,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 @@ -191,7 +190,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
Loading