From d6dc078d5a3463d58637b586c7d48fc133ff8f1c Mon Sep 17 00:00:00 2001 From: Frostebite Date: Sun, 3 Aug 2025 00:50:29 +0100 Subject: [PATCH] test: always mock github check requests --- .../tests/cloud-runner-github-checks.test.ts | 107 +++++++++--------- 1 file changed, 52 insertions(+), 55 deletions(-) diff --git a/src/model/cloud-runner/tests/cloud-runner-github-checks.test.ts b/src/model/cloud-runner/tests/cloud-runner-github-checks.test.ts index b2991800..e55e43cc 100644 --- a/src/model/cloud-runner/tests/cloud-runner-github-checks.test.ts +++ b/src/model/cloud-runner/tests/cloud-runner-github-checks.test.ts @@ -2,7 +2,6 @@ import { BuildParameters } from '../..'; import CloudRunner from '../cloud-runner'; import UnityVersioning from '../../unity-versioning'; import { Cli } from '../../cli/cli'; -import CloudRunnerOptions from '../options/cloud-runner-options'; import setups from './cloud-runner-suite.test'; import { OptionValues } from 'commander'; import GitHub from '../../github'; @@ -16,61 +15,59 @@ describe('Cloud Runner Github Checks', () => { setups(); it('Responds', () => {}); - if (CloudRunnerOptions.cloudRunnerDebug) { - beforeEach(() => { - // Mock GitHub API requests to avoid real network calls - jest.spyOn(GitHub as any, 'createGitHubCheckRequest').mockResolvedValue({ - status: 201, - data: { id: '1' }, - }); - jest.spyOn(GitHub as any, 'updateGitHubCheckRequest').mockResolvedValue({ - status: 200, - data: {}, - }); - jest.spyOn(GitHub as any, 'runUpdateAsyncChecksWorkflow').mockResolvedValue(undefined); + beforeEach(() => { + // Mock GitHub API requests to avoid real network calls + jest.spyOn(GitHub as any, 'createGitHubCheckRequest').mockResolvedValue({ + status: 201, + data: { id: '1' }, }); - - afterEach(() => { - jest.restoreAllMocks(); + jest.spyOn(GitHub as any, 'updateGitHubCheckRequest').mockResolvedValue({ + status: 200, + data: {}, }); + jest.spyOn(GitHub as any, 'runUpdateAsyncChecksWorkflow').mockResolvedValue(undefined); + }); - it( - 'Check Handling Direct', - async () => { - // Setup parameters - const buildParameter = await CreateParameters({ - versioning: 'None', - projectPath: 'test-project', - unityVersion: UnityVersioning.read('test-project'), - asyncCloudRunner: `true`, - githubChecks: `true`, - }); - await CloudRunner.setup(buildParameter); - CloudRunner.buildParameters.githubCheckId = await GitHub.createGitHubCheck(`direct create`); - await GitHub.updateGitHubCheck(`1 ${new Date().toISOString()}`, `direct`); - await GitHub.updateGitHubCheck(`2 ${new Date().toISOString()}`, `direct`, `success`, `completed`); - }, - TIMEOUT_INFINITE, - ); - it( - 'Check Handling Via Async Workflow', - async () => { - // Setup parameters - const buildParameter = await CreateParameters({ - versioning: 'None', - projectPath: 'test-project', - unityVersion: UnityVersioning.read('test-project'), - asyncCloudRunner: `true`, - githubChecks: `true`, - }); - GitHub.forceAsyncTest = true; - await CloudRunner.setup(buildParameter); - CloudRunner.buildParameters.githubCheckId = await GitHub.createGitHubCheck(`async create`); - await GitHub.updateGitHubCheck(`1 ${new Date().toISOString()}`, `async`); - await GitHub.updateGitHubCheck(`2 ${new Date().toISOString()}`, `async`, `success`, `completed`); - GitHub.forceAsyncTest = false; - }, - TIMEOUT_INFINITE, - ); - } + afterEach(() => { + jest.restoreAllMocks(); + }); + + it( + 'Check Handling Direct', + async () => { + // Setup parameters + const buildParameter = await CreateParameters({ + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.read('test-project'), + asyncCloudRunner: `true`, + githubChecks: `true`, + }); + await CloudRunner.setup(buildParameter); + CloudRunner.buildParameters.githubCheckId = await GitHub.createGitHubCheck(`direct create`); + await GitHub.updateGitHubCheck(`1 ${new Date().toISOString()}`, `direct`); + await GitHub.updateGitHubCheck(`2 ${new Date().toISOString()}`, `direct`, `success`, `completed`); + }, + TIMEOUT_INFINITE, + ); + it( + 'Check Handling Via Async Workflow', + async () => { + // Setup parameters + const buildParameter = await CreateParameters({ + versioning: 'None', + projectPath: 'test-project', + unityVersion: UnityVersioning.read('test-project'), + asyncCloudRunner: `true`, + githubChecks: `true`, + }); + GitHub.forceAsyncTest = true; + await CloudRunner.setup(buildParameter); + CloudRunner.buildParameters.githubCheckId = await GitHub.createGitHubCheck(`async create`); + await GitHub.updateGitHubCheck(`1 ${new Date().toISOString()}`, `async`); + await GitHub.updateGitHubCheck(`2 ${new Date().toISOString()}`, `async`, `success`, `completed`); + GitHub.forceAsyncTest = false; + }, + TIMEOUT_INFINITE, + ); });