0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

Added missing test cases for post.author

no issue

- Ghost does not support adding an author by relation (`post.author = {id: '..'}`)
- Ghost does not support editing an author by relation (`post.author = {id: '..'}`)
- only `author_id` is allowed
This commit is contained in:
kirrg001 2018-02-17 15:31:12 +01:00
parent 0aff9f33d9
commit b204d5874e

View file

@ -9,6 +9,8 @@ var should = require('should'),
ghostBookshelf = require('../../../server/models/base'),
PostModel = require('../../../server/models/post').Post,
TagModel = require('../../../server/models/tag').Tag,
UserModel = require('../../../server/models/user').User,
RoleModel = require('../../../server/models/role').Role,
common = require('../../../server/lib/common'),
configUtils = require('../../utils/configUtils'),
DataGenerator = testUtils.DataGenerator,
@ -51,6 +53,7 @@ describe('Post Model', function () {
firstPost.url.should.equal('/html-ipsum/');
firstPost.fields.should.be.an.Array();
firstPost.tags.should.be.an.Array();
firstPost.author.name.should.equal(DataGenerator.Content.users[0].name);
firstPost.fields[0].key.should.equal(DataGenerator.Content.app_fields[0].key);
firstPost.created_at.should.be.an.instanceof(Date);
@ -1027,6 +1030,21 @@ describe('Post Model', function () {
});
});
it('[unsupported] can\'t add `author` as object', function () {
var newPost = testUtils.DataGenerator.forModel.posts[2];
// `post.author` relation get's ignored in Ghost - unsupported
newPost.author = {id: testUtils.DataGenerator.Content.users[3].id};
delete newPost.author_id;
return PostModel.add(newPost, context)
.then(function (createdPost) {
// fallsback to logged in user
createdPost.get('author_id').should.eql(context.context.user);
createdPost.get('author_id').should.not.eql(testUtils.DataGenerator.Content.users[3].id);
});
});
it('can add, defaults are all correct', function (done) {
var createdPostUpdatedDate,
newPost = testUtils.DataGenerator.forModel.posts[2],
@ -1720,6 +1738,8 @@ describe('Post Model', function () {
return Promise.props({
post: PostModel.add(post, _.extend({}, context, {withRelated: ['tags']})),
role: RoleModel.add(testUtils.DataGenerator.forKnex.roles[2], context),
user: UserModel.add(testUtils.DataGenerator.forKnex.users[0], context),
tag1: TagModel.add(extraTags[0], context),
tag2: TagModel.add(extraTags[1], context),
tag3: TagModel.add(extraTags[2], context)
@ -1774,6 +1794,22 @@ describe('Post Model', function () {
});
});
it('[unsupported] can\'t edit `author` as object', function () {
var newJSON = _.cloneDeep(postJSON),
modelOptions = _.clone(editOptions);
newJSON.author.should.eql(testUtils.DataGenerator.Content.users[0].id);
newJSON.author = {id: testUtils.DataGenerator.Content.users[3].id};
delete newJSON.author_id;
modelOptions.withRelated.push('author');
return PostModel.edit(newJSON, modelOptions)
.then(function (updatedPost) {
updatedPost.get('author_id').should.eql(testUtils.DataGenerator.Content.users[0].id);
updatedPost.related('author').toJSON().slug.should.eql(testUtils.DataGenerator.Content.users[0].slug);
});
});
it('can\'t edit dates and authors of existing tag', function () {
var newJSON = _.cloneDeep(postJSON), updatedAtFormat;