mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fixed model posts test suite
refs https://github.com/TryGhost/Toolbox/issues/230 - Code tweaks to make test suite for post modela and utils play nicely without single post author concept
This commit is contained in:
parent
6e6c702127
commit
e38c8a4662
3 changed files with 14 additions and 15 deletions
|
@ -808,8 +808,8 @@ describe('Post Model', function () {
|
|||
const newPost = testUtils.DataGenerator.forModel.posts[2];
|
||||
const newPostDB = testUtils.DataGenerator.Content.posts[2];
|
||||
|
||||
models.Post.add(newPost, _.merge({withRelated: ['author']}, context)).then(function (createdPost) {
|
||||
return models.Post.findOne({id: createdPost.id, status: 'all'});
|
||||
models.Post.add(newPost, _.merge({withRelated: ['authors']}, context)).then(function (createdPost) {
|
||||
return models.Post.findOne({id: createdPost.id, status: 'all'}, {withRelated: ['authors']});
|
||||
}).then(function (createdPost) {
|
||||
should.exist(createdPost);
|
||||
createdPost.has('uuid').should.equal(true);
|
||||
|
@ -832,9 +832,8 @@ describe('Post Model', function () {
|
|||
|
||||
createdPost.get('created_at').should.be.above(new Date(0).getTime());
|
||||
createdPost.get('created_by').should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
createdPost.get('author_id').should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
createdPost.has('author').should.equal(false);
|
||||
createdPost.get('created_by').should.equal(createdPost.get('author_id'));
|
||||
createdPost.relations.authors.models[0].id.should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
createdPost.get('created_by').should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
createdPost.get('updated_at').should.be.above(new Date(0).getTime());
|
||||
createdPost.get('updated_by').should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
should.equal(createdPost.get('published_at'), null);
|
||||
|
@ -882,8 +881,8 @@ describe('Post Model', function () {
|
|||
const newPost = testUtils.DataGenerator.forModel.posts[2];
|
||||
const newPostDB = testUtils.DataGenerator.Content.posts[2];
|
||||
|
||||
models.Post.add(newPost, _.merge({withRelated: ['author']}, context)).then(function (createdPost) {
|
||||
return models.Post.findOne({id: createdPost.id, status: 'all'});
|
||||
models.Post.add(newPost, _.merge({withRelated: ['authors']}, context)).then(function (createdPost) {
|
||||
return models.Post.findOne({id: createdPost.id, status: 'all'}, {withRelated: ['authors']});
|
||||
}).then(function (createdPost) {
|
||||
should.exist(createdPost);
|
||||
createdPost.has('uuid').should.equal(true);
|
||||
|
@ -906,9 +905,8 @@ describe('Post Model', function () {
|
|||
|
||||
createdPost.get('created_at').should.be.above(new Date(0).getTime());
|
||||
createdPost.get('created_by').should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
createdPost.get('author_id').should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
createdPost.has('author').should.equal(false);
|
||||
createdPost.get('created_by').should.equal(createdPost.get('author_id'));
|
||||
createdPost.relations.authors.models[0].id.should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
createdPost.get('created_by').should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
createdPost.get('updated_at').should.be.above(new Date(0).getTime());
|
||||
createdPost.get('updated_by').should.equal(testUtils.DataGenerator.Content.users[0].id);
|
||||
should.equal(createdPost.get('published_at'), null);
|
||||
|
@ -986,7 +984,7 @@ describe('Post Model', function () {
|
|||
}]
|
||||
}, _.merge({withRelated: ['authors']}, context)).then(function (newPost) {
|
||||
should.exist(newPost);
|
||||
newPost.toJSON().author.should.eql(testUtils.DataGenerator.forKnex.users[0].id);
|
||||
newPost.toJSON().primary_author.id.should.eql(testUtils.DataGenerator.forKnex.users[0].id);
|
||||
newPost.toJSON().authors.length.should.eql(1);
|
||||
newPost.toJSON().authors[0].id.should.eql(testUtils.DataGenerator.forKnex.users[0].id);
|
||||
done();
|
||||
|
|
|
@ -95,12 +95,12 @@ const fixtures = {
|
|||
// Let's insert posts with random authors
|
||||
for (i = 0; i < count; i += 1) {
|
||||
const author = users[i % users.length];
|
||||
posts.push(DataGenerator.forKnex.createGenericPost(k, null, null, author));
|
||||
posts.push(DataGenerator.forKnex.createGenericPost(k, null, null, [{id: author}]));
|
||||
k = k + 1;
|
||||
}
|
||||
|
||||
return Promise.map(posts, function (post, index) {
|
||||
posts[index].authors = [{id: posts[index].author_id}];
|
||||
posts[index].authors = [{id: posts[index].authors[0].id}];
|
||||
posts[index].tags = [tags[Math.floor(Math.random() * (tags.length - 1))]];
|
||||
return models.Post.add(posts[index], context.internal);
|
||||
});
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Reference in a new issue