connection-manager.test.js
2.97 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
'use strict';
const chai = require('chai'),
expect = chai.expect,
Sequelize = require('../../../../index'),
Support = require('../../support'),
dialect = Support.getTestDialect(),
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.Connection = {};
const self = this;
this.connectionStub = sinon.stub(this.instance.connectionManager, 'lib').value({
Connection: function FakeConnection() {
return self.Connection;
}
});
});
afterEach(function() {
this.connectionStub.restore();
});
it('connectionManager._connect() does not delete `domain` from config.dialectOptions', async function() {
this.Connection = {
STATE: {},
state: '',
once(event, cb) {
if (event === 'connect') {
setTimeout(() => {
cb();
}, 500);
}
},
removeListener: () => {},
on: () => {}
};
expect(this.config.dialectOptions.domain).to.equal('TEST.COM');
await this.instance.dialect.connectionManager._connect(this.config);
expect(this.config.dialectOptions.domain).to.equal('TEST.COM');
});
it('connectionManager._connect() should reject if end was called and connect was not', async function() {
this.Connection = {
STATE: {},
state: '',
once(event, cb) {
if (event === 'end') {
setTimeout(() => {
cb();
}, 500);
}
},
removeListener: () => {},
on: () => {}
};
try {
await this.instance.dialect.connectionManager._connect(this.config);
} catch (err) {
expect(err.name).to.equal('SequelizeConnectionError');
expect(err.parent.message).to.equal('Connection was closed by remote server');
}
});
it('connectionManager._connect() should call connect if state is initialized', async function() {
const connectStub = sinon.stub();
const INITIALIZED = { name: 'INITIALIZED' };
this.Connection = {
STATE: { INITIALIZED },
state: INITIALIZED,
connect: connectStub,
once(event, cb) {
if (event === 'connect') {
setTimeout(() => {
cb();
}, 500);
}
},
removeListener: () => {},
on: () => {}
};
await this.instance.dialect.connectionManager._connect(this.config);
expect(connectStub.called).to.equal(true);
});
});
}