connection-manager.test.js
1.9 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
'use strict';
/* jshint -W030 */
var chai = require('chai')
, sinon = require('sinon')
, expect = chai.expect
, Support = require(__dirname + '/support')
, Sequelize = require(__dirname + '/../../index')
, ConnectionManager = require(__dirname + '/../../lib/dialects/abstract/connection-manager')
, Promise = Sequelize.Promise;
describe('connection manager', function () {
describe('_connect', function () {
beforeEach(function () {
this.sinon = sinon.sandbox.create();
this.dialect = {
connectionManager: {
connect: this.sinon.stub().returns(Promise.resolve())
}
};
this.sequelize = Support.createSequelizeInstance();
});
afterEach(function () {
this.sinon.restore();
});
it('should resolve connection on dialect connection manager', function () {
var connection = {};
this.dialect.connectionManager.connect.returns(Promise.resolve(connection));
var connectionManager = new ConnectionManager(this.dialect, this.sequelize);
var config = {};
return expect(connectionManager._connect(config)).to.eventually.equal(connection).then(function () {
expect(this.dialect.connectionManager.connect).to.have.been.calledWith(config);
}.bind(this));
});
it('should let beforeConnect hook modify config', function () {
var username = Math.random().toString()
, password = Math.random().toString();
this.sequelize.beforeConnect(function (config) {
config.username = username;
config.password = password;
return config;
});
var connectionManager = new ConnectionManager(this.dialect, this.sequelize);
return connectionManager._connect({}).then(function () {
expect(this.dialect.connectionManager.connect).to.have.been.calledWith({
username: username,
password: password
});
}.bind(this));
});
});
});