Added role-specifics to post API tests (#9058)

refs #9043

- this is preparation for adding Author-specific tests later
  - the changes the posts_spec.js, so that all the tests are inside an "As Owner" describe block, similar to the users_spec.js
- Added new util for creating a specific post
  - This will make it easier to do routing tests on the post model in future
  - Our `index.js` file in test/utils really needs a bit of love 🙈
- Also added all the framework for author role tests in post_spec.js
- Added a single test, showing we can edit posts, including author_id
This commit is contained in:
Hannah Wolfe 2017-09-26 15:50:26 +01:00 committed by Katharina Irrgang
parent af01f51204
commit f280fbcaaf
2 changed files with 1366 additions and 1219 deletions

File diff suppressed because it is too large Load Diff

View File

@ -40,6 +40,7 @@ var Promise = require('bluebird'),
setup,
doAuth,
createUser,
createPost,
login,
togglePermalinks,
startGhost,
@ -679,6 +680,20 @@ createUser = function createUser(options) {
});
};
createPost = function createPost(options) {
var post = DataGenerator.forKnex.createPost(options.post);
if (options.author) {
post.author_id = options.author.id;
}
return db.knex('posts')
.insert(post)
.then(function () {
return post;
});
};
login = function login(request) {
// CASE: by default we use the owner to login
if (!request.user) {
@ -857,6 +872,7 @@ module.exports = {
setup: setup,
doAuth: doAuth,
createUser: createUser,
createPost: createPost,
login: login,
togglePermalinks: togglePermalinks,