forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery-result.js
More file actions
70 lines (61 loc) · 2.12 KB
/
Copy pathquery-result.js
File metadata and controls
70 lines (61 loc) · 2.12 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
const assert = require('assert');
const utils = require('../utils');
const queryText = `
-- dimensions = department 10, orderdate 10
-- measures = cost, revenue, profit
-- orderby = department desc, orderdate asc
-- limit = 100
`;
function validateQueryResult(queryResult) {
assert(queryResult.id, 'id');
assert(queryResult.cacheKey, 'cacheKey');
assert(queryResult.startTime, 'startTime');
assert(queryResult.stopTime, 'stopTime');
assert(queryResult.queryRunTime >= 0, 'queryRunTime');
assert(Array.isArray(queryResult.fields), 'fields');
assert.equal(queryResult.fields.length, 5, 'fields length');
assert.equal(queryResult.fields[0], 'department', 'field department');
assert.equal(queryResult.incomplete, false, 'incomplete');
assert(queryResult.meta, 'meta');
assert(queryResult.meta.department, 'meta.department');
assert(Array.isArray(queryResult.rows), 'rows is array');
assert.equal(queryResult.rows.length, 100, 'rows length');
}
describe('api/query-result', function() {
let query;
let connection;
before(async function() {
await utils.resetWithUser();
const connBody = await utils.post('admin', '/api/connections', {
name: 'test postgres',
driver: 'mock',
host: 'localhost',
database: 'sqlpad',
username: 'sqlpad',
password: 'sqlpad'
});
connection = connBody.connection;
const queryBody = await utils.post('admin', '/api/queries', {
name: 'test query',
tags: ['test', 'postgres'],
connectionId: connection._id,
queryText
});
query = queryBody.query;
});
it('GET /api/query-result/:queryId', async function() {
const body = await utils.get('admin', `/api/query-result/${query._id}`);
assert(!body.error, 'Expect no error');
validateQueryResult(body.queryResult);
});
it('POST /api/query-result', async function() {
const body = await utils.post('admin', `/api/query-result`, {
connectionId: connection._id,
cacheKey: 'cachekey',
queryName: 'test query',
queryText
});
assert(!body.error, 'Expect no error');
validateQueryResult(body.queryResult);
});
});