2023-04-20 18:23:06 +03:00
|
|
|
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 () {
|
2023-04-21 16:14:09 +03:00
|
|
|
const testVisibility = (announcementSettings, member, expected) => {
|
2023-04-20 18:23:06 +03:00
|
|
|
const announcementBarSettings = new AnnouncementBarSettings({
|
2023-04-21 16:14:09 +03:00
|
|
|
getAnnouncementSettings: () => (announcementSettings)
|
2023-04-20 18:23:06 +03:00
|
|
|
});
|
|
|
|
|
2023-04-21 16:14:09 +03:00
|
|
|
const settings = announcementBarSettings.getAnnouncementSettings(member);
|
2023-04-20 18:23:06 +03:00
|
|
|
|
2023-04-21 16:14:09 +03:00
|
|
|
assert.deepEqual(settings, expected);
|
|
|
|
};
|
|
|
|
|
|
|
|
it('returns undefined settings if there is no announcement content', function () {
|
|
|
|
testVisibility({
|
|
|
|
announcement: null,
|
|
|
|
announcement_visibility: []
|
|
|
|
}, undefined, undefined);
|
2023-04-20 18:23:06 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns undefined announcement settings if there is no announcement visibility', function () {
|
2023-04-21 16:14:09 +03:00
|
|
|
testVisibility({
|
|
|
|
announcement: {
|
2023-04-20 18:23:06 +03:00
|
|
|
announcement: 'Hello world',
|
2023-04-21 16:14:09 +03:00
|
|
|
announcement_visibility: []
|
|
|
|
},
|
|
|
|
announcement_visibility: []
|
|
|
|
}, undefined, undefined);
|
2023-04-20 18:23:06 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('returns announcement if visibility is set to visitors and there is no logged in member', function () {
|
2023-04-21 16:14:09 +03:00
|
|
|
testVisibility({
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_visibility: ['visitors'],
|
|
|
|
announcement_background: 'dark'
|
|
|
|
}, undefined, {
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_background: 'dark'
|
2023-04-20 18:23:06 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns announcement if visibility is set to free members and member is free', function () {
|
2023-04-21 16:14:09 +03:00
|
|
|
testVisibility({
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_visibility: ['free_members'],
|
|
|
|
announcement_background: 'dark'
|
|
|
|
}, {
|
2023-04-20 18:23:06 +03:00
|
|
|
status: 'free'
|
2023-04-21 16:14:09 +03:00
|
|
|
}, {
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_background: 'dark'
|
2023-04-20 18:23:06 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns announcement if visibility is set to paid members and member is paid', function () {
|
2023-04-21 16:14:09 +03:00
|
|
|
testVisibility({
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_visibility: ['paid_members'],
|
|
|
|
announcement_background: 'dark'
|
|
|
|
}, {
|
2023-04-20 18:23:06 +03:00
|
|
|
status: 'paid'
|
2023-04-21 16:14:09 +03:00
|
|
|
}, {
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_background: 'dark'
|
2023-04-20 18:23:06 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('returns announcement if visibility is set to paid and paid members and member is comped', function () {
|
2023-04-21 16:14:09 +03:00
|
|
|
testVisibility({
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_visibility: ['paid_members'],
|
|
|
|
announcement_background: 'dark'
|
|
|
|
}, {
|
2023-04-20 18:23:06 +03:00
|
|
|
status: 'comped'
|
2023-04-21 16:14:09 +03:00
|
|
|
}, {
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_background: 'dark'
|
2023-04-20 18:23:06 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|