buster-helpers.js
1.46 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
const Sequelize = require(__dirname + "/../index")
, DataTypes = require(__dirname + "/../lib/data-types")
, config = require(__dirname + "/config/config")
, fs = require('fs')
var BusterHelpers = module.exports = {
initTests: function(options) {
var sequelize = this.createSequelizeInstance(options)
this.clearDatabase(sequelize, function() {
options.beforeComplete && options.beforeComplete(sequelize, DataTypes)
options.onComplete && options.onComplete(sequelize, DataTypes)
})
},
createSequelizeInstance: function(options) {
options = options || {}
options.dialect = options.dialect || 'mysql'
options.logging = (options.hasOwnProperty('logging') ? options.logging : false)
return new Sequelize(
config[options.dialect].database,
config[options.dialect].username,
config[options.dialect].password,
{
logging: options.logging,
dialect: options.dialect,
port: config[options.dialect].port
}
)
},
clearDatabase: function(sequelize, callback) {
sequelize
.getQueryInterface()
.dropAllTables()
.success(function() {
sequelize.daoFactoryManager.daos = []
callback && callback()
})
.error(function(err) { console.log(err) })
},
getSupportedDialects: function() {
return fs.readdirSync(__dirname + '/../lib/dialects').filter(function(file) {
return (file.indexOf('.js') === -1)
})
}
}