Skip to content

Commit

Permalink
Merge pull request Expensify#38664 from software-mansion-labs/ts-migr…
Browse files Browse the repository at this point in the history
…ation/assertions

[No QA][TS migration] Migrate workflow_tests assertions to TypeScript
  • Loading branch information
aldo-expensify authored Mar 26, 2024
2 parents 271a3b2 + 431dc3f commit fed9d6c
Show file tree
Hide file tree
Showing 34 changed files with 546 additions and 576 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/authorChecklist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v4

- name: authorChecklist.js
- name: authorChecklist.ts
uses: ./.github/actions/javascript/authorChecklist
with:
GITHUB_TOKEN: ${{ github.token }}
20 changes: 0 additions & 20 deletions workflow_tests/assertions/authorChecklistAssertions.js

This file was deleted.

19 changes: 19 additions & 0 deletions workflow_tests/assertions/authorChecklistAssertions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type {Step} from '@kie/act-js';
import {createStepAssertion} from '../utils/utils';

function assertChecklistJobExecuted(workflowResult: Step[], didExecute = true) {
const steps = [
createStepAssertion('Checkout', true, null, 'CHECKLIST', 'Checkout'),
createStepAssertion('authorChecklist.ts', true, null, 'CHECKLIST', 'Running authorChecklist.ts', [{key: 'GITHUB_TOKEN', value: '***'}], []),
] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
expect(workflowResult).toEqual(expect.arrayContaining([expectedStep]));
} else {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
});
}

export default {assertChecklistJobExecuted};
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const utils = require('../utils/utils');
import type {Step} from '@kie/act-js';
import {createStepAssertion} from '../utils/utils';

const assertValidateActorJobExecuted = (workflowResult, didExecute = true) => {
const steps = [utils.createStepAssertion('Check if user is deployer', true, null, 'VALIDATEACTOR', 'Checking if user is a deployer', [], [{key: 'GITHUB_TOKEN', value: '***'}])];
function assertValidateActorJobExecuted(workflowResult: Step[], didExecute = true) {
const steps = [createStepAssertion('Check if user is deployer', true, null, 'VALIDATEACTOR', 'Checking if user is a deployer', [], [{key: 'GITHUB_TOKEN', value: '***'}])] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
Expand All @@ -10,10 +11,10 @@ const assertValidateActorJobExecuted = (workflowResult, didExecute = true) => {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
});
};
}

const assertCreateNewVersionJobExecuted = (workflowResult, didExecute = true) => {
const steps = [utils.createStepAssertion('Create new version', true, null, 'CREATENEWVERSION', 'Creating new version', [], [])];
function assertCreateNewVersionJobExecuted(workflowResult: Step[], didExecute = true) {
const steps = [createStepAssertion('Create new version', true, null, 'CREATENEWVERSION', 'Creating new version', [], [])] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
Expand All @@ -22,11 +23,11 @@ const assertCreateNewVersionJobExecuted = (workflowResult, didExecute = true) =>
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
});
};
}

const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pullRequestNumber = '1234', didExecute = true, hasConflicts = false, isSuccessful = true) => {
function assertCherryPickJobExecuted(workflowResult: Step[], user = 'Dummy Author', pullRequestNumber = '1234', didExecute = true, hasConflicts = false, isSuccessful = true) {
const steps = [
utils.createStepAssertion(
createStepAssertion(
'Checkout staging branch',
true,
null,
Expand All @@ -38,11 +39,11 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull
],
[],
),
utils.createStepAssertion('Set up git for OSBotify', true, null, 'CHERRYPICK', 'Setting up git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []),
utils.createStepAssertion('Get previous app version', true, null, 'CHERRYPICK', 'Get previous app version', [{key: 'SEMVER_LEVEL', value: 'PATCH'}]),
utils.createStepAssertion('Fetch history of relevant refs', true, null, 'CHERRYPICK', 'Fetch history of relevant refs'),
utils.createStepAssertion('Get version bump commit', true, null, 'CHERRYPICK', 'Get version bump commit', [], []),
utils.createStepAssertion(
createStepAssertion('Set up git for OSBotify', true, null, 'CHERRYPICK', 'Setting up git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []),
createStepAssertion('Get previous app version', true, null, 'CHERRYPICK', 'Get previous app version', [{key: 'SEMVER_LEVEL', value: 'PATCH'}]),
createStepAssertion('Fetch history of relevant refs', true, null, 'CHERRYPICK', 'Fetch history of relevant refs'),
createStepAssertion('Get version bump commit', true, null, 'CHERRYPICK', 'Get version bump commit', [], []),
createStepAssertion(
'Get merge commit for pull request to CP',
true,
null,
Expand All @@ -55,10 +56,10 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull
],
[],
),
utils.createStepAssertion('Cherry-pick the version-bump to staging', true, null, 'CHERRYPICK', 'Cherry-picking the version-bump to staging', [], []),
utils.createStepAssertion('Cherry-pick the merge commit of target PR', true, null, 'CHERRYPICK', 'Cherry-picking the merge commit of target PR', [], []),
utils.createStepAssertion('Push changes', true, null, 'CHERRYPICK', 'Pushing changes', [], []),
];
createStepAssertion('Cherry-pick the version-bump to staging', true, null, 'CHERRYPICK', 'Cherry-picking the version-bump to staging', [], []),
createStepAssertion('Cherry-pick the merge commit of target PR', true, null, 'CHERRYPICK', 'Cherry-picking the merge commit of target PR', [], []),
createStepAssertion('Push changes', true, null, 'CHERRYPICK', 'Pushing changes', [], []),
] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
Expand All @@ -69,7 +70,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull
});

const conflictSteps = [
utils.createStepAssertion(
createStepAssertion(
'Create Pull Request to manually finish CP',
true,
null,
Expand All @@ -78,7 +79,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull
[],
[{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}],
),
];
] as const;

conflictSteps.forEach((step) => {
if (didExecute && hasConflicts) {
Expand All @@ -89,7 +90,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull
});

const failedSteps = [
utils.createStepAssertion(
createStepAssertion(
'Announces a CP failure in the #announce Slack room',
true,
null,
Expand All @@ -101,7 +102,7 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull
{key: 'SLACK_WEBHOOK_URL', value: '***'},
],
),
];
] as const;

failedSteps.forEach((step) => {
if (didExecute && !isSuccessful) {
Expand All @@ -110,10 +111,6 @@ const assertCherryPickJobExecuted = (workflowResult, user = 'Dummy Author', pull
expect(workflowResult).not.toEqual(expect.arrayContaining([step]));
}
});
};
}

module.exports = {
assertValidateActorJobExecuted,
assertCreateNewVersionJobExecuted,
assertCherryPickJobExecuted,
};
export default {assertValidateActorJobExecuted, assertCreateNewVersionJobExecuted, assertCherryPickJobExecuted};
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const utils = require('../utils/utils');
import type {Step} from '@kie/act-js';
import {createStepAssertion} from '../utils/utils';

const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository = '', didExecute = true, runAssistant = true) => {
function assertCLAJobExecuted(workflowResult: Step[], commentBody = '', githubRepository = '', didExecute = true, runAssistant = true) {
const steps = [
utils.createStepAssertion(
createStepAssertion(
'CLA comment check',
true,
null,
Expand All @@ -14,7 +15,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository
],
[],
),
utils.createStepAssertion(
createStepAssertion(
'CLA comment re-check',
true,
null,
Expand All @@ -26,7 +27,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository
],
[],
),
];
] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
Expand All @@ -37,7 +38,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository
});

const assistantSteps = [
utils.createStepAssertion(
createStepAssertion(
'CLA Assistant',
true,
null,
Expand All @@ -57,7 +58,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository
{key: 'PERSONAL_ACCESS_TOKEN', value: '***'},
],
),
];
] as const;

assistantSteps.forEach((step) => {
if (didExecute && runAssistant) {
Expand All @@ -66,8 +67,7 @@ const assertCLAJobExecuted = (workflowResult, commentBody = '', githubRepository
expect(workflowResult).not.toEqual(expect.arrayContaining([step]));
}
});
};
}

module.exports = {
assertCLAJobExecuted,
};
// eslint-disable-next-line import/prefer-default-export
export {assertCLAJobExecuted};
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
const utils = require('../utils/utils');
import type {Step} from '@kie/act-js';
import {createStepAssertion} from '../utils/utils';

const assertValidateActorJobExecuted = (workflowResult, didExecute = true) => {
const steps = [utils.createStepAssertion('Get user permissions', true, null, 'VALIDATEACTOR', 'Get user permissions', [], [{key: 'GITHUB_TOKEN', value: '***'}])];
function assertValidateActorJobExecuted(workflowResult: Step[], didExecute = true) {
const steps = [createStepAssertion('Get user permissions', true, null, 'VALIDATEACTOR', 'Get user permissions', [], [{key: 'GITHUB_TOKEN', value: '***'}])] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
Expand All @@ -10,11 +11,12 @@ const assertValidateActorJobExecuted = (workflowResult, didExecute = true) => {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
});
};
const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD', didExecute = true, isSuccessful = true) => {
}

function assertCreateNewVersionJobExecuted(workflowResult: Step[], semverLevel = 'BUILD', didExecute = true, isSuccessful = true) {
const steps = [
utils.createStepAssertion('Run turnstyle', true, null, 'CREATENEWVERSION', 'Run turnstyle', [{key: 'poll-interval-seconds', value: '10'}], [{key: 'GITHUB_TOKEN', value: '***'}]),
utils.createStepAssertion(
createStepAssertion('Run turnstyle', true, null, 'CREATENEWVERSION', 'Run turnstyle', [{key: 'poll-interval-seconds', value: '10'}], [{key: 'GITHUB_TOKEN', value: '***'}]),
createStepAssertion(
'Check out',
true,
null,
Expand All @@ -26,8 +28,8 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD'
],
[],
),
utils.createStepAssertion('Setup git for OSBotify', true, null, 'CREATENEWVERSION', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []),
utils.createStepAssertion(
createStepAssertion('Setup git for OSBotify', true, null, 'CREATENEWVERSION', 'Setup git for OSBotify', [{key: 'GPG_PASSPHRASE', value: '***'}], []),
createStepAssertion(
'Generate version',
true,
null,
Expand All @@ -39,9 +41,9 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD'
],
[],
),
utils.createStepAssertion('Commit new version', true, null, 'CREATENEWVERSION', 'Commit new version', [], []),
utils.createStepAssertion('Update main branch', true, null, 'CREATENEWVERSION', 'Update main branch', [], []),
];
createStepAssertion('Commit new version', true, null, 'CREATENEWVERSION', 'Commit new version', [], []),
createStepAssertion('Update main branch', true, null, 'CREATENEWVERSION', 'Update main branch', [], []),
] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
Expand All @@ -54,8 +56,8 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD'
});

const failedSteps = [
utils.createStepAssertion('Announce failed workflow in Slack', true, null, 'CREATENEWVERSION', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []),
];
createStepAssertion('Announce failed workflow in Slack', true, null, 'CREATENEWVERSION', 'Announce failed workflow in Slack', [{key: 'SLACK_WEBHOOK', value: '***'}], []),
] as const;

failedSteps.forEach((step) => {
if (didExecute && !isSuccessful) {
Expand All @@ -64,9 +66,6 @@ const assertCreateNewVersionJobExecuted = (workflowResult, semverLevel = 'BUILD'
expect(workflowResult).not.toEqual(expect.arrayContaining([step]));
}
});
};
}

module.exports = {
assertValidateActorJobExecuted,
assertCreateNewVersionJobExecuted,
};
export {assertValidateActorJobExecuted, assertCreateNewVersionJobExecuted};
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
const utils = require('../utils/utils');
import type {Step} from '@kie/act-js';
import {createStepAssertion} from '../utils/utils';

const assertDeployStagingJobExecuted = (workflowResult, didExecute = true) => {
function assertDeployStagingJobExecuted(workflowResult: Step[], didExecute = true) {
const steps = [
utils.createStepAssertion('Checkout staging branch', true, null, 'DEPLOY_STAGING', 'Checking out staging branch', [
createStepAssertion('Checkout staging branch', true, null, 'DEPLOY_STAGING', 'Checking out staging branch', [
{key: 'ref', value: 'staging'},
{key: 'token', value: '***'},
]),
utils.createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_STAGING', 'Setting up git for OSBotify', [
createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_STAGING', 'Setting up git for OSBotify', [
{key: 'GPG_PASSPHRASE', value: '***'},
{key: 'OS_BOTIFY_APP_ID', value: '***'},
{key: 'OS_BOTIFY_PRIVATE_KEY', value: '***'},
]),
utils.createStepAssertion('Tag version', true, null, 'DEPLOY_STAGING', 'Tagging new version'),
utils.createStepAssertion('🚀 Push tags to trigger staging deploy 🚀', true, null, 'DEPLOY_STAGING', 'Pushing tag to trigger staging deploy'),
];
createStepAssertion('Tag version', true, null, 'DEPLOY_STAGING', 'Tagging new version'),
createStepAssertion('🚀 Push tags to trigger staging deploy 🚀', true, null, 'DEPLOY_STAGING', 'Pushing tag to trigger staging deploy'),
] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
Expand All @@ -22,27 +23,27 @@ const assertDeployStagingJobExecuted = (workflowResult, didExecute = true) => {
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
});
};
}

const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) => {
function assertDeployProductionJobExecuted(workflowResult: Step[], didExecute = true) {
const steps = [
utils.createStepAssertion('Checkout', true, null, 'DEPLOY_PRODUCTION', 'Checking out', [
createStepAssertion('Checkout', true, null, 'DEPLOY_PRODUCTION', 'Checking out', [
{key: 'ref', value: 'production'},
{key: 'token', value: '***'},
]),
utils.createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_PRODUCTION', 'Setting up git for OSBotify', [
createStepAssertion('Setup git for OSBotify', true, null, 'DEPLOY_PRODUCTION', 'Setting up git for OSBotify', [
{key: 'GPG_PASSPHRASE', value: '***'},
{key: 'OS_BOTIFY_APP_ID', value: '***'},
{key: 'OS_BOTIFY_PRIVATE_KEY', value: '***'},
]),
utils.createStepAssertion('Get current app version', true, null, 'DEPLOY_PRODUCTION', 'Getting current app version'),
utils.createStepAssertion('Get Release Pull Request List', true, null, 'DEPLOY_PRODUCTION', 'Getting release PR list', [
createStepAssertion('Get current app version', true, null, 'DEPLOY_PRODUCTION', 'Getting current app version'),
createStepAssertion('Get Release Pull Request List', true, null, 'DEPLOY_PRODUCTION', 'Getting release PR list', [
{key: 'TAG', value: '1.2.3'},
{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'},
{key: 'IS_PRODUCTION_DEPLOY', value: 'true'},
]),
utils.createStepAssertion('Generate Release Body', true, null, 'DEPLOY_PRODUCTION', 'Generating release body', [{key: 'PR_LIST', value: '[1.2.1, 1.2.2]'}]),
utils.createStepAssertion(
createStepAssertion('Generate Release Body', true, null, 'DEPLOY_PRODUCTION', 'Generating release body', [{key: 'PR_LIST', value: '[1.2.1, 1.2.2]'}]),
createStepAssertion(
'🚀 Create release to trigger production deploy 🚀',
true,
null,
Expand All @@ -54,7 +55,7 @@ const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) =>
],
[{key: 'GITHUB_TOKEN', value: 'os_botify_api_token'}],
),
];
] as const;

steps.forEach((expectedStep) => {
if (didExecute) {
Expand All @@ -63,9 +64,6 @@ const assertDeployProductionJobExecuted = (workflowResult, didExecute = true) =>
expect(workflowResult).not.toEqual(expect.arrayContaining([expectedStep]));
}
});
};
}

module.exports = {
assertDeployStagingJobExecuted,
assertDeployProductionJobExecuted,
};
export {assertDeployStagingJobExecuted, assertDeployProductionJobExecuted};
Loading

0 comments on commit fed9d6c

Please sign in to comment.