Skip to content

Commit 697a004

Browse files
Combine test credentials methods into testCredentialsWithRealOctokit
1 parent 03993f3 commit 697a004

File tree

3 files changed

+9
-15
lines changed

3 files changed

+9
-15
lines changed

extensions/ql-vscode/test/factories/authentication.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,6 @@ export function testCredentialsWithStub(
2929
return makeTestOctokit({ request } as any);
3030
}
3131

32-
export function testCredentialsWithUnauthenticatedOctokit(): Credentials {
33-
return makeTestOctokit(new Octokit.Octokit({ retry }));
34-
}
35-
36-
export function testCredentialsWithToken(token: string): Credentials {
32+
export function testCredentialsWithRealOctokit(token?: string): Credentials {
3733
return makeTestOctokit(new Octokit.Octokit({ auth: token, retry }));
3834
}

extensions/ql-vscode/test/unit-tests/remote-queries/gh-api/gh-api-client.test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import { MockGitHubApiServer } from "../../../../src/mocks/mock-gh-api-server";
1313
import { response } from "../../../../src/mocks/scenarios/problem-query-success/0-getRepo.json";
1414
import { response as variantAnalysisJson_response } from "../../../../src/mocks/scenarios/problem-query-success/1-submitVariantAnalysis.json";
1515
import { response as variantAnalysisRepoJson_response } from "../../../../src/mocks/scenarios/problem-query-success/9-getVariantAnalysisRepo.json";
16-
import { testCredentialsWithUnauthenticatedOctokit } from "../../../factories/authentication";
17-
18-
const mockCredentials = testCredentialsWithUnauthenticatedOctokit();
16+
import { testCredentialsWithRealOctokit } from "../../../factories/authentication";
1917

2018
const mockServer = new MockGitHubApiServer();
2119
beforeAll(() => mockServer.startServer());
@@ -31,7 +29,7 @@ describe("submitVariantAnalysis", () => {
3129
await mockServer.loadScenario("problem-query-success");
3230

3331
const result = await submitVariantAnalysis(
34-
mockCredentials,
32+
testCredentialsWithRealOctokit(),
3533
createMockSubmission(),
3634
);
3735

@@ -45,7 +43,7 @@ describe("getVariantAnalysis", () => {
4543
await mockServer.loadScenario("problem-query-success");
4644

4745
const result = await getVariantAnalysis(
48-
mockCredentials,
46+
testCredentialsWithRealOctokit(),
4947
controllerRepoId,
5048
variantAnalysisId,
5149
);
@@ -60,7 +58,7 @@ describe("getVariantAnalysisRepo", () => {
6058
await mockServer.loadScenario("problem-query-success");
6159

6260
const result = await getVariantAnalysisRepo(
63-
mockCredentials,
61+
testCredentialsWithRealOctokit(),
6462
controllerRepoId,
6563
variantAnalysisId,
6664
repoTaskId,
@@ -76,7 +74,7 @@ describe("getVariantAnalysisRepoResult", () => {
7674
await mockServer.loadScenario("problem-query-success");
7775

7876
const result = await getVariantAnalysisRepoResult(
79-
mockCredentials,
77+
testCredentialsWithRealOctokit(),
8078
`https://objects-origin.githubusercontent.com/codeql-query-console/codeql-variant-analysis-repo-tasks/${variantAnalysisId}/${repoTaskId}/${faker.datatype.uuid()}`,
8179
);
8280

@@ -93,7 +91,7 @@ describe("getRepositoryFromNwo", () => {
9391
await mockServer.loadScenario("problem-query-success");
9492

9593
const result = await getRepositoryFromNwo(
96-
mockCredentials,
94+
testCredentialsWithRealOctokit(),
9795
"github",
9896
"mrva-demo-controller-repo",
9997
);

extensions/ql-vscode/test/vscode-tests/no-workspace/remote-queries/gh-api/gh-actions-api-client.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { createMockVariantAnalysis } from "../../../../factories/remote-queries/
88
import { VariantAnalysis } from "../../../../../src/remote-queries/shared/variant-analysis";
99
import {
1010
testCredentialsWithStub,
11-
testCredentialsWithToken,
11+
testCredentialsWithRealOctokit,
1212
} from "../../../../factories/authentication";
1313

1414
jest.setTimeout(10000);
@@ -93,7 +93,7 @@ describe("gh-actions-api-client real responses", () => {
9393
return;
9494
}
9595

96-
const credentials = testCredentialsWithToken(
96+
const credentials = testCredentialsWithRealOctokit(
9797
process.env.VSCODE_CODEQL_GITHUB_TOKEN!,
9898
);
9999
const stargazers = await getRepositoriesMetadata(

0 commit comments

Comments
 (0)