From ffbe73a35218775b153099c0544751217fdb2414 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Thu, 22 Feb 2024 14:39:27 +0000 Subject: [PATCH 1/4] [TS migration] Migrate awaitStagingDeploysTest to Typescript --- src/types/utils/AsMutable.ts | 5 +++ ...loysTest.js => awaitStagingDeploysTest.ts} | 39 ++++++++++++++----- 2 files changed, 34 insertions(+), 10 deletions(-) create mode 100644 src/types/utils/AsMutable.ts rename tests/unit/{awaitStagingDeploysTest.js => awaitStagingDeploysTest.ts} (83%) diff --git a/src/types/utils/AsMutable.ts b/src/types/utils/AsMutable.ts new file mode 100644 index 000000000000..57c49058cd14 --- /dev/null +++ b/src/types/utils/AsMutable.ts @@ -0,0 +1,5 @@ +import type {Writable} from 'type-fest'; + +const asMutable = (value: T): Writable => value as Writable; + +export default asMutable; diff --git a/tests/unit/awaitStagingDeploysTest.js b/tests/unit/awaitStagingDeploysTest.ts similarity index 83% rename from tests/unit/awaitStagingDeploysTest.js rename to tests/unit/awaitStagingDeploysTest.ts index 8b8327e99047..7f1d6bac1eaa 100644 --- a/tests/unit/awaitStagingDeploysTest.js +++ b/tests/unit/awaitStagingDeploysTest.ts @@ -1,29 +1,46 @@ +/* eslint-disable @typescript-eslint/naming-convention */ + /** * @jest-environment node */ import * as core from '@actions/core'; -import _ from 'underscore'; +import asMutable from '@src/types/utils/AsMutable'; import run from '../../.github/actions/javascript/awaitStagingDeploys/awaitStagingDeploys'; import GithubUtils from '../../.github/libs/GithubUtils'; +type Workflow = { + workflow_id: string; + branch: string; +}; + +type WorkflowStatus = {status: string}; + // Lower poll rate to speed up tests const TEST_POLL_RATE = 1; -const COMPLETED_WORKFLOW = {status: 'completed'}; -const INCOMPLETE_WORKFLOW = {status: 'in_progress'}; +const COMPLETED_WORKFLOW: WorkflowStatus = {status: 'completed'}; +const INCOMPLETE_WORKFLOW: WorkflowStatus = {status: 'in_progress'}; + +type MockListResponse = { + data: { + workflow_runs: WorkflowStatus[]; + }; +}; + +type MockedFunctionListResponse = jest.MockedFunction<() => Promise>; const consoleSpy = jest.spyOn(console, 'log'); const mockGetInput = jest.fn(); -const mockListPlatformDeploysForTag = jest.fn(); -const mockListPlatformDeploys = jest.fn(); -const mockListPreDeploys = jest.fn(); -const mockListWorkflowRuns = jest.fn().mockImplementation((args) => { +const mockListPlatformDeploysForTag: MockedFunctionListResponse = jest.fn(); +const mockListPlatformDeploys: MockedFunctionListResponse = jest.fn(); +const mockListPreDeploys: MockedFunctionListResponse = jest.fn(); +const mockListWorkflowRuns = jest.fn().mockImplementation((args: Workflow) => { const defaultReturn = Promise.resolve({data: {workflow_runs: []}}); - if (!_.has(args, 'workflow_id')) { + if (!args.workflow_id) { return defaultReturn; } - if (!_.isUndefined(args.branch)) { + if (args.branch !== undefined) { return mockListPlatformDeploysForTag(); } @@ -40,7 +57,7 @@ const mockListWorkflowRuns = jest.fn().mockImplementation((args) => { beforeAll(() => { // Mock core module - core.getInput = mockGetInput; + asMutable(core).getInput = mockGetInput; // Mock octokit module const moctokit = { @@ -50,6 +67,8 @@ beforeAll(() => { }, }, }; + + // @ts-expect-error TODO: Remove this once GithubUtils (https://github.com/Expensify/App/issues/25382) is migrated to TypeScript. GithubUtils.internalOctokit = moctokit; GithubUtils.POLL_RATE = TEST_POLL_RATE; }); From 0bb481dcf86bc56a84ac7147d0feefb5c7443ac4 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Thu, 28 Mar 2024 14:12:59 +0000 Subject: [PATCH 2/4] [TS migration][awaitStagingDeploysTest] Removed expect error from octokit --- .github/libs/GithubUtils.ts | 2 ++ tests/unit/awaitStagingDeploysTest.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/libs/GithubUtils.ts b/.github/libs/GithubUtils.ts index 52122702fb2d..9d536a1ac18b 100644 --- a/.github/libs/GithubUtils.ts +++ b/.github/libs/GithubUtils.ts @@ -75,6 +75,8 @@ type InternalOctokit = OctokitCore & Api & {paginate: PaginateInterface}; class GithubUtils { static internalOctokit: InternalOctokit | undefined; + static POLL_RATE: number; + /** * Initialize internal octokit * diff --git a/tests/unit/awaitStagingDeploysTest.ts b/tests/unit/awaitStagingDeploysTest.ts index 7f1d6bac1eaa..1bda7b0fac23 100644 --- a/tests/unit/awaitStagingDeploysTest.ts +++ b/tests/unit/awaitStagingDeploysTest.ts @@ -4,13 +4,15 @@ * @jest-environment node */ import * as core from '@actions/core'; -import asMutable from '@src/types/utils/AsMutable'; +import asMutable from '@src/types/utils/asMutable'; import run from '../../.github/actions/javascript/awaitStagingDeploys/awaitStagingDeploys'; +import type {InternalOctokit} from '../../.github/libs/GithubUtils'; import GithubUtils from '../../.github/libs/GithubUtils'; type Workflow = { workflow_id: string; branch: string; + owner: string; }; type WorkflowStatus = {status: string}; @@ -60,15 +62,15 @@ beforeAll(() => { asMutable(core).getInput = mockGetInput; // Mock octokit module - const moctokit = { + const moctokit: InternalOctokit = { rest: { + // @ts-expect-error This error was removed because getting the rest of the data from internalOctokit makes the test to break actions: { - listWorkflowRuns: mockListWorkflowRuns, + listWorkflowRuns: mockListWorkflowRuns as unknown as typeof GithubUtils.octokit.actions.listWorkflowRuns, }, }, }; - // @ts-expect-error TODO: Remove this once GithubUtils (https://github.com/Expensify/App/issues/25382) is migrated to TypeScript. GithubUtils.internalOctokit = moctokit; GithubUtils.POLL_RATE = TEST_POLL_RATE; }); From 887bfcd4b080884e0200f204c29216d1c96d7047 Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Thu, 28 Mar 2024 14:19:26 +0000 Subject: [PATCH 3/4] [TS migration][awaitStagingDeploysTest] Generated github utils --- .github/actions/javascript/authorChecklist/index.js | 1 + .github/actions/javascript/awaitStagingDeploys/index.js | 1 + .github/actions/javascript/checkDeployBlockers/index.js | 1 + .github/actions/javascript/createOrUpdateStagingDeploy/index.js | 1 + .github/actions/javascript/getArtifactInfo/index.js | 1 + .github/actions/javascript/getDeployPullRequestList/index.js | 1 + .github/actions/javascript/getPullRequestDetails/index.js | 1 + .github/actions/javascript/getReleaseBody/index.js | 1 + .github/actions/javascript/isStagingDeployLocked/index.js | 1 + .github/actions/javascript/markPullRequestsAsDeployed/index.js | 1 + .github/actions/javascript/postTestBuildComment/index.js | 1 + .github/actions/javascript/reopenIssueWithComment/index.js | 1 + .github/actions/javascript/reviewerChecklist/index.js | 1 + .github/actions/javascript/verifySignedCommits/index.js | 1 + 14 files changed, 14 insertions(+) diff --git a/.github/actions/javascript/authorChecklist/index.js b/.github/actions/javascript/authorChecklist/index.js index 02c97d7a0e2b..d779e197c081 100644 --- a/.github/actions/javascript/authorChecklist/index.js +++ b/.github/actions/javascript/authorChecklist/index.js @@ -16918,6 +16918,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/awaitStagingDeploys/index.js b/.github/actions/javascript/awaitStagingDeploys/index.js index 6dc6a4a213e3..fa7c6bc60903 100644 --- a/.github/actions/javascript/awaitStagingDeploys/index.js +++ b/.github/actions/javascript/awaitStagingDeploys/index.js @@ -11680,6 +11680,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/checkDeployBlockers/index.js b/.github/actions/javascript/checkDeployBlockers/index.js index a83cdd2b71fc..979543ac3ba8 100644 --- a/.github/actions/javascript/checkDeployBlockers/index.js +++ b/.github/actions/javascript/checkDeployBlockers/index.js @@ -11578,6 +11578,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/createOrUpdateStagingDeploy/index.js b/.github/actions/javascript/createOrUpdateStagingDeploy/index.js index 69eef6cfc7fc..c9f8f7d560ce 100644 --- a/.github/actions/javascript/createOrUpdateStagingDeploy/index.js +++ b/.github/actions/javascript/createOrUpdateStagingDeploy/index.js @@ -14751,6 +14751,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/getArtifactInfo/index.js b/.github/actions/javascript/getArtifactInfo/index.js index 7dc0300895b0..c99381ffe0b4 100644 --- a/.github/actions/javascript/getArtifactInfo/index.js +++ b/.github/actions/javascript/getArtifactInfo/index.js @@ -11560,6 +11560,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/getDeployPullRequestList/index.js b/.github/actions/javascript/getDeployPullRequestList/index.js index 30cef0dbdc68..da8a91a28c0d 100644 --- a/.github/actions/javascript/getDeployPullRequestList/index.js +++ b/.github/actions/javascript/getDeployPullRequestList/index.js @@ -11978,6 +11978,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/getPullRequestDetails/index.js b/.github/actions/javascript/getPullRequestDetails/index.js index 71c502f6161f..dd13a9c3f8f4 100644 --- a/.github/actions/javascript/getPullRequestDetails/index.js +++ b/.github/actions/javascript/getPullRequestDetails/index.js @@ -11545,6 +11545,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/getReleaseBody/index.js b/.github/actions/javascript/getReleaseBody/index.js index f07678cbaf24..68e211b29ab0 100644 --- a/.github/actions/javascript/getReleaseBody/index.js +++ b/.github/actions/javascript/getReleaseBody/index.js @@ -11545,6 +11545,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/isStagingDeployLocked/index.js b/.github/actions/javascript/isStagingDeployLocked/index.js index c5afdab0b078..a8b3065832df 100644 --- a/.github/actions/javascript/isStagingDeployLocked/index.js +++ b/.github/actions/javascript/isStagingDeployLocked/index.js @@ -11529,6 +11529,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/markPullRequestsAsDeployed/index.js b/.github/actions/javascript/markPullRequestsAsDeployed/index.js index e43aec749df7..ebd9d8b16098 100644 --- a/.github/actions/javascript/markPullRequestsAsDeployed/index.js +++ b/.github/actions/javascript/markPullRequestsAsDeployed/index.js @@ -11741,6 +11741,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/postTestBuildComment/index.js b/.github/actions/javascript/postTestBuildComment/index.js index 27214d85d18d..05d3fd937341 100644 --- a/.github/actions/javascript/postTestBuildComment/index.js +++ b/.github/actions/javascript/postTestBuildComment/index.js @@ -11648,6 +11648,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/reopenIssueWithComment/index.js b/.github/actions/javascript/reopenIssueWithComment/index.js index 252e772359ac..8463ef6e9fe3 100644 --- a/.github/actions/javascript/reopenIssueWithComment/index.js +++ b/.github/actions/javascript/reopenIssueWithComment/index.js @@ -11499,6 +11499,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/reviewerChecklist/index.js b/.github/actions/javascript/reviewerChecklist/index.js index b63c55ae5eb8..f8487d8001a2 100644 --- a/.github/actions/javascript/reviewerChecklist/index.js +++ b/.github/actions/javascript/reviewerChecklist/index.js @@ -11543,6 +11543,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * diff --git a/.github/actions/javascript/verifySignedCommits/index.js b/.github/actions/javascript/verifySignedCommits/index.js index 26c0757dcde7..2e199b82f31a 100644 --- a/.github/actions/javascript/verifySignedCommits/index.js +++ b/.github/actions/javascript/verifySignedCommits/index.js @@ -11543,6 +11543,7 @@ const POLL_RATE = 10000; exports.POLL_RATE = POLL_RATE; class GithubUtils { static internalOctokit; + static POLL_RATE; /** * Initialize internal octokit * From 5e8d0ee4cc3b9b4aedfe3ef20f9c690a798e872d Mon Sep 17 00:00:00 2001 From: ruben-rebelo Date: Fri, 29 Mar 2024 16:00:03 +0000 Subject: [PATCH 4/4] [TS migration] Removed AsMutable old file --- src/types/utils/AsMutable.ts | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/types/utils/AsMutable.ts diff --git a/src/types/utils/AsMutable.ts b/src/types/utils/AsMutable.ts deleted file mode 100644 index 57c49058cd14..000000000000 --- a/src/types/utils/AsMutable.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type {Writable} from 'type-fest'; - -const asMutable = (value: T): Writable => value as Writable; - -export default asMutable;