0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed timing-dependent content gating test

- This test failed for me intermittently because the posts would be out of order
- I assume this is due to my super-powered M1 mac 😂
- This rewrite only aims to remove the dependency between the insertion order and the output order
- Everything else should be the same, and it still tests that the posts that are meant to be members only are exactly that
This commit is contained in:
Hannah Wolfe 2022-01-24 21:43:59 +00:00
parent d3dfa1e5a1
commit 8319d73b0a
No known key found for this signature in database
GPG key ID: AB586C3B5AE5C037

View file

@ -262,28 +262,24 @@ describe('api/canary/content/posts', function () {
before (function () { before (function () {
publicPost = testUtils.DataGenerator.forKnex.createPost({ publicPost = testUtils.DataGenerator.forKnex.createPost({
slug: 'free-to-see', slug: 'free-to-see',
visibility: 'public', visibility: 'public'
published_at: moment().add(15, 'seconds').toDate() // here to ensure sorting is not modified
}); });
membersPost = testUtils.DataGenerator.forKnex.createPost({ membersPost = testUtils.DataGenerator.forKnex.createPost({
slug: 'thou-shalt-not-be-seen', slug: 'thou-shalt-not-be-seen',
visibility: 'members', visibility: 'members'
published_at: moment().add(45, 'seconds').toDate() // here to ensure sorting is not modified
}); });
paidPost = testUtils.DataGenerator.forKnex.createPost({ paidPost = testUtils.DataGenerator.forKnex.createPost({
slug: 'thou-shalt-be-paid-for', slug: 'thou-shalt-be-paid-for',
visibility: 'paid', visibility: 'paid'
published_at: moment().add(30, 'seconds').toDate() // here to ensure sorting is not modified
}); });
membersPostWithPaywallCard = testUtils.DataGenerator.forKnex.createPost({ membersPostWithPaywallCard = testUtils.DataGenerator.forKnex.createPost({
slug: 'thou-shalt-have-a-taste', slug: 'thou-shalt-have-a-taste',
visibility: 'members', visibility: 'members',
mobiledoc: '{"version":"0.3.1","markups":[],"atoms":[],"cards":[["paywall",{}]],"sections":[[1,"p",[[0,[],0,"Free content"]]],[10,0],[1,"p",[[0,[],0,"Members content"]]]]}', mobiledoc: '{"version":"0.3.1","markups":[],"atoms":[],"cards":[["paywall",{}]],"sections":[[1,"p",[[0,[],0,"Free content"]]],[10,0],[1,"p",[[0,[],0,"Members content"]]]]}',
html: '<p>Free content</p><!--members-only--><p>Members content</p>', html: '<p>Free content</p><!--members-only--><p>Members content</p>'
published_at: moment().add(5, 'seconds').toDate()
}); });
return testUtils.fixtures.insertPosts([ return testUtils.fixtures.insertPosts([
@ -407,24 +403,32 @@ describe('api/canary/content/posts', function () {
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination'); localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
_.isBoolean(jsonResponse.posts[0].featured).should.eql(true); _.isBoolean(jsonResponse.posts[0].featured).should.eql(true);
// Default order 'published_at desc' check const membersOnlySlugs = [
jsonResponse.posts[0].slug.should.eql('thou-shalt-not-be-seen'); 'thou-shalt-not-be-seen',
jsonResponse.posts[1].slug.should.eql('thou-shalt-be-paid-for'); 'thou-shalt-be-paid-for'
jsonResponse.posts[2].slug.should.eql('free-to-see'); ];
jsonResponse.posts[3].slug.should.eql('thou-shalt-have-a-taste');
jsonResponse.posts[8].slug.should.eql('sell');
jsonResponse.posts[0].html.should.eql(''); const freeToSeeSlugs = [
jsonResponse.posts[1].html.should.eql(''); 'free-to-see',
jsonResponse.posts[2].html.should.not.eql(''); 'thou-shalt-have-a-taste',
jsonResponse.posts[3].html.should.not.eql(''); 'sell'
jsonResponse.posts[8].html.should.not.eql(''); ];
jsonResponse.posts[0].excerpt.should.eql(''); let seen = 0;
jsonResponse.posts[1].excerpt.should.eql('');
jsonResponse.posts[2].excerpt.should.not.eql(''); jsonResponse.posts.forEach((post) => {
jsonResponse.posts[3].excerpt.should.not.eql(''); if (membersOnlySlugs.indexOf(post.slug) > -1) {
jsonResponse.posts[8].excerpt.should.not.eql(''); post.html.should.eql('');
post.excerpt.should.eql('');
seen += 1;
} else if (freeToSeeSlugs.indexOf(post.slug) > -1) {
post.html.should.not.eql('');
post.excerpt.should.not.eql('');
seen += 1;
}
});
seen.should.eql(membersOnlySlugs.length + freeToSeeSlugs.length);
// check meta response for this test // check meta response for this test
jsonResponse.meta.pagination.page.should.eql(1); jsonResponse.meta.pagination.page.should.eql(1);