Skip to content

Commit b59638b

Browse files
committed
Test the regex for "getRepositories"
1 parent b0e1992 commit b59638b

File tree

1 file changed

+48
-14
lines changed

1 file changed

+48
-14
lines changed

extensions/ql-vscode/src/vscode-tests/no-workspace/run-remote-query.test.ts

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,29 @@ describe('run-remote-query', function() {
1717
let quickPickSpy: sinon.SinonStub;
1818
let showInputBoxSpy: sinon.SinonStub;
1919
let getRemoteRepositoryListsSpy: sinon.SinonStub;
20+
let showAndLogErrorMessageSpy: sinon.SinonStub;
2021
let mod: any;
2122
beforeEach(() => {
2223
sandbox = sinon.createSandbox();
2324
quickPickSpy = sandbox.stub(window, 'showQuickPick');
2425
showInputBoxSpy = sandbox.stub(window, 'showInputBox');
2526
getRemoteRepositoryListsSpy = sandbox.stub();
27+
showAndLogErrorMessageSpy = sandbox.stub();
2628
mod = proxyquire('../../run-remote-query', {
2729
'./config': {
2830
getRemoteRepositoryLists: getRemoteRepositoryListsSpy
29-
}
31+
},
32+
'./helpers': {
33+
showAndLogErrorMessage: showAndLogErrorMessageSpy
34+
},
3035
});
31-
3236
});
3337

3438
afterEach(() => {
3539
sandbox.restore();
3640
});
3741

38-
it('should return a repo list that you chose from your pre-defined config', async () => {
42+
it('should run on a repo list that you chose from your pre-defined config', async () => {
3943
// fake return values
4044
quickPickSpy.resolves(
4145
{ repoList: ['foo/bar', 'foo/baz'] }
@@ -56,19 +60,49 @@ describe('run-remote-query', function() {
5660
);
5761
});
5862

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();
63+
// Test the regex in various "good" cases
64+
const goodRepos = [
65+
'owner/repo',
66+
'owner-with-hyphens/repo-with-hyphens_and_underscores',
67+
'ownerWithNumbers58/repoWithNumbers37'
68+
];
69+
goodRepos.forEach(repo => {
70+
it(`should run on a valid repo that you enter in the text box: ${repo}`, async () => {
71+
// fake return values
72+
getRemoteRepositoryListsSpy.returns({}); // no pre-defined repo lists
73+
showInputBoxSpy.resolves(repo);
74+
75+
// make the function call
76+
const repoList = await mod.getRepositories();
77+
78+
// Check that the return value is correct
79+
expect(repoList).to.deep.equal(
80+
[repo]
81+
);
82+
});
83+
});
6684

67-
// Check that the return value is correct
68-
expect(repoList).to.deep.equal(
69-
['foo/bar']
70-
);
85+
// Test the regex in various "bad" cases
86+
const badRepos = [
87+
'invalid_owner/repo',
88+
'owner/repo+some&invalid&stuff',
89+
'owner-with-no-repo/',
90+
'/repo-with-no-owner'
91+
];
92+
badRepos.forEach(repo => {
93+
it(`should show an error message if you enter an invalid repo in the text box: ${repo}`, async () => {
94+
// fake return values
95+
getRemoteRepositoryListsSpy.returns({}); // no pre-defined repo lists
96+
showInputBoxSpy.resolves(repo);
97+
98+
// make the function call
99+
await mod.getRepositories();
100+
101+
// check that we get the right error message
102+
expect(showAndLogErrorMessageSpy.firstCall.args[0]).to.contain('Invalid repository format');
103+
});
71104
});
105+
72106
});
73107

74108
describe('validateRepositories', () => {

0 commit comments

Comments
 (0)