transaction.test.js
2.07 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
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, Transaction = require(__dirname + '/../lib/transaction')
describe(Support.getTestDialectTeaser("Transaction"), function () {
this.timeout(4000);
describe('constructor', function() {
it('stores options', function() {
var transaction = new Transaction(this.sequelize)
expect(transaction.options).to.be.an.instanceOf(Object)
})
it('generates an identifier', function() {
var transaction = new Transaction(this.sequelize)
expect(transaction.id).to.exist
})
})
describe('success', function() {
it("is a success method available", function() {
expect(Transaction).to.respondTo("success")
})
})
describe('error', function() {
it("is an error method available", function() {
expect(Transaction).to.respondTo("error")
})
})
describe('commit', function() {
it('is a commit method available', function() {
expect(Transaction).to.respondTo('commit')
})
})
describe('rollback', function() {
it('is a rollback method available', function() {
expect(Transaction).to.respondTo('rollback')
})
})
describe('done', function() {
it('gets called when the transaction gets commited', function(done) {
var transaction = new Transaction(this.sequelize)
transaction.done(done)
transaction.prepareEnvironment(function() {
transaction.commit()
})
})
it('works for long running transactions', function(done) {
var transaction = new Transaction(this.sequelize)
, self = this
transaction.done(done)
transaction.prepareEnvironment(function() {
setTimeout(function() {
self.sequelize.query('select 1+1 as sum', null, {
raw: true,
plain: true,
transaction: transaction
}).done(function(err, result) {
expect(err).to.be.null
expect(result.sum).to.equal(2)
transaction.commit()
})
}, 2000)
})
})
})
})