configuration.test.js
3.29 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
'use strict';
const chai = require('chai'),
expect = chai.expect,
Support = require(__dirname + '/support'),
Sequelize = Support.Sequelize,
dialect = Support.getTestDialect();
describe('Sequelize', () => {
describe('dialect is required', () => {
it('throw error when no dialect is supplied', () => {
expect(() => {
new Sequelize('localhost', 'test', 'test');
}).to.throw(Error);
});
it('works when dialect explicitly supplied', () => {
expect(() => {
new Sequelize('localhost', 'test', 'test', {
dialect: 'mysql'
});
}).not.to.throw(Error);
});
});
it('should throw error if pool:false', () => {
expect(() => {
new Sequelize('localhost', 'test', 'test', {
dialect: 'mysql',
pool: false
});
}).to.throw('Support for pool:false was removed in v4.0');
});
describe('Instantiation with arguments', () => {
it('should accept four parameters (database, username, password, options)', () => {
const sequelize = new Sequelize('dbname', 'root', 'pass', {
port: 999,
dialect,
dialectOptions: {
supportBigNumbers: true,
bigNumberStrings: true
}
});
const config = sequelize.config;
expect(config.database).to.equal('dbname');
expect(config.username).to.equal('root');
expect(config.password).to.equal('pass');
expect(config.port).to.equal(999);
expect(sequelize.options.dialect).to.equal(dialect);
expect(config.dialectOptions.supportBigNumbers).to.be.true;
expect(config.dialectOptions.bigNumberStrings).to.be.true;
});
});
describe('Instantiation with a URL string', () => {
it('should accept username, password, host, port, and database', () => {
const sequelize = new Sequelize('mysql://user:pass@example.com:9821/dbname');
const config = sequelize.config;
const options = sequelize.options;
expect(options.dialect).to.equal('mysql');
expect(config.database).to.equal('dbname');
expect(config.host).to.equal('example.com');
expect(config.username).to.equal('user');
expect(config.password).to.equal('pass');
expect(config.port).to.equal('9821');
});
it('should work with no authentication options', () => {
const sequelize = new Sequelize('mysql://example.com:9821/dbname');
const config = sequelize.config;
expect(config.username).to.not.be.ok;
expect(config.password).to.be.null;
});
it('should work with no authentication options and passing additional options', () => {
const sequelize = new Sequelize('mysql://example.com:9821/dbname', {});
const config = sequelize.config;
expect(config.username).to.not.be.ok;
expect(config.password).to.be.null;
});
it('should use the default port when no other is specified', () => {
const sequelize = new Sequelize('dbname', 'root', 'pass', {
dialect
}),
config = sequelize.config;
let port;
if (dialect === 'mysql') {
port = 3306;
} else if (dialect === 'postgres' || dialect === 'postgres-native') {
port = 5432;
} else {
// sqlite has no concept of ports when connecting
return;
}
expect(config.port).to.equal(port);
});
});
});