Setup schema and tests.

This commit is contained in:
Jonathan Cremin 2016-06-19 11:17:31 -07:00
parent 806f42e3f8
commit de0284e48a
7 changed files with 49 additions and 17 deletions

35
test/fixtures/user.js vendored
View file

@ -1,27 +1,34 @@
import co from 'co';
import models from '../../models';
function createUser() {
models.user.create({
import debugname from 'debug';
const debug = debugname('hostr:db');
function *createUser() {
const user = yield models.user.create({
'email': 'test@hostr.co',
'password': '$pbkdf2-256-1$2$kBhIDRqFwnF/1ms6ZHfME2o2$a48e8c350d26397fcc88bf0a7a2817b1cdcd1ffffe0521a5',
'ip': '127.0.0.1',
'plan': 'Free',
'activated': true,
}).then((user) => {
user.save().then(() => {
models.sequelize.close();
});
});
yield user.save();
yield models.sequelize.close();
}
models.user.findOne({
where: {
email: 'test@hostr.co',
},
}).then((user) => {
co(function *sync() {
debug('Syncing schema');
yield models.sequelize.sync();
debug('Schema synced');
const user = yield models.user.findOne({
where: {
email: 'test@hostr.co',
},
});
if (user) {
user.destroy().then(createUser);
} else {
createUser();
yield user.destroy();
}
debug('Creating test user');
yield createUser();
});