Ghost/ghost/announcement-bar-settings/test/AnnouncementBarSettings.test.js
Naz cddf786424
Added filtering of announcement bar content
refs https://github.com/TryGhost/Team/issues/3051

-  We need to show the announcement_content to specific audiences based on the announcement_visibility filter
2023-04-21 13:46:37 +02:00

106 lines
4.1 KiB
JavaScript

const assert = require('assert');
const AnnouncementBarSettings = require('../index');
describe('AnnouncementBarSettings', function () {
it('can initialize', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['visitors'],
announcement_background: 'dark'
})
});
assert.ok(announcementBarSettings);
});
describe('getAnnouncementSettings', function () {
it('returns undefined if there is no announcement content', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: null,
announcement_visibility: [],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings();
assert.equal(settings, undefined);
});
it('returns undefined announcement settings if there is no announcement visibility', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: [],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings();
assert.equal(settings, undefined);
});
it('returns announcement if visibility is set to visitors and there is no logged in member', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['visitors'],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings();
assert.equal(settings.announcement, 'Hello world');
});
it('returns announcement if visibility is set to free members and member is free', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['free_members'],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings({
status: 'free'
});
assert.equal(settings.announcement, 'Hello world');
});
it('returns announcement if visibility is set to paid members and member is paid', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['paid_members'],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings({
status: 'paid'
});
assert.equal(settings.announcement, 'Hello world');
});
it('returns announcement if visibility is set to paid and paid members and member is comped', function () {
const announcementBarSettings = new AnnouncementBarSettings({
getAnnouncementSettings: () => ({
announcement: 'Hello world',
announcement_visibility: ['paid_members'],
announcement_background: 'dark'
})
});
const settings = announcementBarSettings.getAnnouncementSettings({
status: 'comped'
});
assert.equal(settings.announcement, 'Hello world');
});
});
});