apemandb
Version:
Database for apeman project.
95 lines (81 loc) • 2.33 kB
JavaScript
/**
* Test case for apemandb.
* Runs with mocha.
*/
const Apemandb = require('../lib/apemandb.js')
const fs = require('fs')
const co = require('co')
const asleep = require('asleep')
const assert = require('assert')
const Sequelize = require('sequelize')
describe('apemandb', function () {
this.timeout(9000)
let tmpDir = `${__dirname}/../tmp`
let dbFile = tmpDir + '/testing-db.db'
before(() => co(function * () {
}))
after(() => co(function * () {
if (fs.existsSync(dbFile)) {
fs.unlinkSync(dbFile)
}
yield asleep(100) // Wait for flush.
}))
it('SQLite', () => co(function * () {
let db = new Apemandb('testing-database01', 'foo', 'bar', {
dialect: 'sqlite',
storage: dbFile
})
assert.ok(db)
let User = db.define('user', {
firstName: {
type: Sequelize.STRING,
field: 'first_name' // Will result in an attribute that is firstName when user facing but first_name in the database
},
lastName: {
type: 'STRING(1024)'
}
}, {})
assert.doesNotThrow(() => {
assert.ok(db.model('User'))
})
assert.throws(() => {
db.model('__invalid_model_name__')
})
yield User.sync({ force: true })
// Table created
yield User.create({
firstName: 'John',
lastName: 'Hancock'
})
yield db.reset()
assert.ok(db)
}))
it('MySQL', () => co(function * () {
let db = new Apemandb('apemandb_test', 'apemandb-test', 'apemandb-test', {
dialect: 'mysql',
port: 3306,
host: 'localhost'
})
yield db.setup()
let User = db.define('user', {
firstName: {
type: Sequelize.STRING,
field: 'first_name' // Will result in an attribute that is firstName when user facing but first_name in the database
},
lastName: {
type: 'VARCHAR(255)'
}
}, {})
yield db.sync()
yield User.sync()
yield db.drop()
}))
it('Test other', () => co(function * () {
let { modelNameForFile } = require('../lib/seeding/from_files')
assert.equal(modelNameForFile('foo/bar/hoge_seed.js'), 'Hoge')
assert.equal(modelNameForFile('foo/bar/hoge.seed.js'), 'Hoge')
assert.equal(modelNameForFile('foo/bar/Seed.seed.js'), 'Seed')
}))
})
/* global describe, before, after, it */