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

[TS migration] Migrate awaitStagingDeploysTest to Typescript #37084

5 changes: 5 additions & 0 deletions src/types/utils/AsMutable.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type {Writable} from 'type-fest';

const asMutable = <T>(value: T): Writable<T> => value as Writable<T>;

export default asMutable;
Original file line number Diff line number Diff line change
@@ -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<MockListResponse>>;

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) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The logic is a bit different, this is more accurate:

    if (!('workflow_id' in args)) {

But the suggested change should work, right?

return defaultReturn;
}

if (!_.isUndefined(args.branch)) {
if (args.branch !== undefined) {
return mockListPlatformDeploysForTag();
}

Expand All @@ -40,7 +57,7 @@

beforeAll(() => {
// Mock core module
core.getInput = mockGetInput;
asMutable(core).getInput = mockGetInput;

// Mock octokit module
const moctokit = {
Expand All @@ -50,8 +67,10 @@
},
},
};

// @ts-expect-error TODO: Remove this once GithubUtils (https://github.com/Expensify/App/issues/25382) is migrated to TypeScript.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's hold this PR for now

GithubUtils.internalOctokit = moctokit;
GithubUtils.POLL_RATE = TEST_POLL_RATE;

Check failure on line 73 in tests/unit/awaitStagingDeploysTest.ts

View workflow job for this annotation

GitHub Actions / typecheck

Property 'POLL_RATE' does not exist on type 'typeof GithubUtils'.
});

beforeEach(() => {
Expand Down
Loading