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);
|
|
|
|
});
|
|
|
|
|
2023-04-25 16:47:29 +03:00
|
|
|
describe('AnnouncementVisibilityValues', function () {
|
|
|
|
it('has static VisibilityValues property', function () {
|
|
|
|
assert.ok(AnnouncementBarSettings.VisibilityValues);
|
|
|
|
assert.equal(AnnouncementBarSettings.VisibilityValues.VISITORS, 'visitors');
|
|
|
|
assert.equal(AnnouncementBarSettings.VisibilityValues.FREE_MEMBERS, 'free_members');
|
|
|
|
assert.equal(AnnouncementBarSettings.VisibilityValues.PAID_MEMBERS, 'paid_members');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-20 18:23:06 +03:00
|
|
|
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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-21 16:27:09 +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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-21 16:27:09 +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
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-04-21 16:27:09 +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
|
|
|
});
|
|
|
|
});
|
2023-04-21 16:27:09 +03:00
|
|
|
|
|
|
|
it('returns announcement if visibility is set to paid_members and member is comped', function () {
|
|
|
|
testVisibility({
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_visibility: ['paid_members'],
|
|
|
|
announcement_background: 'dark'
|
|
|
|
}, {
|
|
|
|
status: 'comped'
|
|
|
|
}, {
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_background: 'dark'
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not return announcement if visibility is set to paid_members and there is no members', function () {
|
|
|
|
testVisibility({
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_visibility: ['paid_members'],
|
|
|
|
announcement_background: 'dark'
|
|
|
|
}, undefined, undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not return announcement if visibility is set to paid_members and member is free', function () {
|
|
|
|
testVisibility({
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_visibility: ['paid_members'],
|
|
|
|
announcement_background: 'dark'
|
|
|
|
}, {
|
|
|
|
status: 'free'
|
|
|
|
}, undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('does not return announcement if visibility is set to free_members && paid_member and there is no member', function () {
|
|
|
|
testVisibility({
|
|
|
|
announcement: 'Hello world',
|
|
|
|
announcement_visibility: ['free_members', 'paid_members'],
|
|
|
|
announcement_background: 'dark'
|
|
|
|
}, undefined, undefined);
|
|
|
|
});
|
2023-04-20 18:23:06 +03:00
|
|
|
});
|
|
|
|
});
|