Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
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;
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;
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 kieMockGithub.MockGithub({
mockGithub = new MockGithub({
repo: {
testFailureNotifierWorkflowRepo: {
files: FILES_TO_COPY_INTO_TEST_REPO,

// if any branches besides main are need add: pushedBranches: ['staging', 'production'],
// if any branches besides main are needed add: pushedBranches: ['staging', 'production'],
},
},
});
Expand All @@ -34,19 +37,21 @@ describe('test workflow failureNotifier', () => {
await mockGithub.teardown();
});
it('runs the notify failure when main fails', async () => {
const repoPath = mockGithub.repo.getPath('testFailureNotifierWorkflowRepo') || '';
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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if as const is needed, probably just satisfies ... is enough.

I did a quick search on the project and did not find the pattern as const satisfies ... used anywhere else

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as const enforces immutability, satisfies generalizes a type. I think it's good to use it as long as we know the content isn't supposed to change

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fair enough, then leave as is 👍


const result = await act.runEvent(event, {
workflowFile: path.join(repoPath, '.github', 'workflows', 'failureNotifier.yml'),
mockSteps: testMockSteps,
Expand Down