7383-testToMaster #2445

Merged
alexm merged 233 commits from 7383-testToMaster into master 2024-05-14 05:44:13 +00:00
2 changed files with 12 additions and 15 deletions
Showing only changes of commit 4c55ae40ef - Show all commits

View File

@ -52,18 +52,16 @@ describe('Operator', () => {
}); });
it('should not sent notification when is already notified by another worker', async() => { it('should not sent notification when is already notified by another worker', async() => {
try { const {id} = await models.NotificationQueue.create({
await models.NotificationQueue.create({
authorFk: 2, authorFk: 2,
notificationFk: notificationName, notificationFk: notificationName,
params: JSON.stringify({'labelerId': labeler, 'sectorId': sectorId, 'workerId': 2}), params: JSON.stringify({'labelerId': labeler, 'sectorId': sectorId, 'workerId': 2}),
created: '2001-01-01 12:30:00', created: '2001-01-01 11:30:00',
status: sentStatus status: sentStatus
}); });
await models.Operator.updateAll({id: 1}, {labelerFk: labeler, sectorFk: sectorId}); const notificationQueue = await updateOperatorAndFindNotification();
} catch (e) {
expect(e.message).toEqual('Previous notification sended with the same parameters'); expect(notificationQueue.id).toEqual(id);
}
}); });
it('should send a notification when the previous one has distinct params', async() => { it('should send a notification when the previous one has distinct params', async() => {

View File

@ -18,7 +18,7 @@ module.exports = Self => {
const {backupPrinterNotificationDelay} = await models.ProductionConfig.findOne(); const {backupPrinterNotificationDelay} = await models.ProductionConfig.findOne();
if (backupPrinterNotificationDelay) { if (backupPrinterNotificationDelay) {
const notifications = await models.NotificationQueue.find( const notifications = await models.NotificationQueue.find(
{where: {created: {gte: Date.vnNow() - (backupPrinterNotificationDelay * 1000) + (3600 * 1000)}, {where: {created: {gte: new Date(Date.vnNow() - (backupPrinterNotificationDelay * 1000))},
notificationFk: notificationName, notificationFk: notificationName,
status: 'sent' status: 'sent'
} }
@ -30,8 +30,7 @@ module.exports = Self => {
return Object.keys(criteria).every(key => criteria[key] === paramsObj?.[key]); return Object.keys(criteria).every(key => criteria[key] === paramsObj?.[key]);
}); });
if (filteredNotifications.length >= 1) if (filteredNotifications.length >= 1) return;
throw new Error('Previous notification sended with the same parameters');
} }
await models.NotificationQueue.create({ await models.NotificationQueue.create({