feat(spec): refs #6005 add spec
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
59336b8588
commit
5e97f820a2
|
@ -45,7 +45,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
availableNotificationsMap.delete(active.notificationFk);
|
availableNotificationsMap.delete(active.notificationFk);
|
||||||
}
|
}
|
||||||
|
console.log(activeNotificationsMap);
|
||||||
return {
|
return {
|
||||||
active: [...activeNotificationsMap.entries()],
|
active: [...activeNotificationsMap.entries()],
|
||||||
available: [...availableNotificationsMap.entries()]
|
available: [...availableNotificationsMap.entries()]
|
||||||
|
|
|
@ -2,9 +2,10 @@ const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('NotificationSubscription getList()', () => {
|
describe('NotificationSubscription getList()', () => {
|
||||||
it('should return a list of available and active notifications of a user', async() => {
|
it('should return a list of available and active notifications of a user', async() => {
|
||||||
const {active, available} = await models.NotificationSubscription.getList(9);
|
const userId = 9;
|
||||||
const notifications = await models.Notification.find({});
|
const {active, available} = await models.NotificationSubscription.getList(userId);
|
||||||
const totalAvailable = notifications.length - active.length;
|
const notifications = await models.NotificationSubscription.getAvailable(userId);
|
||||||
|
const totalAvailable = notifications.size - active.length;
|
||||||
|
|
||||||
expect(active.length).toEqual(2);
|
expect(active.length).toEqual(2);
|
||||||
expect(available.length).toEqual(totalAvailable);
|
expect(available.length).toEqual(totalAvailable);
|
||||||
|
|
|
@ -2810,14 +2810,15 @@ INSERT INTO `vn`.`packingSiteConfig` (`shinobiUrl`, `shinobiToken`, `shinobiGrou
|
||||||
INSERT INTO `util`.`notificationConfig`
|
INSERT INTO `util`.`notificationConfig`
|
||||||
SET `cleanDays` = 90;
|
SET `cleanDays` = 90;
|
||||||
|
|
||||||
INSERT INTO `util`.`notification` (`id`, `name`, `description`)
|
INSERT INTO `util`.`notification` (`id`, `name`, `description`, `delay`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 'print-email', 'notification fixture one'),
|
(1, 'print-email', 'notification fixture one', NULL),
|
||||||
(2, 'invoice-electronic', 'A electronic invoice has been generated'),
|
(2, 'invoice-electronic', 'A electronic invoice has been generated', NULL),
|
||||||
(3, 'not-main-printer-configured', 'A printer distinct than main has been configured'),
|
(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'),
|
(4, 'supplier-pay-method-update', 'A supplier pay method has been updated', NULL),
|
||||||
(5, 'modified-entry', 'An entry has been modified'),
|
(5, 'modified-entry', 'An entry has been modified', NULL),
|
||||||
(6, 'book-entry-deleted', 'accounting entries deleted');
|
(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`)
|
INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
|
||||||
VALUES
|
VALUES
|
||||||
|
@ -2827,7 +2828,8 @@ INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`)
|
||||||
(3, 9),
|
(3, 9),
|
||||||
(4, 1),
|
(4, 1),
|
||||||
(5, 9),
|
(5, 9),
|
||||||
(6, 9);
|
(6, 9),
|
||||||
|
(7, 66);
|
||||||
|
|
||||||
INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`)
|
INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`)
|
||||||
VALUES
|
VALUES
|
||||||
|
@ -2844,7 +2846,8 @@ INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`)
|
||||||
(2, 1109),
|
(2, 1109),
|
||||||
(1, 9),
|
(1, 9),
|
||||||
(1, 3),
|
(1, 3),
|
||||||
(6, 9);
|
(6, 9),
|
||||||
|
(7, 66);
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
|
INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
describe('Operator', () => {
|
fdescribe('Operator', () => {
|
||||||
const authorFk = 9;
|
const authorFk = 9;
|
||||||
const sectorId = 1;
|
const sectorId = 1;
|
||||||
const labeler = 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({});
|
const tx = await models.Operator.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -74,15 +74,13 @@ describe('Operator', () => {
|
||||||
created: Date.vnNow(),
|
created: Date.vnNow(),
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
let error;
|
await createOperator(labeler, options);
|
||||||
|
await models.Notification.send(options);
|
||||||
|
const lastNotification = await models.NotificationQueue.find({order: 'id DESC'}, options);
|
||||||
|
|
||||||
try {
|
console.log('lastNotification: ', lastNotification);
|
||||||
await createOperator(labeler, options);
|
|
||||||
} catch (e) {
|
|
||||||
error = e;
|
|
||||||
}
|
|
||||||
|
|
||||||
expect(error.message).toEqual('Is already Notified');
|
expect(1).toEqual('Is already Notified');
|
||||||
|
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -5,8 +5,10 @@ const name = 'backup-printer-selected';
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: name,
|
name: name,
|
||||||
async serverPrefetch() {
|
async serverPrefetch() {
|
||||||
|
const notifications1 = await this.rawSqlFromDef('previousNotificationscopy', [name]);
|
||||||
|
console.log('notifications: ', notifications1);
|
||||||
const notifications = await this.rawSqlFromDef('previousNotifications', [name]);
|
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');
|
throw new Error('Previous notification sended with the same parameters');
|
||||||
|
|
||||||
this.sector = await this.findOneFromDef('sector', [this.sectorId]);
|
this.sector = await this.findOneFromDef('sector', [this.sectorId]);
|
||||||
|
@ -45,6 +47,5 @@ function checkDuplicates(notifications, labelerFk, printerFk) {
|
||||||
const paramsObj = JSON.parse(notification.params);
|
const paramsObj = JSON.parse(notification.params);
|
||||||
return Object.keys(criteria).every(key => criteria[key] === paramsObj[key]);
|
return Object.keys(criteria).every(key => criteria[key] === paramsObj[key]);
|
||||||
});
|
});
|
||||||
|
return filteredNotifications.length > 1;
|
||||||
return filteredNotifications.size > 1;
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
SELECT nq.params
|
||||||
|
FROM util.notificationQueue nq
|
||||||
|
JOIN util.notification n ON n.name = nq.notificationFk
|
||||||
|
WHERE n.name = ?
|
Loading…
Reference in New Issue