hostr/test/fixtures/user.js

37 lines
781 B
JavaScript
Raw Normal View History

2016-06-19 11:17:31 -07:00
import co from 'co';
2019-07-21 19:37:20 +00:00
import passwords from 'passwords';
2016-06-19 11:17:31 -07:00
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() {
2019-07-21 19:37:20 +00:00
const password = yield passwords.hash('test-password');
2016-06-19 11:17:31 -07:00
const user = yield models.user.create({
2016-06-19 10:14:47 -07:00
'email': 'test@hostr.co',
2019-07-21 19:37:20 +00:00
'password': password,
2016-06-19 10:14:47 -07:00
'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
});