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

1 change: 1 addition & 0 deletions .github/actions/javascript/authorChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16918,6 +16918,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
1 change: 1 addition & 0 deletions .github/actions/javascript/awaitStagingDeploys/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12375,6 +12375,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
1 change: 1 addition & 0 deletions .github/actions/javascript/checkDeployBlockers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11578,6 +11578,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14751,6 +14751,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
1 change: 1 addition & 0 deletions .github/actions/javascript/getArtifactInfo/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11560,6 +11560,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11978,6 +11978,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11545,6 +11545,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
1 change: 1 addition & 0 deletions .github/actions/javascript/getReleaseBody/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11545,6 +11545,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11560,6 +11560,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11741,6 +11741,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
1 change: 1 addition & 0 deletions .github/actions/javascript/postTestBuildComment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11659,6 +11659,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11570,6 +11570,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
1 change: 1 addition & 0 deletions .github/actions/javascript/reviewerChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11543,6 +11543,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
1 change: 1 addition & 0 deletions .github/actions/javascript/verifySignedCommits/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11543,6 +11543,7 @@ const POLL_RATE = 10000;
exports.POLL_RATE = POLL_RATE;
class GithubUtils {
static internalOctokit;
static POLL_RATE;
/**
* Initialize internal octokit
*
Expand Down
2 changes: 2 additions & 0 deletions .github/libs/GithubUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ type InternalOctokit = OctokitCore & Api & {paginate: PaginateInterface};
class GithubUtils {
static internalOctokit: InternalOctokit | undefined;

static POLL_RATE: number;

/**
* Initialize internal octokit
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,48 @@
/* 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 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};

// 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,16 +59,18 @@ const mockListWorkflowRuns = jest.fn().mockImplementation((args) => {

beforeAll(() => {
// Mock core module
core.getInput = mockGetInput;
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
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is needed because InternalOctoKit requires all the data of the object to be passed but in this case for the unit tests we shall only pass listWorkflowRuns otherwise it will break the test

actions: {
listWorkflowRuns: mockListWorkflowRuns,
listWorkflowRuns: mockListWorkflowRuns as unknown as typeof GithubUtils.octokit.actions.listWorkflowRuns,
},
},
};

GithubUtils.internalOctokit = moctokit;
GithubUtils.POLL_RATE = TEST_POLL_RATE;
});
Expand Down
Loading