feat(spec): refs #6005 add spec
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Pablo Natek 2024-02-21 12:59:42 +01:00
parent 59336b8588
commit 5e97f820a2
7 changed files with 32 additions and 25 deletions

View File

@ -45,7 +45,7 @@ module.exports = Self => {
});
availableNotificationsMap.delete(active.notificationFk);
}
console.log(activeNotificationsMap);
return {
active: [...activeNotificationsMap.entries()],
available: [...availableNotificationsMap.entries()]

View File

@ -2,9 +2,10 @@ const models = require('vn-loopback/server/server').models;
describe('NotificationSubscription getList()', () => {
it('should return a list of available and active notifications of a user', async() => {
const {active, available} = await models.NotificationSubscription.getList(9);
const notifications = await models.Notification.find({});
const totalAvailable = notifications.length - active.length;
const userId = 9;
const {active, available} = await models.NotificationSubscription.getList(userId);
const notifications = await models.NotificationSubscription.getAvailable(userId);
const totalAvailable = notifications.size - active.length;
expect(active.length).toEqual(2);
expect(available.length).toEqual(totalAvailable);

View File

@ -2810,14 +2810,15 @@ INSERT INTO `vn`.`packingSiteConfig` (`shinobiUrl`, `shinobiToken`, `shinobiGrou
INSERT INTO `util`.`notificationConfig`
SET `cleanDays` = 90;
INSERT INTO `util`.`notification` (`id`, `name`, `description`)
INSERT INTO `util`.`notification` (`id`, `name`, `description`, `delay`)
VALUES
(1, 'print-email', 'notification fixture one'),
(2, 'invoice-electronic', 'A electronic invoice has been generated'),
(3, 'not-main-printer-configured', 'A printer distinct than main has been configured'),
(4, 'supplier-pay-method-update', 'A supplier pay method has been updated'),
(5, 'modified-entry', 'An entry has been modified'),
(6, 'book-entry-deleted', 'accounting entries deleted');
(1, 'print-email', 'notification fixture one', NULL),
(2, 'invoice-electronic', 'A electronic invoice has been generated', NULL),
(3, 'not-main-printer-configured', 'A printer distinct than main has been configured', NULL),
(4, 'supplier-pay-method-update', 'A supplier pay method has been updated', NULL),
(5, 'modified-entry', 'An entry has been modified', NULL),
(6, 'book-entry-deleted', 'accounting entries deleted', NULL),
(7, 'backup-printer-selected','A backup printer has been selected', 3600);
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
VALUES
@ -2827,7 +2828,8 @@ INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
(3, 9),
(4, 1),
(5, 9),
(6, 9);
(6, 9),
(7, 66);
INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`)
VALUES
@ -2844,7 +2846,8 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`)
(2, 1109),
(1, 9),
(1, 3),
(6, 9);
(6, 9),
(7, 66);
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)

View File

@ -1,6 +1,6 @@
const models = require('vn-loopback/server/server').models;
describe('Operator', () => {
fdescribe('Operator', () => {
const authorFk = 9;
const sectorId = 1;
const labeler = 1;
@ -62,7 +62,7 @@ describe('Operator', () => {
}
});
it('should not create notification when is already notified by another worker', async() => {
fit('should not create notification when is already notified by another worker', async() => {
const tx = await models.Operator.beginTransaction({});
try {
@ -74,15 +74,13 @@ describe('Operator', () => {
created: Date.vnNow(),
}, options);
let error;
await createOperator(labeler, options);
await models.Notification.send(options);
const lastNotification = await models.NotificationQueue.find({order: 'id DESC'}, options);
try {
await createOperator(labeler, options);
} catch (e) {
error = e;
}
console.log('lastNotification: ', lastNotification);
expect(error.message).toEqual('Is already Notified');
expect(1).toEqual('Is already Notified');
await tx.rollback();
} catch (e) {

View File

@ -5,8 +5,10 @@ const name = 'backup-printer-selected';
module.exports = {
name: name,
async serverPrefetch() {
const notifications1 = await this.rawSqlFromDef('previousNotificationscopy', [name]);
console.log('notifications: ', notifications1);
const notifications = await this.rawSqlFromDef('previousNotifications', [name]);
if (notifications && checkDuplicates(notifications, this.labelerId, this.sectorId))
if (!notifications.length && checkDuplicates(notifications, this.labelerId, this.sectorId))
throw new Error('Previous notification sended with the same parameters');
this.sector = await this.findOneFromDef('sector', [this.sectorId]);
@ -45,6 +47,5 @@ function checkDuplicates(notifications, labelerFk, printerFk) {
const paramsObj = JSON.parse(notification.params);
return Object.keys(criteria).every(key => criteria[key] === paramsObj[key]);
});
return filteredNotifications.size > 1;
return filteredNotifications.length > 1;
}

View File

@ -0,0 +1,4 @@
SELECT nq.params
FROM util.notificationQueue nq
JOIN util.notification n ON n.name = nq.notificationFk
WHERE n.name = ?