Updated tests to handle visibility tier

refs https://github.com/TryGhost/Team/issues/1071

- updates tests to handle new visibility of `tiers` which uses tiers pivot table
This commit is contained in:
Rishabh 2022-01-26 16:56:33 +05:30 committed by Rishabh Garg
parent 93596a1375
commit 64721150a9
12 changed files with 45 additions and 31 deletions

View File

@ -116,9 +116,20 @@ describe('Pages API', function () {
.set('Origin', config.get('url'))
.expect(200);
const resProducts = await request
.get(localUtils.API.getApiQuery(`products/`))
.set('Origin', config.get('url'))
.expect(200);
const products = resProducts.body.products;
page.updated_at = res.body.pages[0].updated_at;
page.visibility = 'filter';
page.visibility_filter = 'product:default-product';
page.visibility = 'tiers';
const paidTiers = products.filter((p) => {
return p.type === 'paid';
}).map((product) => {
return product;
});
page.tiers = paidTiers;
const res2 = await request.put(localUtils.API.getApiQuery('pages/' + testUtils.DataGenerator.Content.posts[5].id))
.set('Origin', config.get('url'))
@ -128,7 +139,8 @@ describe('Pages API', function () {
.expect(200);
should.exist(res2.headers['x-cache-invalidate']);
localUtils.API.checkResponse(res2.body.pages[0], 'page', ['visibility_filter']);
localUtils.API.checkResponse(res2.body.pages[0], 'page');
res2.body.pages[0].tiers.length.should.eql(paidTiers.length);
const model = await models.Post.findOne({
id: res2.body.pages[0].id

View File

@ -94,7 +94,7 @@ describe('Posts API', function () {
jsonResponse.posts[0],
'post',
null,
['authors', 'primary_author', 'email']
['authors', 'primary_author', 'email', 'tiers']
);
localUtils.API.checkResponse(jsonResponse.meta.pagination, 'pagination');
@ -179,7 +179,7 @@ describe('Posts API', function () {
it('Can include relations for a single post', async function () {
const res = await request
.get(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/?include=authors,tags,email'))
.get(localUtils.API.getApiQuery('posts/' + testUtils.DataGenerator.Content.posts[0].id + '/?include=authors,tags,email,tiers'))
.set('Origin', config.get('url'))
.expect('Content-Type', /json/)
.expect('Cache-Control', testUtils.cacheRules.private)

View File

@ -70,7 +70,8 @@ const expectedProperties = {
'meta_description',
'email_subject',
'frontmatter',
'email_only'
'email_only',
'tiers'
],
page: [
@ -108,7 +109,8 @@ const expectedProperties = {
'twitter_description',
'meta_title',
'meta_description',
'frontmatter'
'frontmatter',
'tiers'
],
user: _(schema.users)

View File

@ -55,10 +55,10 @@ describe('Exporter', function () {
'permissions_roles',
'permissions_users',
'posts',
'posts_products',
'posts_authors',
'posts_meta',
'posts_tags',
'posts_products',
'products',
'benefits',
'products_benefits',

View File

@ -19,7 +19,7 @@ describe('Unit: canary/utils/serializers/output/pages', function () {
sinon.restore();
});
it('calls the mapper', function () {
it('calls the mapper', async function () {
const apiConfig = {};
const frame = {
options: {
@ -44,7 +44,7 @@ describe('Unit: canary/utils/serializers/output/pages', function () {
meta: {}
};
serializers.output.pages.all(ctrlResponse, apiConfig, frame);
await serializers.output.pages.all(ctrlResponse, apiConfig, frame);
mapper.mapPage.callCount.should.equal(2);
mapper.mapPage.getCall(0).args.should.eql([ctrlResponse.data[0], frame]);

View File

@ -19,7 +19,7 @@ describe('Unit: canary/utils/serializers/output/posts', function () {
sinon.restore();
});
it('calls the mapper', function () {
it('calls the mapper', async function () {
const apiConfig = {};
const frame = {
options: {
@ -38,7 +38,7 @@ describe('Unit: canary/utils/serializers/output/posts', function () {
meta: {}
};
serializers.output.posts.all(ctrlResponse, apiConfig, frame);
await serializers.output.posts.all(ctrlResponse, apiConfig, frame);
mapper.mapPost.callCount.should.equal(2);
mapper.mapPost.getCall(0).args.should.eql([ctrlResponse.data[0], frame]);

View File

@ -19,7 +19,7 @@ describe('Unit: canary/utils/serializers/output/preview', function () {
sinon.restore();
});
it('calls the mapper', function () {
it('calls the mapper', async function () {
const apiConfig = {};
const frame = {
options: {
@ -35,7 +35,7 @@ describe('Unit: canary/utils/serializers/output/preview', function () {
type: 'page'
}));
serializers.output.preview.all(ctrlResponse, apiConfig, frame);
await serializers.output.preview.all(ctrlResponse, apiConfig, frame);
mapper.mapPost.callCount.should.equal(1);
mapper.mapPost.getCall(0).args.should.eql([ctrlResponse, frame]);

View File

@ -65,7 +65,7 @@ describe('{{next_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
done();
})
@ -262,7 +262,7 @@ describe('{{next_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.match(/\+primary_tag:test/);
done();
@ -294,7 +294,7 @@ describe('{{next_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.match(/\+primary_author:hans/);
done();
@ -326,7 +326,7 @@ describe('{{next_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.match(/\+author:author-name/);
done();
@ -357,7 +357,7 @@ describe('{{next_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.not.match(/\+author:/);
done();
@ -389,7 +389,7 @@ describe('{{next_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.not.match(/\+magic/);
done();

View File

@ -65,7 +65,7 @@ describe('{{prev_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
done();
})
@ -260,7 +260,7 @@ describe('{{prev_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.match(/\+primary_tag:test/);
done();
@ -292,7 +292,7 @@ describe('{{prev_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.match(/\+primary_author:hans/);
done();
@ -324,7 +324,7 @@ describe('{{prev_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.match(/\+author:author-name/);
done();
@ -355,7 +355,7 @@ describe('{{prev_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.not.match(/\+author:/);
done();
@ -387,7 +387,7 @@ describe('{{prev_post}} helper', function () {
fn.firstCall.args[0].should.have.properties('slug', 'title');
fn.firstCall.args[1].should.be.an.Object().and.have.property('data');
browsePostsStub.calledOnce.should.be.true();
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags');
browsePostsStub.firstCall.args[0].include.should.eql('author,authors,tags,tiers');
browsePostsStub.firstCall.args[0].filter.should.not.match(/\+magic/);
done();

View File

@ -79,7 +79,7 @@ describe('Unit - services/routing/controllers/preview', function () {
previewStub.withArgs({
uuid: req.params.uuid,
status: 'all',
include: 'authors,tags'
include: 'authors,tags,tiers'
}).resolves(apiResponse);
sinon.stub(api, 'preview').get(() => {

View File

@ -30,7 +30,7 @@ describe('Unit - services/routing/helpers/entry-lookup', function () {
postsReadStub = sinon.stub();
pagesReadStub = sinon.stub();
pagesReadStub//.withArgs({slug: pages[0].slug, include: 'author,authors,tags'})
pagesReadStub//.withArgs({slug: pages[0].slug, include: 'author,authors,tags,tiers'})
.resolves({
pages: pages
});
@ -81,7 +81,7 @@ describe('Unit - services/routing/helpers/entry-lookup', function () {
postsReadStub = sinon.stub();
pagesReadStub = sinon.stub();
postsReadStub//.withArgs({slug: posts[0].slug, include: 'author,authors,tags'})
postsReadStub//.withArgs({slug: posts[0].slug, include: 'author,authors,tags,tiers'})
.resolves({
posts: posts
});

View File

@ -113,7 +113,7 @@ describe('Unit - services/routing/helpers/fetch-data', function () {
result.data.featured.length.should.eql(posts.length);
browsePostsStub.calledTwice.should.be.true();
browsePostsStub.firstCall.args[0].should.have.property('include', 'authors,tags');
browsePostsStub.firstCall.args[0].should.have.property('include', 'authors,tags,tiers');
browsePostsStub.secondCall.args[0].should.have.property('filter', 'featured:true');
browsePostsStub.secondCall.args[0].should.have.property('limit', 3);
done();
@ -145,7 +145,7 @@ describe('Unit - services/routing/helpers/fetch-data', function () {
result.data.featured.length.should.eql(posts.length);
browsePostsStub.calledTwice.should.be.true();
browsePostsStub.firstCall.args[0].should.have.property('include', 'authors,tags');
browsePostsStub.firstCall.args[0].should.have.property('include', 'authors,tags,tiers');
browsePostsStub.firstCall.args[0].should.have.property('page', 2);
browsePostsStub.secondCall.args[0].should.have.property('filter', 'featured:true');
browsePostsStub.secondCall.args[0].should.have.property('limit', 3);