Skipped notificaiton processing when no valid data

refs https://github.com/TryGhost/Team/issues/754

- When there are no message objects coming from the external update check service in the response there is no need to continue to process the data and fire off unneeded queries
This commit is contained in:
Naz 2021-06-23 19:14:47 +04:00
parent 65d863d74b
commit bc3ea7e12e
2 changed files with 43 additions and 1 deletions

View File

@ -283,7 +283,7 @@ class UpdateCheckService {
* @return {Promise}
*/
async createCustomNotification(notification) {
if (!notification) {
if (!notification || !notification.messages || notification.messages.length === 0) {
debug(`Skipping notification creation as there are no messages to process`);
return;
}

View File

@ -326,5 +326,47 @@ describe('Update Check', function () {
notificationsAPIAddStub.calledOnce.should.equal(true);
notificationsAPIAddStub.args[0][0].notifications.length.should.equal(1);
});
it('not create a notification if the check response has no messages', async function () {
const notificationsAPIAddStub = sinon.stub().resolves();
const updateCheckService = new UpdateCheckService({
api: {
settings: {
read: settingsStub,
edit: settingsStub
},
users: {
browse: sinon.stub().resolves({
users: [{
roles: [{
name: 'Owner'
}]
}]
})
},
posts: {
browse: sinon.stub().resolves()
},
notifications: {
add: notificationsAPIAddStub
}
},
config: {
siteUrl: 'https://localhost:2368/test'
},
i18n: i18nStub,
logging: loggingStub,
request: sinon.stub().resolves({
body: {
notifications: []
}
})
});
await updateCheckService.check();
notificationsAPIAddStub.calledOnce.should.equal(false);
});
});
});