paranoid.test.js
2.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
'use strict';
var chai = require('chai')
, expect = chai.expect
, Support = require(__dirname + '/../support')
, DataTypes = require(__dirname + '/../../lib/data-types')
, datetime = require('chai-datetime');
chai.use(datetime);
chai.config.includeStack = true;
describe(Support.getTestDialectTeaser('Paranoid'), function() {
beforeEach(function(done ) {
var S = this.sequelize,
DT = DataTypes,
A = this.A = S.define('A', { name: DT.STRING }, { paranoid: true }),
B = this.B = S.define('B', { name: DT.STRING }, { paranoid: true }),
C = this.C = S.define('C', { name: DT.STRING }, { paranoid: true }),
D = this.D = S.define('D', { name: DT.STRING }, { paranoid: true });
A.belongsTo(B);
A.hasMany(D);
A.hasMany(C);
B.hasMany(A);
B.hasMany(C);
C.belongsTo(A);
C.belongsTo(B);
D.hasMany(A);
S.sync({ force: true }).done(function(err ) {
expect(err).not.to.be.ok;
done();
});
});
it('paranoid with timestamps: false should be ignored / not crash', function(done) {
var S = this.sequelize,
Test = S.define('Test', {
name: DataTypes.STRING
},{
timestamps: false,
paranoid: true
});
S.sync({ force: true }).done(function() {
Test.find(1).done(function(err ) {
expect(err).to.be.not.ok;
done();
});
});
});
it('test if non required is marked as false', function(done ) {
var A = this.A,
B = this.B,
options = {
include: [
{
model: B,
required: false
}
]
};
A.find(options).done(function(err ) {
expect(err).not.to.be.ok;
expect(options.include[0].required).to.be.equal(false);
done();
});
});
it('test if required is marked as true', function(done ) {
var A = this.A,
B = this.B,
options = {
include: [
{
model: B,
required: true
}
]
};
A.find(options).done(function(err ) {
expect(err).not.to.be.ok;
expect(options.include[0].required).to.be.equal(true);
done();
});
});
});