diff --git a/ghost/announcement-bar-settings/lib/AnnouncementBarSettings.js b/ghost/announcement-bar-settings/lib/AnnouncementBarSettings.js index b5bcf61e5e..5e22cf143f 100644 --- a/ghost/announcement-bar-settings/lib/AnnouncementBarSettings.js +++ b/ghost/announcement-bar-settings/lib/AnnouncementBarSettings.js @@ -36,7 +36,7 @@ class AnnouncementBarSettings { announcement = announcementContent; } else if (visibilities.includes('free_members') && (member?.status === 'free')) { announcement = announcementContent; - } else if (visibilities.includes('paid_members') && (member?.status !== 'free')) { + } else if (visibilities.includes('paid_members') && (member && member.status !== 'free')) { announcement = announcementContent; } } diff --git a/ghost/announcement-bar-settings/test/AnnouncementBarSettings.test.js b/ghost/announcement-bar-settings/test/AnnouncementBarSettings.test.js index 47e78f7523..b7b38a6201 100644 --- a/ghost/announcement-bar-settings/test/AnnouncementBarSettings.test.js +++ b/ghost/announcement-bar-settings/test/AnnouncementBarSettings.test.js @@ -53,7 +53,7 @@ describe('AnnouncementBarSettings', function () { }); }); - it('returns announcement if visibility is set to free members and member is free', function () { + it('returns announcement if visibility is set to free_members and member is free', function () { testVisibility({ announcement: 'Hello world', announcement_visibility: ['free_members'], @@ -66,7 +66,7 @@ describe('AnnouncementBarSettings', function () { }); }); - it('returns announcement if visibility is set to paid members and member is paid', function () { + it('returns announcement if visibility is set to paid_members and member is paid', function () { testVisibility({ announcement: 'Hello world', announcement_visibility: ['paid_members'], @@ -79,7 +79,7 @@ describe('AnnouncementBarSettings', function () { }); }); - it('returns announcement if visibility is set to paid and paid members and member is comped', function () { + it('returns announcement if visibility is set to paid and paid_members and member is comped', function () { testVisibility({ announcement: 'Hello world', announcement_visibility: ['paid_members'], @@ -91,5 +91,44 @@ describe('AnnouncementBarSettings', function () { announcement_background: 'dark' }); }); + + 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); + }); }); });