Skip to content

Commit

Permalink
Merge pull request #37084 from ruben-rebelo/ts-migration/unit-awaitSt…
Browse files Browse the repository at this point in the history
…agingDeploysTest

[TS migration] Migrate awaitStagingDeploysTest to Typescript
  • Loading branch information
marcaaron authored Mar 30, 2024
2 parents 54c669f + 5e8d0ee commit edacb67
Show file tree
Hide file tree
Showing 16 changed files with 49 additions and 12 deletions.
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
1 change: 1 addition & 0 deletions .github/actions/javascript/getPullRequestDetails/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
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
1 change: 1 addition & 0 deletions .github/actions/javascript/isStagingDeployLocked/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 @@ -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
1 change: 1 addition & 0 deletions .github/actions/javascript/reopenIssueWithComment/index.js
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) {
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
actions: {
listWorkflowRuns: mockListWorkflowRuns,
listWorkflowRuns: mockListWorkflowRuns as unknown as typeof GithubUtils.octokit.actions.listWorkflowRuns,
},
},
};

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

0 comments on commit edacb67

Please sign in to comment.