|
| 1 | +import { expect } from 'chai'; |
| 2 | +import * as path from 'path'; |
| 3 | + |
| 4 | +import * as Octokit from '@octokit/rest'; |
| 5 | +import { retry } from '@octokit/plugin-retry'; |
| 6 | + |
| 7 | +import { setupServer } from 'msw/node'; |
| 8 | + |
| 9 | +import { |
| 10 | + getRepositoryFromNwo, |
| 11 | + getVariantAnalysis, |
| 12 | + getVariantAnalysisRepo, getVariantAnalysisRepoResult, |
| 13 | + submitVariantAnalysis |
| 14 | +} from '../../../../src/remote-queries/gh-api/gh-api-client'; |
| 15 | +import { Credentials } from '../../../../src/authentication'; |
| 16 | +import { |
| 17 | + createMockSubmission |
| 18 | +} from '../../../../src/vscode-tests/factories/remote-queries/shared/variant-analysis-submission'; |
| 19 | +import { createRequestHandlers } from '../../../../src/mocks/request-handlers'; |
| 20 | + |
| 21 | +const mockCredentials = { |
| 22 | + getOctokit: () => Promise.resolve(new Octokit.Octokit({ retry })) |
| 23 | +} as unknown as Credentials; |
| 24 | + |
| 25 | +const server = setupServer(); |
| 26 | + |
| 27 | +before(() => server.listen()); |
| 28 | + |
| 29 | +afterEach(() => server.resetHandlers()); |
| 30 | + |
| 31 | +after(() => server.close()); |
| 32 | + |
| 33 | +async function loadScenario(scenarioName: string) { |
| 34 | + const handlers = await createRequestHandlers(path.join(__dirname, '../../../../src/mocks/scenarios', scenarioName)); |
| 35 | + |
| 36 | + server.use(...handlers); |
| 37 | +} |
| 38 | + |
| 39 | +describe('submitVariantAnalysis', () => { |
| 40 | + it('returns the submitted variant analysis', async () => { |
| 41 | + await loadScenario('problem-query-success'); |
| 42 | + |
| 43 | + const result = await submitVariantAnalysis(mockCredentials, createMockSubmission()); |
| 44 | + |
| 45 | + expect(result).not.to.be.undefined; |
| 46 | + expect(result.id).to.eq(146); |
| 47 | + }); |
| 48 | +}); |
| 49 | + |
| 50 | +describe('getVariantAnalysis', () => { |
| 51 | + it('returns the variant analysis', async () => { |
| 52 | + await loadScenario('problem-query-success'); |
| 53 | + |
| 54 | + const result = await getVariantAnalysis(mockCredentials, 557804416, 146); |
| 55 | + |
| 56 | + expect(result).not.to.be.undefined; |
| 57 | + expect(result.status).not.to.be.undefined; |
| 58 | + }); |
| 59 | +}); |
| 60 | + |
| 61 | +describe('getVariantAnalysisRepo', () => { |
| 62 | + it('returns the variant analysis repo task', async () => { |
| 63 | + await loadScenario('problem-query-success'); |
| 64 | + |
| 65 | + const result = await getVariantAnalysisRepo(mockCredentials, 557804416, 146, 206444); |
| 66 | + |
| 67 | + expect(result).not.to.be.undefined; |
| 68 | + expect(result.repository.id).to.eq(206444); |
| 69 | + }); |
| 70 | +}); |
| 71 | + |
| 72 | +describe('getVariantAnalysisRepoResult', () => { |
| 73 | + it('returns the variant analysis repo result', async () => { |
| 74 | + await loadScenario('problem-query-success'); |
| 75 | + |
| 76 | + 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'); |
| 77 | + |
| 78 | + expect(result).not.to.be.undefined; |
| 79 | + expect(result).to.be.an('ArrayBuffer'); |
| 80 | + expect(result.byteLength).to.eq(81841); |
| 81 | + }); |
| 82 | +}); |
| 83 | + |
| 84 | +describe('getRepositoryFromNwo', () => { |
| 85 | + it('returns the repository', async () => { |
| 86 | + await loadScenario('problem-query-success'); |
| 87 | + |
| 88 | + const result = await getRepositoryFromNwo(mockCredentials, 'github', 'mrva-demo-controller-repo'); |
| 89 | + |
| 90 | + expect(result).not.to.be.undefined; |
| 91 | + expect(result.id).to.eq(557804416); |
| 92 | + }); |
| 93 | +}); |
0 commit comments