Skip to content

Commit c0e3988

Browse files
committed
Add unit tests for remote queries in logs
Also, change text slightly.
1 parent 37de2e7 commit c0e3988

2 files changed

Lines changed: 112 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,18 +337,22 @@ async function runRemoteQueriesApiRequest(
337337
}
338338
}
339339

340-
function parseResponse(owner: string, repo: string, response: QueriesResponse) {
341-
const popupMessage = `Successfully scheduled runs. [Click here to see the progress](https://github.com/${owner}/${repo}/actions/runs/${response.workflowRunId}).`
340+
// exported for testng only
341+
export function parseResponse(owner: string, repo: string, response: QueriesResponse) {
342+
const popupMessage = `Successfully scheduled runs. [Click here to see the progress](https://github.com/${owner}/${repo}/actions/runs/${response.workflow_run_id}).`
342343
+ (response.errors ? '\n\nSome repositories could not be scheduled. See extension log for details.' : '');
343344

344345
let logMessage = `Successfully scheduled runs. See https://github.com/${owner}/${repo}/actions/runs/${response.workflow_run_id}.`;
346+
if (response.repositories_queried) {
347+
logMessage += `\n\nRepositories queried:\n${response.repositories_queried.join(', ')}`;
348+
}
345349
if (response.errors) {
346-
logMessage += '\nSome repositories could not be scheduled.';
350+
logMessage += '\n\nSome repositories could not be scheduled.';
347351
if (response.errors.invalid_repositories?.length) {
348-
logMessage += `\nInvalid repositories: ${response.errors.invalid_repositories.join(', ')}`;
352+
logMessage += `\n\nInvalid repositories:\n${response.errors.invalid_repositories.join(', ')}`;
349353
}
350354
if (response.errors.repositories_without_database?.length) {
351-
logMessage += `\nRepositories without databases: ${response.errors.repositories_without_database.join(', ')}`;
355+
logMessage += `\n\nRepositories without databases:\n${response.errors.repositories_without_database.join(', ')}`;
352356
}
353357
}
354358

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
import { expect } from 'chai';
2+
import { parseResponse } from '../../../remote-queries/run-remote-query';
3+
4+
describe('run-remote-queries', () => {
5+
describe('parseResponse', () => {
6+
it('should parse a successful response', () => {
7+
const result = parseResponse('org', 'name', {
8+
workflow_run_id: 123,
9+
repositories_queried: ['a/b', 'c/d'],
10+
});
11+
12+
expect(result.popupMessage).to.equal('Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).');
13+
expect(result.logMessage).to.equal(
14+
['Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.',
15+
'',
16+
'Repositories queried:',
17+
'a/b, c/d'].join('\n')
18+
);
19+
});
20+
21+
it('should parse a response with invalid repos', () => {
22+
const result = parseResponse('org', 'name', {
23+
workflow_run_id: 123,
24+
repositories_queried: ['a/b', 'c/d'],
25+
errors: {
26+
invalid_repositories: ['e/f', 'g/h'],
27+
}
28+
});
29+
30+
expect(result.popupMessage).to.equal(
31+
['Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).',
32+
'',
33+
'Some repositories could not be scheduled. See extension log for details.'].join('\n')
34+
);
35+
expect(result.logMessage).to.equal(
36+
['Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.',
37+
'',
38+
'Repositories queried:',
39+
'a/b, c/d',
40+
'',
41+
'Some repositories could not be scheduled.',
42+
'',
43+
'Invalid repositories:',
44+
'e/f, g/h'].join('\n')
45+
);
46+
});
47+
48+
it('should parse a response with repos w/o databases', () => {
49+
const result = parseResponse('org', 'name', {
50+
workflow_run_id: 123,
51+
repositories_queried: ['a/b', 'c/d'],
52+
errors: {
53+
repositories_without_database: ['e/f', 'g/h'],
54+
}
55+
});
56+
57+
expect(result.popupMessage).to.equal(
58+
['Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).',
59+
'',
60+
'Some repositories could not be scheduled. See extension log for details.'].join('\n')
61+
);
62+
expect(result.logMessage).to.equal(
63+
['Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.',
64+
'',
65+
'Repositories queried:\na/b, c/d',
66+
'',
67+
'Some repositories could not be scheduled.',
68+
'',
69+
'Repositories without databases:\ne/f, g/h'].join('\n')
70+
);
71+
});
72+
73+
it('should parse a response with invalid repos and repos w/o databases', () => {
74+
const result = parseResponse('org', 'name', {
75+
workflow_run_id: 123,
76+
repositories_queried: ['a/b', 'c/d'],
77+
errors: {
78+
invalid_repositories: ['e/f', 'g/h'],
79+
repositories_without_database: ['i/j', 'k/l'],
80+
}
81+
});
82+
83+
expect(result.popupMessage).to.equal(
84+
['Successfully scheduled runs. [Click here to see the progress](https://github.com/org/name/actions/runs/123).',
85+
'',
86+
'Some repositories could not be scheduled. See extension log for details.'].join('\n')
87+
);
88+
expect(result.logMessage).to.equal(
89+
['Successfully scheduled runs. See https://github.com/org/name/actions/runs/123.',
90+
'',
91+
'Repositories queried:\na/b, c/d',
92+
'',
93+
'Some repositories could not be scheduled.',
94+
'',
95+
'Invalid repositories:',
96+
'e/f, g/h',
97+
'',
98+
'Repositories without databases:',
99+
'i/j, k/l'].join('\n')
100+
);
101+
});
102+
});
103+
});

0 commit comments

Comments
 (0)