dao-factory.spec.js
1.9 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
if(typeof require === 'function') {
const buster = require("buster")
, Sequelize = require("../index")
, config = require("./config/config")
, dialects = ['sqlite', 'mysql', 'postgres']
}
buster.spec.expose()
dialects.forEach(function(dialect) {
describe('DAO@' + dialect, function() {
before(function(done) {
var self = this
this.sequelize = new Sequelize(config.database, config.username, config.password, {
logging: false
})
this.User = this.sequelize.define('User', {
username: { type: Sequelize.STRING },
secretValue: Sequelize.STRING
})
self.sequelize
.getQueryInterface()
.dropAllTables()
.success(function() {
self.User
.sync({ force: true })
.success(done)
.error(function(err) {
console.log(err)
})
})
.error(function(err) { console.log(err) })
})
describe('create with whitelist', function() {
var data = {
username: 'Peter',
secretValue: '42'
}
it('should only store the values passed in the witelist', function(done) {
var self = this;
this.User.create(data, ['username']).success(function(user) {
self.User.find(user.id).success(function(_user) {
expect(_user.username).toEqual(data.username);
expect(_user.secretValue).not.toEqual(data.secretValue);
done();
})
})
})
it('should store all values if no whitelist is specified', function(done) {
var self = this;
this.User.create(data).success(function(user) {
self.User.find(user.id).success(function(_user) {
expect(_user.username).toEqual(data.username);
expect(_user.secretValue).toEqual(data.secretValue);
done();
})
})
})
})
})
})