2022-02-23 14:25:53 +03:00
|
|
|
const assert = require('assert');
|
2022-03-02 19:00:22 +03:00
|
|
|
const moment = require('moment');
|
2022-02-23 14:25:53 +03:00
|
|
|
|
2022-03-02 19:00:22 +03:00
|
|
|
const testUtils = require('../../utils');
|
|
|
|
const models = require('../../../core/server/models');
|
2022-02-23 14:25:53 +03:00
|
|
|
const {agentProvider, fixtureManager, matchers} = require('../../utils/e2e-framework');
|
2022-03-01 14:17:13 +03:00
|
|
|
const {anyEtag, anyUuid, anyISODateTimeWithTZ} = matchers;
|
2022-02-23 14:25:53 +03:00
|
|
|
|
|
|
|
const pageMatcher = {
|
2022-03-01 14:17:13 +03:00
|
|
|
published_at: anyISODateTimeWithTZ,
|
|
|
|
created_at: anyISODateTimeWithTZ,
|
|
|
|
updated_at: anyISODateTimeWithTZ,
|
2022-02-23 14:25:53 +03:00
|
|
|
uuid: anyUuid
|
|
|
|
};
|
2018-10-13 01:48:49 +03:00
|
|
|
|
2019-02-04 17:49:59 +03:00
|
|
|
describe('Pages Content API', function () {
|
2022-02-23 14:25:53 +03:00
|
|
|
let agent;
|
2020-11-30 17:25:22 +03:00
|
|
|
|
|
|
|
before(async function () {
|
2022-02-23 14:25:53 +03:00
|
|
|
agent = await agentProvider.getContentAPIAgent();
|
|
|
|
await fixtureManager.init('users:no-owner', 'user:inactive', 'posts', 'tags:extra', 'api_keys');
|
2022-05-30 16:00:55 +03:00
|
|
|
await agent.authenticate();
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can request pages', async function () {
|
2022-02-23 14:25:53 +03:00
|
|
|
const res = await agent.get(`pages/`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
pages: new Array(5)
|
|
|
|
.fill(pageMatcher)
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.body.pages[0].slug, 'about');
|
|
|
|
|
|
|
|
const urlParts = new URL(res.body.pages[0].url);
|
|
|
|
assert.equal(urlParts.protocol, 'http:');
|
|
|
|
assert.equal(urlParts.host, '127.0.0.1:2369');
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|
2018-10-17 12:48:06 +03:00
|
|
|
|
2020-11-30 17:25:22 +03:00
|
|
|
it('Can request page', async function () {
|
2022-02-23 14:25:53 +03:00
|
|
|
const res = await agent.get(`pages/${fixtureManager.get('posts', 5).id}/`)
|
|
|
|
.expectStatus(200)
|
|
|
|
.matchHeaderSnapshot({
|
|
|
|
etag: anyEtag
|
|
|
|
})
|
|
|
|
.matchBodySnapshot({
|
|
|
|
pages: new Array(1)
|
|
|
|
.fill(pageMatcher)
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(res.body.pages[0].slug, fixtureManager.get('posts', 5).slug);
|
|
|
|
|
|
|
|
const urlParts = new URL(res.body.pages[0].url);
|
|
|
|
assert.equal(urlParts.protocol, 'http:');
|
|
|
|
assert.equal(urlParts.host, '127.0.0.1:2369');
|
2018-10-17 12:48:06 +03:00
|
|
|
});
|
2022-03-02 19:00:22 +03:00
|
|
|
|
|
|
|
it('Can include free and paid tiers for public post', async function () {
|
|
|
|
const publicPost = testUtils.DataGenerator.forKnex.createPost({
|
|
|
|
type: 'page',
|
|
|
|
slug: 'free-to-see',
|
|
|
|
visibility: 'public',
|
|
|
|
published_at: moment().add(15, 'seconds').toDate() // here to ensure sorting is not modified
|
|
|
|
});
|
|
|
|
await models.Post.add(publicPost, {context: {internal: true}});
|
|
|
|
|
|
|
|
const publicPostRes = await agent
|
|
|
|
.get(`pages/${publicPost.id}/?include=tiers`)
|
|
|
|
.expectStatus(200);
|
|
|
|
const publicPostData = publicPostRes.body.pages[0];
|
|
|
|
publicPostData.tiers.length.should.eql(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can include free and paid tiers for members only post', async function () {
|
|
|
|
const membersPost = testUtils.DataGenerator.forKnex.createPost({
|
|
|
|
type: 'page',
|
|
|
|
slug: 'thou-shalt-not-be-seen',
|
|
|
|
visibility: 'members',
|
|
|
|
published_at: moment().add(45, 'seconds').toDate() // here to ensure sorting is not modified
|
|
|
|
});
|
|
|
|
await models.Post.add(membersPost, {context: {internal: true}});
|
|
|
|
|
|
|
|
const membersPostRes = await agent
|
|
|
|
.get(`pages/${membersPost.id}/?include=tiers`)
|
|
|
|
.expectStatus(200);
|
|
|
|
const membersPostData = membersPostRes.body.pages[0];
|
|
|
|
membersPostData.tiers.length.should.eql(2);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can include only paid tier for paid post', async function () {
|
|
|
|
const paidPost = testUtils.DataGenerator.forKnex.createPost({
|
|
|
|
type: 'page',
|
|
|
|
slug: 'thou-shalt-be-paid-for',
|
|
|
|
visibility: 'paid',
|
|
|
|
published_at: moment().add(30, 'seconds').toDate() // here to ensure sorting is not modified
|
|
|
|
});
|
|
|
|
await models.Post.add(paidPost, {context: {internal: true}});
|
|
|
|
|
|
|
|
const paidPostRes = await agent
|
|
|
|
.get(`pages/${paidPost.id}/?include=tiers`)
|
|
|
|
.expectStatus(200);
|
|
|
|
const paidPostData = paidPostRes.body.pages[0];
|
|
|
|
paidPostData.tiers.length.should.eql(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Can include specific tier for page with tiers visibility', async function () {
|
|
|
|
const res = await agent
|
2022-05-12 17:44:06 +03:00
|
|
|
.get(`tiers/`)
|
2022-03-02 19:00:22 +03:00
|
|
|
.expectStatus(200);
|
|
|
|
|
|
|
|
const jsonResponse = res.body;
|
2022-05-12 17:44:06 +03:00
|
|
|
const paidTier = jsonResponse.tiers.find(p => p.type === 'paid');
|
2022-03-02 19:00:22 +03:00
|
|
|
|
|
|
|
const tiersPage = testUtils.DataGenerator.forKnex.createPost({
|
|
|
|
slug: 'thou-shalt-be-for-specific-tiers',
|
|
|
|
type: 'page',
|
|
|
|
visibility: 'tiers',
|
|
|
|
published_at: moment().add(30, 'seconds').toDate() // here to ensure sorting is not modified
|
|
|
|
});
|
|
|
|
|
|
|
|
tiersPage.tiers = [paidTier];
|
|
|
|
|
|
|
|
await models.Post.add(tiersPage, {context: {internal: true}});
|
|
|
|
|
|
|
|
const tiersPostRes = await agent
|
|
|
|
.get(`pages/${tiersPage.id}/?include=tiers`)
|
|
|
|
.expectStatus(200);
|
|
|
|
|
|
|
|
const tiersPostData = tiersPostRes.body.pages[0];
|
|
|
|
|
|
|
|
tiersPostData.tiers.length.should.eql(1);
|
|
|
|
});
|
2018-10-13 01:48:49 +03:00
|
|
|
});
|