diff --git a/core/server/services/notifications/notifications.js b/core/server/services/notifications/notifications.js index b83e885893..422101f8f6 100644 --- a/core/server/services/notifications/notifications.js +++ b/core/server/services/notifications/notifications.js @@ -54,7 +54,7 @@ class Notifications { let notificationVersion = notification.message.match(/(\d+\.)(\d+\.)(\d+)/); const ghostMajorMatch = ghostMajorRegEx.exec(notification.message); - if (ghostMajorMatch.groups.major) { + if (ghostMajorMatch && ghostMajorMatch.groups && ghostMajorMatch.groups.major) { notificationVersion = `${ghostMajorMatch.groups.major}.0.0`; } else if (notificationVersion){ notificationVersion = notificationVersion[0]; diff --git a/test/unit/services/notifications/notifications_spec.js b/test/unit/services/notifications/notifications_spec.js index a9e7096d44..717197c579 100644 --- a/test/unit/services/notifications/notifications_spec.js +++ b/test/unit/services/notifications/notifications_spec.js @@ -5,7 +5,32 @@ const Notifications = require('../../../../core/server/services/notifications/no const {owner} = require('../../../utils/fixtures/context'); describe('Notifications Service', function () { - it('can browse major version upgrade notifications notifications', function () { + it('can browse non-major version upgrade notifications', function () { + const settingsCache = { + get: sinon.fake.returns([{ + dismissible: true, + id: '130f7c24-113a-4768-a698-12a8b34223f1', + type: 'info', + message: `Ghost 5.1.3 is now available - You are using an old version of Ghost, which means you don't have access to the latest features. Read more!`, + createdAt: '2021-03-16T12:55:20.000Z', + addedAt: '2021-03-17T01:41:20.906Z' + }]) + }; + + const notificationSvc = new Notifications({ + settingsCache, + ghostVersion: { + full: '4.1.0' + } + }); + + const notifications = notificationSvc.browse({user: owner}); + + should.exist(notifications); + notifications.length.should.equal(1); + }); + + it('can browse major version upgrade notifications', function () { const settingsCache = { get: sinon.fake.returns([{ dismissible: true, @@ -36,7 +61,7 @@ describe('Notifications Service', function () { notifications.length.should.equal(1); }); - it('cannot see 2.0 version upgrade notifications notifications in Ghost 3.0', function () { + it('cannot see 2.0 version upgrade notifications in Ghost 3.0', function () { const settingsCache = { get: sinon.fake.returns([{ dismissible: true, @@ -67,7 +92,7 @@ describe('Notifications Service', function () { notifications.length.should.equal(0); }); - it('cannot see 4.0 version upgrade notifications notifications in Ghost 4.0', function () { + it('cannot see 4.0 version upgrade notifications in Ghost 4.0', function () { const settingsCache = { get: sinon.fake.returns([{ dismissible: true, @@ -98,7 +123,7 @@ describe('Notifications Service', function () { notifications.length.should.equal(0); }); - it('cannot see 5.0 version upgrade notifications notifications in Ghost 5.0', function () { + it('cannot see 5.0 version upgrade notifications in Ghost 5.0', function () { const settingsCache = { get: sinon.fake.returns([{ dismissible: true,