mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Fix tests to ensure correct post is being checked
Refs #3473 - Change tests to not assume that all inserted fixture data will end up with the same millisecond-precision time for results sorting. If a test is set up to check the contents of a specific fixture extract it explictly from the results.
This commit is contained in:
parent
b0fdf4d078
commit
0ebccc5c65
1 changed files with 16 additions and 5 deletions
|
@ -21,6 +21,10 @@ describe('Post Model', function () {
|
||||||
|
|
||||||
should.exist(PostModel);
|
should.exist(PostModel);
|
||||||
|
|
||||||
|
function extractFirstPost(posts) {
|
||||||
|
return _.filter(posts, { id: 1 })[0];
|
||||||
|
}
|
||||||
|
|
||||||
function checkFirstPostData(firstPost) {
|
function checkFirstPostData(firstPost) {
|
||||||
should.not.exist(firstPost.author_id);
|
should.not.exist(firstPost.author_id);
|
||||||
firstPost.author.should.be.an.Object;
|
firstPost.author.should.be.an.Object;
|
||||||
|
@ -54,8 +58,14 @@ describe('Post Model', function () {
|
||||||
.then(function (results) {
|
.then(function (results) {
|
||||||
should.exist(results);
|
should.exist(results);
|
||||||
results.length.should.be.above(0);
|
results.length.should.be.above(0);
|
||||||
firstPost = results.models[0].toJSON();
|
posts = results.models.map(function (model) {
|
||||||
checkFirstPostData(firstPost);
|
return model.toJSON();
|
||||||
|
});
|
||||||
|
|
||||||
|
// the first post in the result is not always the post at
|
||||||
|
// position 0 in the fixture data so we need to use extractFirstPost
|
||||||
|
// to get the post with id: 1
|
||||||
|
checkFirstPostData(extractFirstPost(posts));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
|
@ -86,9 +96,10 @@ describe('Post Model', function () {
|
||||||
results.meta.pagination.pages.should.equal(1);
|
results.meta.pagination.pages.should.equal(1);
|
||||||
results.posts.length.should.equal(4);
|
results.posts.length.should.equal(4);
|
||||||
|
|
||||||
firstPost = results.posts[0];
|
// the first post in the result is not always the post at
|
||||||
|
// position 0 in the fixture data so we need to use extractFirstPost
|
||||||
checkFirstPostData(firstPost);
|
// to get the post with id: 1
|
||||||
|
checkFirstPostData(extractFirstPost(results.posts));
|
||||||
|
|
||||||
done();
|
done();
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
|
|
Loading…
Add table
Reference in a new issue