-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathrun-queries.test.ts
More file actions
122 lines (107 loc) · 3.5 KB
/
run-queries.test.ts
File metadata and controls
122 lines (107 loc) · 3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import * as chai from 'chai';
import * as path from 'path';
import 'mocha';
import 'sinon-chai';
import * as sinon from 'sinon';
import * as chaiAsPromised from 'chai-as-promised';
import { QueryInfo } from '../../run-queries';
import { QlProgram, Severity, compileQuery } from '../../pure/messages';
import { DatabaseItem } from '../../databases';
chai.use(chaiAsPromised);
const expect = chai.expect;
describe('run-queries', () => {
it('should create a QueryInfo', () => {
const info = createMockQueryInfo();
const queryID = info.queryID;
expect(path.basename(info.compiledQueryPath)).to.eq(`compiledQuery${queryID}.qlo`);
expect(path.basename(info.dilPath)).to.eq(`results${queryID}.dil`);
expect(path.basename(info.resultsPaths.resultsPath)).to.eq(`results${queryID}.bqrs`);
expect(path.basename(info.resultsPaths.interpretedResultsPath)).to.eq(`interpretedResults${queryID}.sarif`);
expect(info.dataset).to.eq('file:///abc');
});
it('should check if interpreted results can be created', async () => {
const info = createMockQueryInfo();
(info.dbItem.hasMetadataFile as sinon.SinonStub).returns(true);
expect(await info.canHaveInterpretedResults()).to.eq(true);
(info.dbItem.hasMetadataFile as sinon.SinonStub).returns(false);
expect(await info.canHaveInterpretedResults()).to.eq(false);
(info.dbItem.hasMetadataFile as sinon.SinonStub).returns(true);
info.metadata!.kind = undefined;
expect(await info.canHaveInterpretedResults()).to.eq(false);
info.metadata!.kind = 'table';
expect(await info.canHaveInterpretedResults()).to.eq(false);
});
describe('compile', () => {
it('should compile', async () => {
const info = createMockQueryInfo();
const qs = createMockQueryServerClient();
const mockProgress = 'progress-monitor';
const mockCancel = 'cancel-token';
const results = await info.compile(
qs as any,
mockProgress as any,
mockCancel as any
);
expect(results).to.deep.eq([
{ message: 'err', severity: Severity.ERROR }
]);
expect(qs.sendRequest).to.have.been.calledOnceWith(
compileQuery,
{
compilationOptions: {
computeNoLocationUrls: true,
failOnWarnings: false,
fastCompilation: false,
includeDilInQlo: true,
localChecking: false,
noComputeGetUrl: false,
noComputeToString: false,
computeDefaultStrings: true
},
extraOptions: {
timeoutSecs: 5
},
queryToCheck: 'my-program',
resultPath: info.compiledQueryPath,
target: { query: {} }
},
mockCancel,
mockProgress
);
});
});
function createMockQueryInfo() {
return new QueryInfo(
'my-program' as unknown as QlProgram,
{
contents: {
datasetUri: 'file:///abc'
},
hasMetadataFile: sinon.stub()
} as unknown as DatabaseItem,
'my-scheme', // queryDbscheme,
undefined,
{
kind: 'problem'
}
);
}
function createMockQueryServerClient() {
return {
config: {
timeoutSecs: 5
},
sendRequest: sinon.stub().returns(new Promise(resolve => {
resolve({
messages: [
{ message: 'err', severity: Severity.ERROR },
{ message: 'warn', severity: Severity.WARNING },
]
});
})),
logger: {
log: sinon.spy()
}
};
}
});