forked from sqlpad/sqlpad
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidate-connection.js
More file actions
68 lines (62 loc) · 2.1 KB
/
validate-connection.js
File metadata and controls
68 lines (62 loc) · 2.1 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
const assert = require('assert');
const validateConnection = require('../../lib/validate-connection');
describe('drivers', function () {
it('validateConnection() for old', function () {
const validPostgres = validateConnection({
name: 'testname',
driver: 'postgres',
host: 'host',
port: 'port',
postgresSsl: true,
somethingStripped: 'shouldnotmakeit',
});
assert.equal(Object.keys(validPostgres).length, 3, 'only 3 keys valid');
assert.equal(validPostgres.name, 'testname');
assert.equal(validPostgres.driver, 'postgres');
assert.equal(validPostgres.data.host, 'host');
assert.equal(validPostgres.data.port, 'port');
assert.equal(validPostgres.data.postgresSsl, true);
});
it('validateConnection() for current', function () {
const validPostgres = validateConnection({
name: 'testname',
driver: 'postgres',
data: {
host: 'host',
port: 'port',
postgresSsl: true,
somethingStripped: 'shouldnotmakeit',
},
});
assert.equal(Object.keys(validPostgres).length, 3, 'only 3 keys valid');
assert.equal(validPostgres.name, 'testname');
assert.equal(validPostgres.driver, 'postgres');
assert.equal(validPostgres.data.host, 'host');
assert.equal(validPostgres.data.port, 'port');
assert.equal(validPostgres.data.postgresSsl, true);
});
it('invalid bool throws', function () {
assert.throws(() => {
validateConnection({
name: 'name',
driver: 'postgres',
postgresSsl: 'notboolean',
});
}, 'boolean not convertable throws error');
});
it('missing driver throws', function () {
assert.throws(() => {
validateConnection({ name: 'name' });
}, 'missing driver throws error');
});
it('missing name throws', function () {
assert.throws(() => {
validateConnection({ driver: 'postgres' });
}, 'missing name throws error');
});
it('missing driver imp throws', function () {
assert.throws(() => {
validateConnection({ name: 'name', driver: 'not exist' });
}, 'missing driver imp throws error');
});
});