sequelize.transaction.test.js
1.91 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
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/support')
, Transaction = require(__dirname + '/../lib/transaction')
describe(Support.getTestDialectTeaser("Sequelize#transaction"), function () {
describe('success', function() {
it("gets triggered once a transaction has been successfully committed", function(done) {
this
.sequelize
.transaction(function(t) { t.commit() })
.success(function() { done() })
})
it("gets triggered once a transaction has been successfully rollbacked", function(done) {
this
.sequelize
.transaction(function(t) { t.rollback() })
.success(function() { done() })
})
})
describe('error', function() {
if (Support.getTestDialect() === 'sqlite') {
// not sure if we can test this in sqlite ...
// how could we enforce an authentication error in sqlite?
} else {
it("gets triggered once an error occurs", function(done) {
var sequelize = Support.createSequelizeInstance({ dialect: Support.getTestDialect() })
// lets overwrite the host to get an error
sequelize.config.username = 'foobarbaz'
sequelize
.transaction(function() {})
.error(function(err) {
expect(err).to.not.be.undefined
done()
})
})
}
})
describe('callback', function() {
it("receives the transaction if only one argument is passed", function(done) {
this.sequelize.transaction(function(t) {
expect(t).to.be.instanceOf(Transaction)
t.commit()
}).done(done)
})
it("receives an error and the transaction if two arguments are passed", function(done) {
this.sequelize.transaction(function(err, t) {
expect(err).to.not.be.instanceOf(Transaction)
expect(t).to.be.instanceOf(Transaction)
t.commit()
}).done(done)
})
})
})