transaction.test.js
1.36 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
'use strict';
const chai = require('chai');
const expect = chai.expect;
const sinon = require('sinon');
const Support = require(__dirname + '/support');
const Sequelize = Support.Sequelize;
const dialect = Support.getTestDialect();
const current = Support.sequelize;
describe('Transaction', function() {
before(() => {
this.stub = sinon.stub(current, 'query').returns(Sequelize.Promise.resolve({}));
this.stubConnection = sinon.stub(current.connectionManager, 'getConnection')
.returns(Sequelize.Promise.resolve({
uuid: 'ssfdjd-434fd-43dfg23-2d',
close(){}
}));
this.stubRelease = sinon.stub(current.connectionManager, 'releaseConnection')
.returns(Sequelize.Promise.resolve());
});
beforeEach(() => {
this.stub.reset();
this.stubConnection.reset();
this.stubRelease.reset();
});
after(() => {
this.stub.restore();
this.stubConnection.restore();
});
it('should run auto commit query only when needed', () => {
const expectations = {
all: [
'START TRANSACTION;'
],
sqlite: [
'BEGIN DEFERRED TRANSACTION;'
],
mssql: [
'BEGIN TRANSACTION;'
]
};
return current.transaction(() => {
expect(this.stub.args.map(arg => arg[0])).to.deep.equal(expectations[dialect] || expectations.all);
return Sequelize.Promise.resolve();
});
});
});