2013-09-23 02:20:08 +04:00
|
|
|
var knex = require('../../server/models/base').knex,
|
2013-06-25 15:43:15 +04:00
|
|
|
when = require('when'),
|
2013-08-03 19:11:16 +04:00
|
|
|
migration = require("../../server/data/migration/"),
|
2013-09-02 05:49:08 +04:00
|
|
|
Settings = require('../../server/models/settings').Settings,
|
2013-10-08 05:39:33 +04:00
|
|
|
DataGenerator = require('./fixtures/data-generator'),
|
|
|
|
API = require('./utils/api');
|
2013-05-24 08:02:41 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
function initData() {
|
|
|
|
return migration.init();
|
|
|
|
}
|
2013-06-15 02:12:04 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
function clearData() {
|
|
|
|
// we must always try to delete all tables
|
|
|
|
return migration.reset();
|
|
|
|
}
|
2013-06-15 02:12:04 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
function insertDefaultFixtures() {
|
|
|
|
var promises = [];
|
|
|
|
|
|
|
|
promises.push(insertDefaultUser());
|
|
|
|
promises.push(insertPosts());
|
|
|
|
|
|
|
|
return when.all(promises);
|
|
|
|
}
|
|
|
|
|
|
|
|
function insertPosts() {
|
|
|
|
var promises = [];
|
|
|
|
|
|
|
|
promises.push(knex('posts').insert(DataGenerator.forKnex.posts));
|
|
|
|
promises.push(knex('tags').insert(DataGenerator.forKnex.tags));
|
|
|
|
promises.push(knex('posts_tags').insert(DataGenerator.forKnex.posts_tags));
|
2013-08-25 00:51:58 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
return when.all(promises);
|
|
|
|
}
|
2013-06-15 02:12:04 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
function insertMorePosts() {
|
|
|
|
var lang,
|
|
|
|
status,
|
|
|
|
posts,
|
|
|
|
promises = [],
|
|
|
|
i, j, k = 0;
|
2013-06-15 02:12:04 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
for (i = 0; i < 2; i += 1) {
|
|
|
|
posts = [];
|
|
|
|
lang = i % 2 ? 'en' : 'fr';
|
|
|
|
posts.push(DataGenerator.forKnex.createGenericPost(k++, null, lang));
|
2013-06-15 02:12:04 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
for (j = 0; j < 50; j += 1) {
|
|
|
|
status = j % 2 ? 'published' : 'draft';
|
|
|
|
posts.push(DataGenerator.forKnex.createGenericPost(k++, status, lang));
|
|
|
|
}
|
|
|
|
|
|
|
|
promises.push(knex('posts').insert(posts));
|
2013-06-25 15:43:15 +04:00
|
|
|
}
|
2013-08-25 00:51:58 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
return when.all(promises);
|
|
|
|
}
|
|
|
|
|
|
|
|
function insertDefaultUser() {
|
|
|
|
var users = [],
|
|
|
|
userRoles = [],
|
|
|
|
u_promises = [];
|
2013-05-24 08:02:41 +04:00
|
|
|
|
2013-10-08 05:39:33 +04:00
|
|
|
users.push(DataGenerator.forKnex.createUser(DataGenerator.Content.users[0]));
|
|
|
|
u_promises.push(knex('users').insert(users));
|
|
|
|
userRoles.push(DataGenerator.forKnex.createUserRole(1, 1));
|
|
|
|
u_promises.push(knex('roles_users').insert(userRoles));
|
|
|
|
|
|
|
|
return when.all(u_promises);
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
initData: initData,
|
|
|
|
clearData: clearData,
|
|
|
|
insertDefaultFixtures: insertDefaultFixtures,
|
|
|
|
insertPosts: insertPosts,
|
|
|
|
insertMorePosts: insertMorePosts,
|
|
|
|
insertDefaultUser: insertDefaultUser,
|
|
|
|
|
|
|
|
DataGenerator: DataGenerator,
|
|
|
|
API: API
|
|
|
|
};
|