mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added unit tests for content gating post access
refs https://github.com/TryGhost/Team/issues/1343
refs 3ccd3601b3
This commit is contained in:
parent
3ccd3601b3
commit
56a8d21263
1 changed files with 84 additions and 0 deletions
84
test/unit/server/services/members/content-gating.test.js
Normal file
84
test/unit/server/services/members/content-gating.test.js
Normal file
|
@ -0,0 +1,84 @@
|
|||
const should = require('should');
|
||||
const {checkPostAccess} = require('../../../../../core/server/services/members/content-gating');
|
||||
|
||||
describe('Members Service - Content gating', function () {
|
||||
describe('checkPostAccess', function () {
|
||||
let post;
|
||||
let member;
|
||||
let access;
|
||||
|
||||
it('should allow access to public posts without member', async function () {
|
||||
post = {visibility: 'public'};
|
||||
member = null;
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.true();
|
||||
});
|
||||
|
||||
it('should allow access to public posts with member', async function () {
|
||||
post = {visibility: 'public'};
|
||||
member = {id: 'test'};
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.true();
|
||||
});
|
||||
|
||||
it('should allow access to members only post with member', async function () {
|
||||
post = {visibility: 'members'};
|
||||
member = {id: 'test'};
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.true();
|
||||
});
|
||||
|
||||
it('should allow access to paid members only posts for paid members', async function () {
|
||||
post = {visibility: 'paid'};
|
||||
member = {id: 'test', status: 'paid'};
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.true();
|
||||
});
|
||||
|
||||
it('should allow access to tiers only post for members on allowed tier', async function () {
|
||||
post = {visibility: 'tiers', tiers: [{slug: 'test-tier'}]};
|
||||
member = {id: 'test', status: 'paid', products: [{
|
||||
slug: 'test-tier'
|
||||
}]};
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.true();
|
||||
});
|
||||
|
||||
it('should block access to members only post without member', async function () {
|
||||
post = {visibility: 'members'};
|
||||
member = null;
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.false();
|
||||
});
|
||||
|
||||
it('should block access to paid members only post without member', async function () {
|
||||
post = {visibility: 'paid'};
|
||||
member = null;
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.false();
|
||||
});
|
||||
|
||||
it('should block access to paid members only posts for free members', async function () {
|
||||
post = {visibility: 'paid'};
|
||||
member = {id: 'test', status: 'free'};
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.false();
|
||||
});
|
||||
|
||||
it('should block access to specific tiers only post without tiers list', async function () {
|
||||
post = {visibility: 'tiers'};
|
||||
member = {id: 'test'};
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.false();
|
||||
});
|
||||
|
||||
it('should block access to tiers only post for members not on allowed tier', async function () {
|
||||
post = {visibility: 'tiers', tiers: [{slug: 'test-tier'}]};
|
||||
member = {id: 'test', status: 'paid', products: [{
|
||||
slug: 'test-tier-2'
|
||||
}]};
|
||||
access = checkPostAccess(post, member);
|
||||
should(access).be.false();
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue