0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Fixed update check tests

refs #12537

- Refactored overuse of rewire mocking blog-version.
- Fixed a bug introduced along the way when duplicate notifications errored instead of returning empty result
This commit is contained in:
Naz 2021-01-14 18:30:09 +13:00
parent cc9d987e94
commit 1cec604318
4 changed files with 34 additions and 30 deletions

View file

@ -30,15 +30,17 @@ module.exports = {
notifications: frame.data.notifications
});
return api.settings.edit({
settings: [{
key: 'notifications',
// @NOTE: We always need to store all notifications!
value: allNotifications.concat(notificationsToAdd)
}]
}, internalContext).then(() => {
return notificationsToAdd;
});
if (notificationsToAdd.length){
return api.settings.edit({
settings: [{
key: 'notifications',
// @NOTE: We always need to store all notifications!
value: allNotifications.concat(notificationsToAdd)
}]
}, internalContext).then(() => {
return notificationsToAdd;
});
}
}
},

View file

@ -30,15 +30,17 @@ module.exports = {
notifications: frame.data.notifications
});
return api.settings.edit({
settings: [{
key: 'notifications',
// @NOTE: We always need to store all notifications!
value: allNotifications.concat(notificationsToAdd)
}]
}, internalContext).then(() => {
return notificationsToAdd;
});
if (notificationsToAdd.length){
return api.settings.edit({
settings: [{
key: 'notifications',
// @NOTE: We always need to store all notifications!
value: allNotifications.concat(notificationsToAdd)
}]
}, internalContext).then(() => {
return notificationsToAdd;
});
}
}
},

View file

@ -107,7 +107,7 @@ class Notifications {
// CASE: nothing to add, skip
if (!notificationsToAdd.length) {
return Promise.resolve();
return {allNotifications, notificationsToAdd};
}
const releaseNotificationsToAdd = notificationsToAdd.filter((notification) => {

View file

@ -11,12 +11,12 @@ const packageInfo = require('../../../package.json');
const api = require('../../../core/server/api').v2;
let updateCheck = rewire('../../../core/server/update-check');
let NotificationsAPI = rewire('../../../core/server/api/v2/notifications');
let ghostVersion = rewire('../../../core/server/lib/ghost-version');
describe('Update Check', function () {
beforeEach(function () {
updateCheck = rewire('../../../core/server/update-check');
NotificationsAPI = rewire('../../../core/server/api/v2/notifications');
ghostVersion = rewire('../../../core/server/lib/ghost-version');
});
afterEach(function () {
@ -145,14 +145,19 @@ describe('Update Check', function () {
describe('fn: createCustomNotification', function () {
let currentVersionOrig;
let currentVersionFull;
before(function () {
currentVersionOrig = updateCheck.__get__('ghostVersion.original');
updateCheck.__set__('ghostVersion.original', '0.9.0');
currentVersionFull = updateCheck.__get__('ghostVersion.original');
ghostVersion.__set__('original', '0.9.0');
ghostVersion.__set__('full', '0.9.0');
});
after(function () {
updateCheck.__set__('ghostVersion.original', currentVersionOrig);
ghostVersion.__set__('original', currentVersionOrig);
ghostVersion.__set__('full', currentVersionFull);
});
beforeEach(testUtils.teardownDb);
@ -170,15 +175,13 @@ describe('Update Check', function () {
custom: 0,
messages: [{
id: uuid.v4(),
version: '0.9.x',
content: '<p>Hey there! This is for 0.9.0 version</p>',
version: '999.9.x',
content: '<p>Hey there! This is for 999.9.0 version</p>',
dismissible: true,
top: true
}]
};
NotificationsAPI.__set__('ghostVersion.full', '0.8.1');
createCustomNotification(notification).then(function () {
return api.notifications.browse(testUtils.context.internal);
}).then(function (results) {
@ -213,7 +216,6 @@ describe('Update Check', function () {
}]
};
NotificationsAPI.__set__('ghostVersion.full', '0.8.1');
createCustomNotification(notification).then(function () {
return api.notifications.browse(testUtils.context.internal);
@ -240,8 +242,6 @@ describe('Update Check', function () {
}]
};
NotificationsAPI.__set__('ghostVersion.full', '0.8');
createCustomNotification(notification).then(function () {
return api.notifications.browse(testUtils.context.internal);
}).then(function (results) {