transaction.test.js
1.21 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
'use strict';
/* jshint -W030 */
var chai = require('chai')
, expect = chai.expect
, sinon = require('sinon')
, Support = require(__dirname + '/support')
, Sequelize = Support.Sequelize
, dialect = Support.getTestDialect()
, current = Support.sequelize
, Promise = Sequelize.Promise;
describe('Transaction', function() {
before(function () {
this.stub = sinon.stub(current, 'query').returns(Promise.resolve({}));
this.stubConnection = sinon.stub(current.connectionManager, 'getConnection')
.returns(Promise.resolve({ uuid: 'ssfdjd-434fd-43dfg23-2d', close : function() { }}));
});
beforeEach(function () {
this.stub.reset();
this.stubConnection.reset();
});
after(function () {
this.stub.restore();
this.stubConnection.restore();
});
it('should run auto commit query only when needed', function() {
var 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 Promise.resolve();
});
});
});