Skip to content

Commit ab441ef

Browse files
committed
Tests for "getRepositories"
1 parent b4478e9 commit ab441ef

File tree

2 files changed

+78
-1
lines changed

2 files changed

+78
-1
lines changed

extensions/ql-vscode/src/run-remote-query.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ interface RepoListQuickPickItem extends QuickPickItem {
2323
/**
2424
* Gets the repositories to run the query against.
2525
*/
26-
async function getRepositories(): Promise<string[] | undefined> {
26+
export async function getRepositories(): Promise<string[] | undefined> {
2727
const repoLists = getRemoteRepositoryLists();
2828
if (repoLists && Object.keys(repoLists).length) {
2929
const quickPickItems = Object.entries(repoLists).map<RepoListQuickPickItem>(([key, value]) => (
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import 'vscode-test';
2+
import 'mocha';
3+
import * as chaiAsPromised from 'chai-as-promised';
4+
import * as sinon from 'sinon';
5+
import * as chai from 'chai';
6+
import { window } from 'vscode';
7+
import * as pq from 'proxyquire';
8+
9+
const proxyquire = pq.noPreserveCache();
10+
chai.use(chaiAsPromised);
11+
const expect = chai.expect;
12+
13+
describe('run-remote-query', function() {
14+
15+
describe('getRepositories', () => {
16+
let sandbox: sinon.SinonSandbox;
17+
let quickPickSpy: sinon.SinonStub;
18+
let showInputBoxSpy: sinon.SinonStub;
19+
let getRemoteRepositoryListsSpy: sinon.SinonStub;
20+
let mod: any;
21+
beforeEach(() => {
22+
sandbox = sinon.createSandbox();
23+
quickPickSpy = sandbox.stub(window, 'showQuickPick');
24+
showInputBoxSpy = sandbox.stub(window, 'showInputBox');
25+
getRemoteRepositoryListsSpy = sandbox.stub();
26+
mod = proxyquire('../../run-remote-query', {
27+
'./config': {
28+
getRemoteRepositoryLists: getRemoteRepositoryListsSpy
29+
}
30+
});
31+
32+
});
33+
34+
afterEach(() => {
35+
sandbox.restore();
36+
});
37+
38+
it('should return a repo list that you chose from your pre-defined config', async () => {
39+
// fake return values
40+
quickPickSpy.resolves(
41+
{ repoList: ['foo/bar', 'foo/baz'] }
42+
);
43+
getRemoteRepositoryListsSpy.returns(
44+
{
45+
'list1': ['foo/bar', 'foo/baz'],
46+
'list2': [],
47+
}
48+
);
49+
50+
// make the function call
51+
const repoList = await mod.getRepositories();
52+
53+
// Check that the return value is correct
54+
expect(repoList).to.deep.eq(
55+
['foo/bar', 'foo/baz']
56+
);
57+
});
58+
59+
it('should show a textbox if you have no repo lists configured', async () => {
60+
// fake return values
61+
showInputBoxSpy.resolves('foo/bar');
62+
getRemoteRepositoryListsSpy.returns({});
63+
64+
// make the function call
65+
const repoList = await mod.getRepositories();
66+
67+
// Check that the return value is correct
68+
expect(repoList).to.deep.equal(
69+
['foo/bar']
70+
);
71+
});
72+
});
73+
74+
describe('runRemoteQuery', () => {
75+
// TODO
76+
});
77+
});

0 commit comments

Comments
 (0)