Ghost/core/test/unit/testUtils.js
William Dibbern 8ef27f0590 Refactored tests
Fixes #362

- There is no need to set the viewport on functional tests anymore
unless something other
than the default of 1280x1024 is desired.
- There is no need to invoke `casper.run` to trigger `test.done`
anymore for functional tests.
- Each test works independently of the rest; registration is handled
once for the lifetime of the test run and then login/logout can be
invoked automatically as desired.
- Mocha tests all utilize predefined, more realistic fixtures when
appropriate.
- Renamed old api tests that were really model tests as appropraite.
- Added example api test for posts.
2013-10-07 21:05:25 -05:00

83 lines
2.1 KiB
JavaScript

var knex = require('../../server/models/base').Knex,
when = require('when'),
migration = require("../../server/data/migration/"),
Settings = require('../../server/models/settings').Settings,
DataGenerator = require('./fixtures/data-generator'),
API = require('./utils/api');
function initData() {
return migration.init();
}
function clearData() {
// we must always try to delete all tables
return migration.reset();
}
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));
return when.all(promises);
}
function insertMorePosts() {
var lang,
status,
posts,
promises = [],
i, j, k = 0;
for (i = 0; i < 2; i += 1) {
posts = [];
lang = i % 2 ? 'en' : 'fr';
posts.push(DataGenerator.forKnex.createGenericPost(k++, null, lang));
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));
}
return when.all(promises);
}
function insertDefaultUser() {
var users = [],
userRoles = [],
u_promises = [];
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
};