connection-manager.test.js
1.98 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
'use strict';
const chai = require('chai'),
expect = chai.expect,
Sequelize = require(__dirname + '/../../../../index'),
Support = require(__dirname + '/../../support'),
dialect = Support.getTestDialect(),
tedious = require('tedious'),
sinon = require('sinon');
if (dialect === 'mssql') {
describe('[MSSQL Specific] Connection Manager', () => {
beforeEach(function() {
this.config = {
dialect: 'mssql',
database: 'none',
username: 'none',
password: 'none',
host: 'localhost',
port: 2433,
pool: {},
dialectOptions: {
domain: 'TEST.COM'
}
};
this.instance = new Sequelize(
this.config.database,
this.config.username,
this.config.password,
this.config
);
this.connectionStub = sinon.stub(tedious, 'Connection');
});
afterEach(function() {
this.connectionStub.restore();
});
it('connectionManager._connect() does not delete `domain` from config.dialectOptions', function() {
this.connectionStub.returns({on(event, cb) {
if (event === 'connect') {
setTimeout(() => {
cb();
}, 500);
}
}});
expect(this.config.dialectOptions.domain).to.equal('TEST.COM');
return this.instance.dialect.connectionManager._connect(this.config).then(() => {
expect(this.config.dialectOptions.domain).to.equal('TEST.COM');
});
});
it('connectionManager._connect() should reject if end was called and connect was not', function() {
this.connectionStub.returns({ on(event, cb) {
if (event === 'end') {
setTimeout(() => {
cb();
}, 500);
}
} });
return this.instance.dialect.connectionManager._connect(this.config)
.catch(err => {
expect(err.name).to.equal('SequelizeConnectionError');
expect(err.parent).to.equal('Connection was closed by remote server');
});
});
});
}