Combine test credentials methods into testCredentialsWithRealOctokit

This commit is contained in:
Robert
2023-01-24 15:40:21 +00:00
parent 03993f376f
commit 697a004005
3 changed files with 9 additions and 15 deletions

View File

@@ -29,10 +29,6 @@ export function testCredentialsWithStub(
return makeTestOctokit({ request } as any); return makeTestOctokit({ request } as any);
} }
export function testCredentialsWithUnauthenticatedOctokit(): Credentials { export function testCredentialsWithRealOctokit(token?: string): Credentials {
return makeTestOctokit(new Octokit.Octokit({ retry }));
}
export function testCredentialsWithToken(token: string): Credentials {
return makeTestOctokit(new Octokit.Octokit({ auth: token, retry })); return makeTestOctokit(new Octokit.Octokit({ auth: token, retry }));
} }

View File

@@ -13,9 +13,7 @@ import { MockGitHubApiServer } from "../../../../src/mocks/mock-gh-api-server";
import { response } from "../../../../src/mocks/scenarios/problem-query-success/0-getRepo.json"; import { response } from "../../../../src/mocks/scenarios/problem-query-success/0-getRepo.json";
import { response as variantAnalysisJson_response } from "../../../../src/mocks/scenarios/problem-query-success/1-submitVariantAnalysis.json"; import { response as variantAnalysisJson_response } from "../../../../src/mocks/scenarios/problem-query-success/1-submitVariantAnalysis.json";
import { response as variantAnalysisRepoJson_response } from "../../../../src/mocks/scenarios/problem-query-success/9-getVariantAnalysisRepo.json"; import { response as variantAnalysisRepoJson_response } from "../../../../src/mocks/scenarios/problem-query-success/9-getVariantAnalysisRepo.json";
import { testCredentialsWithUnauthenticatedOctokit } from "../../../factories/authentication"; import { testCredentialsWithRealOctokit } from "../../../factories/authentication";
const mockCredentials = testCredentialsWithUnauthenticatedOctokit();
const mockServer = new MockGitHubApiServer(); const mockServer = new MockGitHubApiServer();
beforeAll(() => mockServer.startServer()); beforeAll(() => mockServer.startServer());
@@ -31,7 +29,7 @@ describe("submitVariantAnalysis", () => {
await mockServer.loadScenario("problem-query-success"); await mockServer.loadScenario("problem-query-success");
const result = await submitVariantAnalysis( const result = await submitVariantAnalysis(
mockCredentials, testCredentialsWithRealOctokit(),
createMockSubmission(), createMockSubmission(),
); );
@@ -45,7 +43,7 @@ describe("getVariantAnalysis", () => {
await mockServer.loadScenario("problem-query-success"); await mockServer.loadScenario("problem-query-success");
const result = await getVariantAnalysis( const result = await getVariantAnalysis(
mockCredentials, testCredentialsWithRealOctokit(),
controllerRepoId, controllerRepoId,
variantAnalysisId, variantAnalysisId,
); );
@@ -60,7 +58,7 @@ describe("getVariantAnalysisRepo", () => {
await mockServer.loadScenario("problem-query-success"); await mockServer.loadScenario("problem-query-success");
const result = await getVariantAnalysisRepo( const result = await getVariantAnalysisRepo(
mockCredentials, testCredentialsWithRealOctokit(),
controllerRepoId, controllerRepoId,
variantAnalysisId, variantAnalysisId,
repoTaskId, repoTaskId,
@@ -76,7 +74,7 @@ describe("getVariantAnalysisRepoResult", () => {
await mockServer.loadScenario("problem-query-success"); await mockServer.loadScenario("problem-query-success");
const result = await getVariantAnalysisRepoResult( const result = await getVariantAnalysisRepoResult(
mockCredentials, testCredentialsWithRealOctokit(),
`https://objects-origin.githubusercontent.com/codeql-query-console/codeql-variant-analysis-repo-tasks/${variantAnalysisId}/${repoTaskId}/${faker.datatype.uuid()}`, `https://objects-origin.githubusercontent.com/codeql-query-console/codeql-variant-analysis-repo-tasks/${variantAnalysisId}/${repoTaskId}/${faker.datatype.uuid()}`,
); );
@@ -93,7 +91,7 @@ describe("getRepositoryFromNwo", () => {
await mockServer.loadScenario("problem-query-success"); await mockServer.loadScenario("problem-query-success");
const result = await getRepositoryFromNwo( const result = await getRepositoryFromNwo(
mockCredentials, testCredentialsWithRealOctokit(),
"github", "github",
"mrva-demo-controller-repo", "mrva-demo-controller-repo",
); );

View File

@@ -8,7 +8,7 @@ import { createMockVariantAnalysis } from "../../../../factories/remote-queries/
import { VariantAnalysis } from "../../../../../src/remote-queries/shared/variant-analysis"; import { VariantAnalysis } from "../../../../../src/remote-queries/shared/variant-analysis";
import { import {
testCredentialsWithStub, testCredentialsWithStub,
testCredentialsWithToken, testCredentialsWithRealOctokit,
} from "../../../../factories/authentication"; } from "../../../../factories/authentication";
jest.setTimeout(10000); jest.setTimeout(10000);
@@ -93,7 +93,7 @@ describe("gh-actions-api-client real responses", () => {
return; return;
} }
const credentials = testCredentialsWithToken( const credentials = testCredentialsWithRealOctokit(
process.env.VSCODE_CODEQL_GITHUB_TOKEN!, process.env.VSCODE_CODEQL_GITHUB_TOKEN!,
); );
const stargazers = await getRepositoriesMetadata( const stargazers = await getRepositoriesMetadata(