From e69fa71584c20efcb3eb175d8d88fc6b2338a099 Mon Sep 17 00:00:00 2001 From: Naz Date: Thu, 7 Oct 2021 18:16:58 +0200 Subject: [PATCH] Added basic unit test to cover notifications' service add method refs https://linear.app/tryghost/issue/CORE-64/resolve-undissmissable-update-notification-banners - We aim for full unit test coverage in our libraries and services. The very basic method coverage was missing so adding it! --- .../notifications/notifications.test.js | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/test/unit/server/services/notifications/notifications.test.js b/test/unit/server/services/notifications/notifications.test.js index 55d5a265c9..fe0f8bc2f6 100644 --- a/test/unit/server/services/notifications/notifications.test.js +++ b/test/unit/server/services/notifications/notifications.test.js @@ -1,6 +1,7 @@ const should = require('should'); const sinon = require('sinon'); +const moment = require('moment'); const Notifications = require('../../../../../core/server/services/notifications/notifications'); const {owner} = require('../../../../utils/fixtures/context'); @@ -154,6 +155,37 @@ describe('Notifications Service', function () { notifications.length.should.equal(0); }); + describe('add', function () { + it('adds a single notification when no previous exist', function () { + const existingNotifications = []; + const settingsCache = { + get: sinon.fake.returns(existingNotifications) + }; + + const notificationsSvc = new Notifications({ + settingsCache, + ghostVersion: { + full: '4.1.0' + } + }); + + const {allNotifications, notificationsToAdd} = notificationsSvc.add({ + notifications: [{ + custom: true, + createdAt: moment().toDate(), + status: 'alert', + type: 'info', + dismissible: true, + top: true, + message: 'Hello test world!' + }] + }); + + allNotifications.length.should.equal(0); + notificationsToAdd.length.should.equal(1); + }); + }); + describe('Stored notifications data corruption recovery', function () { it('should correct broken notifications data on browse', function () { const settingsCache = {