hostr/test/fixtures/user.js

35 lines
771 B
JavaScript
Raw Normal View History

2016-06-19 11:17:31 -07:00
import co from 'co';
2016-06-19 10:14:47 -07:00
import models from '../../models';
2016-06-19 11:17:31 -07:00
import debugname from 'debug';
const debug = debugname('hostr:db');
function *createUser() {
const user = yield models.user.create({
2016-06-19 10:14:47 -07:00
'email': 'test@hostr.co',
'password': '$pbkdf2-256-1$2$kBhIDRqFwnF/1ms6ZHfME2o2$a48e8c350d26397fcc88bf0a7a2817b1cdcd1ffffe0521a5',
'ip': '127.0.0.1',
'plan': 'Free',
'activated': true,
});
2016-06-19 11:17:31 -07:00
yield user.save();
yield models.sequelize.close();
2016-06-19 10:14:47 -07:00
}
2016-06-19 11:17:31 -07:00
co(function *sync() {
debug('Syncing schema');
yield models.sequelize.sync();
debug('Schema synced');
const user = yield models.user.findOne({
where: {
email: 'test@hostr.co',
},
});
2016-06-19 10:14:47 -07:00
if (user) {
2016-06-19 11:17:31 -07:00
yield user.destroy();
2016-06-19 10:14:47 -07:00
}
2016-06-19 11:17:31 -07:00
debug('Creating test user');
yield createUser();
2016-06-19 10:14:47 -07:00
});