From bc7387e0c1bc1cd8cd3e7132cdbb80e0372687d1 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Wed, 20 Mar 2024 15:26:36 +0100 Subject: [PATCH 1/2] migrate failure notifier --- workflow_tests/failureNotifier.test.ts | 64 ++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 workflow_tests/failureNotifier.test.ts diff --git a/workflow_tests/failureNotifier.test.ts b/workflow_tests/failureNotifier.test.ts new file mode 100644 index 000000000000..8dfc092c7e61 --- /dev/null +++ b/workflow_tests/failureNotifier.test.ts @@ -0,0 +1,64 @@ +import type {MockStep} from '@kie/act-js/build/src/step-mocker/step-mocker.types'; +import type {CreateRepositoryFile} from '@kie/mock-github'; +import {MockGithub} from '@kie/mock-github'; +import path from 'path'; +import assertions from './assertions/failureNotifierAssertions'; +import mocks from './mocks/failureNotifierMocks'; +import ExtendedAct from './utils/ExtendedAct'; + +jest.setTimeout(90 * 1000); +let mockGithub: MockGithub; + +const FILES_TO_COPY_INTO_TEST_REPO = [ + { + src: path.resolve(__dirname, '..', '.github', 'workflows', 'failureNotifier.yml'), + dest: '.github/workflows/failureNotifier.yml', + }, +] as const satisfies CreateRepositoryFile[]; + +describe('test workflow failureNotifier', () => { + const actor = 'Dummy Actor'; + beforeEach(async () => { + // create a local repository and copy required files + mockGithub = new MockGithub({ + repo: { + testFailureNotifierWorkflowRepo: { + files: FILES_TO_COPY_INTO_TEST_REPO, + + // if any branches besides main are needed add: pushedBranches: ['staging', 'production'], + }, + }, + }); + + await mockGithub.setup(); + }); + + afterEach(async () => { + await mockGithub.teardown(); + }); + it('runs the notify failure when main fails', async () => { + const repoPath = mockGithub.repo.getPath('testFailureNotifierWorkflowRepo') ?? ''; + const workflowPath = path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml'); + let act = new ExtendedAct(repoPath, workflowPath); + const event = 'workflow_run'; + act = act.setEvent({ + // eslint-disable-next-line @typescript-eslint/naming-convention + workflow_run: { + name: 'Process new code merged to main', + conclusion: 'failure', + }, + }); + const testMockSteps = { + notifyFailure: mocks.FAILURENOTIFIER__NOTIFYFAILURE__STEP_MOCKS, + } as const satisfies MockStep; + + const result = await act.runEvent(event, { + workflowFile: path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml'), + mockSteps: testMockSteps, + actor, + }); + + // assert execution with imported assertions + assertions.assertNotifyFailureJobExecuted(result); + }); +}); From 81ee7cef3e8eb5576823375155f690f542b852b7 Mon Sep 17 00:00:00 2001 From: BrtqKr Date: Wed, 20 Mar 2024 15:29:25 +0100 Subject: [PATCH 2/2] cleanup --- workflow_tests/failureNotifier.test.js | 59 -------------------------- 1 file changed, 59 deletions(-) delete mode 100644 workflow_tests/failureNotifier.test.js diff --git a/workflow_tests/failureNotifier.test.js b/workflow_tests/failureNotifier.test.js deleted file mode 100644 index d521c6cde00e..000000000000 --- a/workflow_tests/failureNotifier.test.js +++ /dev/null @@ -1,59 +0,0 @@ -const path = require('path'); -const kieMockGithub = require('@kie/mock-github'); -const assertions = require('./assertions/failureNotifierAssertions'); -const mocks = require('./mocks/failureNotifierMocks'); -const ExtendedAct = require('./utils/ExtendedAct').default; - -jest.setTimeout(90 * 1000); -let mockGithub; -const FILES_TO_COPY_INTO_TEST_REPO = [ - { - src: path.resolve(__dirname, '..', '.github', 'workflows', 'failureNotifier.yml'), - dest: '.github/workflows/failureNotifier.yml', - }, -]; - -describe('test workflow failureNotifier', () => { - const actor = 'Dummy Actor'; - beforeEach(async () => { - // create a local repository and copy required files - mockGithub = new kieMockGithub.MockGithub({ - repo: { - testFailureNotifierWorkflowRepo: { - files: FILES_TO_COPY_INTO_TEST_REPO, - - // if any branches besides main are need add: pushedBranches: ['staging', 'production'], - }, - }, - }); - - await mockGithub.setup(); - }); - - afterEach(async () => { - await mockGithub.teardown(); - }); - it('runs the notify failure when main fails', async () => { - const repoPath = mockGithub.repo.getPath('testFailureNotifierWorkflowRepo') || ''; - const workflowPath = path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml'); - let act = new ExtendedAct(repoPath, workflowPath); - const event = 'workflow_run'; - act = act.setEvent({ - workflow_run: { - name: 'Process new code merged to main', - conclusion: 'failure', - }, - }); - const testMockSteps = { - notifyFailure: mocks.FAILURENOTIFIER__NOTIFYFAILURE__STEP_MOCKS, - }; - const result = await act.runEvent(event, { - workflowFile: path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml'), - mockSteps: testMockSteps, - actor, - }); - - // assert execution with imported assertions - assertions.assertNotifyFailureJobExecuted(result); - }); -});