Skip to content

Commit 5629865

Browse files
committed
Use scenario JSON files in tests
This will check that the data returned matches the data in the JSON files, rather than checking against constants/magic values.
1 parent c4d9ef2 commit 5629865

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { expect } from 'chai';
33
import * as Octokit from '@octokit/rest';
44
import { retry } from '@octokit/plugin-retry';
55

6+
import { faker } from '@faker-js/faker';
7+
68
import {
79
getRepositoryFromNwo,
810
getVariantAnalysis,
@@ -15,6 +17,10 @@ import {
1517
} from '../../../../src/vscode-tests/factories/remote-queries/shared/variant-analysis-submission';
1618
import { MockGitHubApiServer } from '../../../../src/mocks/mock-gh-api-server';
1719

20+
import * as getRepoJson from '../../../../src/mocks/scenarios/problem-query-success/0-getRepo.json';
21+
import * as variantAnalysisJson from '../../../../src/mocks/scenarios/problem-query-success/1-submitVariantAnalysis.json';
22+
import * as variantAnalysisRepoJson from '../../../../src/mocks/scenarios/problem-query-success/9-getVariantAnalysisRepo.json';
23+
1824
const mockCredentials = {
1925
getOctokit: () => Promise.resolve(new Octokit.Octokit({ retry }))
2026
} as unknown as Credentials;
@@ -24,22 +30,26 @@ before(() => mockServer.startServer());
2430
afterEach(() => mockServer.unloadScenario());
2531
after(() => mockServer.stopServer());
2632

33+
const controllerRepoId = variantAnalysisJson.response.body.controller_repo.id;
34+
const variantAnalysisId = variantAnalysisJson.response.body.id;
35+
const repoTaskId = variantAnalysisRepoJson.response.body.repository.id;
36+
2737
describe('submitVariantAnalysis', () => {
2838
it('returns the submitted variant analysis', async () => {
2939
await mockServer.loadScenario('problem-query-success');
3040

3141
const result = await submitVariantAnalysis(mockCredentials, createMockSubmission());
3242

3343
expect(result).not.to.be.undefined;
34-
expect(result.id).to.eq(146);
44+
expect(result.id).to.eq(variantAnalysisId);
3545
});
3646
});
3747

3848
describe('getVariantAnalysis', () => {
3949
it('returns the variant analysis', async () => {
4050
await mockServer.loadScenario('problem-query-success');
4151

42-
const result = await getVariantAnalysis(mockCredentials, 557804416, 146);
52+
const result = await getVariantAnalysis(mockCredentials, controllerRepoId, variantAnalysisId);
4353

4454
expect(result).not.to.be.undefined;
4555
expect(result.status).not.to.be.undefined;
@@ -50,22 +60,22 @@ describe('getVariantAnalysisRepo', () => {
5060
it('returns the variant analysis repo task', async () => {
5161
await mockServer.loadScenario('problem-query-success');
5262

53-
const result = await getVariantAnalysisRepo(mockCredentials, 557804416, 146, 206444);
63+
const result = await getVariantAnalysisRepo(mockCredentials, controllerRepoId, variantAnalysisId, repoTaskId);
5464

5565
expect(result).not.to.be.undefined;
56-
expect(result.repository.id).to.eq(206444);
66+
expect(result.repository.id).to.eq(repoTaskId);
5767
});
5868
});
5969

6070
describe('getVariantAnalysisRepoResult', () => {
6171
it('returns the variant analysis repo result', async () => {
6272
await mockServer.loadScenario('problem-query-success');
6373

64-
const result = await getVariantAnalysisRepoResult(mockCredentials, 'https://objects-origin.githubusercontent.com/codeql-query-console/codeql-variant-analysis-repo-tasks/146/206444/f6752c5c-ad60-46ba-b8dc-977546108458');
74+
const result = await getVariantAnalysisRepoResult(mockCredentials, `https://objects-origin.githubusercontent.com/codeql-query-console/codeql-variant-analysis-repo-tasks/${variantAnalysisId}/${repoTaskId}/${faker.datatype.uuid()}`);
6575

6676
expect(result).not.to.be.undefined;
6777
expect(result).to.be.an('ArrayBuffer');
68-
expect(result.byteLength).to.eq(81841);
78+
expect(result.byteLength).to.eq(variantAnalysisRepoJson.response.body.artifact_size_in_bytes);
6979
});
7080
});
7181

@@ -76,6 +86,6 @@ describe('getRepositoryFromNwo', () => {
7686
const result = await getRepositoryFromNwo(mockCredentials, 'github', 'mrva-demo-controller-repo');
7787

7888
expect(result).not.to.be.undefined;
79-
expect(result.id).to.eq(557804416);
89+
expect(result.id).to.eq(getRepoJson.response.body.id);
8090
});
8191
});

0 commit comments

Comments
 (0)