0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-03 23:00:14 -05:00

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!
This commit is contained in:
Naz 2021-10-07 18:16:58 +02:00
parent 7555020a49
commit e69fa71584

View file

@ -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 = {