Fixed failing notification update for non-major version

refs 4dc413d6a1

- Fixed failing test cases which were designed to check non-major upgrade messages. There's no clear use cases for those, but still worth keeping such case in mind
This commit is contained in:
Naz 2021-03-23 18:02:52 +13:00
parent 4dc413d6a1
commit 81a54a70bc
2 changed files with 30 additions and 5 deletions

View File

@ -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];

View File

@ -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: `<strong>Ghost 5.1.3 is now available</strong> - You are using an old version of Ghost, which means you don't have access to the latest features. <a href=\'https://ghost.org/changelog/4/\' target=\'_blank\' rel=\'noopener\'>Read more!</a>`,
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,