From c9291197971f1b84a251dee0abf00fe6bcea77cd Mon Sep 17 00:00:00 2001 From: pablone Date: Tue, 28 Nov 2023 08:11:42 +0100 Subject: [PATCH] fix(spec): refs #6005 backupLabeler spec --- .../notification/specs/getList.spec.js | 5 +- .../specs/notificationSubscription.spec.js | 11 ++-- .../234801/00-sectorBackUpLabelerFk.sql | 19 ++++--- db/dump/dumpedFixtures.sql | 26 +++++++++ db/dump/fixtures.sql | 54 +++++++------------ db/export-data.sh | 2 + 6 files changed, 67 insertions(+), 50 deletions(-) diff --git a/back/methods/notification/specs/getList.spec.js b/back/methods/notification/specs/getList.spec.js index 52ac497a5..6c8507986 100644 --- a/back/methods/notification/specs/getList.spec.js +++ b/back/methods/notification/specs/getList.spec.js @@ -2,12 +2,11 @@ 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 userId = 9; - const {active, available} = await models.NotificationSubscription.getList(userId); + const {active, available} = await models.NotificationSubscription.getList(100); const notifications = await models.Notification.find({}); const totalAvailable = notifications.length - active.length; - expect(active.length).toEqual(2); + expect(active.length).toEqual(0); expect(available.length).toEqual(totalAvailable); }); }); diff --git a/back/models/specs/notificationSubscription.spec.js b/back/models/specs/notificationSubscription.spec.js index c2adcbc59..1d4b2354c 100644 --- a/back/models/specs/notificationSubscription.spec.js +++ b/back/models/specs/notificationSubscription.spec.js @@ -41,8 +41,7 @@ describe('loopback model NotificationSubscription', () => { try { const options = {transaction: tx, accessToken: {userId: 9}}; - const notificationSubscriptionId = 2; - await models.NotificationSubscription.destroyAll({id: notificationSubscriptionId}, options); + await models.NotificationSubscription.destroyAll({id: 2}, options); await tx.rollback(); } catch (e) { @@ -76,8 +75,7 @@ describe('loopback model NotificationSubscription', () => { try { const options = {transaction: tx, accessToken: {userId: 9}}; - const notificationSubscriptionId = 6; - await models.NotificationSubscription.destroyAll({id: notificationSubscriptionId}, options); + await models.NotificationSubscription.destroyAll({id: 6}, options); await tx.rollback(); } catch (e) { @@ -94,7 +92,7 @@ describe('loopback model NotificationSubscription', () => { try { const options = {transaction: tx, accessToken: {userId: 9}}; - await models.NotificationSubscription.create({notificationFk: 1, userFk: 5}, options); + await models.NotificationSubscription.create({notificationFk: 12, userFk: 5}, options); await tx.rollback(); } catch (e) { @@ -111,8 +109,7 @@ describe('loopback model NotificationSubscription', () => { try { const options = {transaction: tx, accessToken: {userId: 19}}; - const notificationSubscriptionId = 4; - await models.NotificationSubscription.destroyAll({id: notificationSubscriptionId}, options); + await models.NotificationSubscription.destroyAll({id: 4}, options); await tx.rollback(); } catch (e) { diff --git a/db/changes/234801/00-sectorBackUpLabelerFk.sql b/db/changes/234801/00-sectorBackUpLabelerFk.sql index bf7126693..605571fc8 100644 --- a/db/changes/234801/00-sectorBackUpLabelerFk.sql +++ b/db/changes/234801/00-sectorBackUpLabelerFk.sql @@ -9,15 +9,22 @@ ALTER TABLE `util`.`notificationAcl` DROP FOREIGN KEY `notificationAcl_ibfk_1`; ALTER TABLE `util`.`notification` MODIFY COLUMN `id` int(11) auto_increment NOT NULL; -ALTER TABLE `util`.`notificationSubscription` ADD CONSTRAINT `notificationSubscription_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`id`); -ALTER TABLE `util`.`notificationQueue` ADD CONSTRAINT `notificationQueue_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`name`); -ALTER TABLE `util`.`notificationAcl` ADD CONSTRAINT `notificationAcl_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`id`); +ALTER TABLE `util`.`notificationSubscription` ADD CONSTRAINT `notificationSubscription_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `util`.`notificationQueue` ADD CONSTRAINT `notificationQueue_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`name`) ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE `util`.`notificationAcl` ADD CONSTRAINT `notificationAcl_Fk` FOREIGN KEY (`notificationFk`) REFERENCES `util`.`notification`(`id`) ON DELETE CASCADE ON UPDATE CASCADE; DELETE FROM `util`.`notification` WHERE `name` = 'not-main-printer-configured'; -INSERT INTO `util`.`notification` - SET `id` = 15, - `name` = 'backup-printer-selected', +INSERT INTO `util`.`notification` + SET `name` = 'backup-printer-selected', `description` = 'The worker has selected the backup printer for their sector', `delay` = 600000; + +INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) + SELECT `n`.`id`, `r`.`id` + FROM `util`.`notification` `n` + JOIN `account`.`role` `r` + WHERE `n`.`name` = 'backup-printer-selected' + AND `r`.`name` = 'system' + LIMIT 1; diff --git a/db/dump/dumpedFixtures.sql b/db/dump/dumpedFixtures.sql index 3e46c8e04..3596eeb75 100644 --- a/db/dump/dumpedFixtures.sql +++ b/db/dump/dumpedFixtures.sql @@ -232,6 +232,32 @@ LOCK TABLES `agencyTermConfig` WRITE; /*!40000 ALTER TABLE `agencyTermConfig` DISABLE KEYS */; INSERT INTO `agencyTermConfig` VALUES ('6240000000','4721000015',21.0000000000,'Adquisiciones intracomunitarias de servicios'); /*!40000 ALTER TABLE `agencyTermConfig` ENABLE KEYS */; +UNLOCK TABLES; + +LOCK TABLES `notification` WRITE; +INSERT INTO `util`.`notification` (id, name, description) + VALUES(1, 'vehicle-event-expired', 'scheduled event of a vehicle'), + (2, 'invoice-electronic', 'A electronic invoice has been generated'), + (3, 'supplier-pay-method-update', 'A supplier pay method has been updated'), + (4, 'book-entries-imported-incorrectly', 'accounting entries exported incorrectly'), + (5, 'greuge-wrong', 'A wrong greuge has been created'), + (6, 'not-main-printer-configured', 'A printer distinct than main has been configured'), + (7, 'entry-update-comission', 'entry change comission'), + (8, 'modified-entry', 'An entry has been modified'), + (9, 'book-entry-deleted', 'accounting entries deleted'), + (10, 'modified-collection-volumetry', 'A collection volumetry has been modified'); +UNLOCK TABLES; + +LOCK TABLES `notificationAcl` WRITE; +INSERT INTO `util`.`notificationAcl` (notificationFk, roleFk) + VALUES(1, 57), + (3, 73), + (4, 5), + (6, 108), + (7, 30), + (7, 35), + (8, 15), + (9, 5); UNLOCK TABLES; -- diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 870f56a30..3215e6164 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2780,49 +2780,35 @@ INSERT INTO `vn`.`packingSite` (`id`, `code`, `hostFk`, `monitorId`) INSERT INTO `vn`.`packingSiteConfig` (`shinobiUrl`, `shinobiToken`, `shinobiGroupKey`, `avgBoxingTime`) VALUES ('', 'SHINNOBI_TOKEN', 'GROUP_TOKEN', 6000); -INSERT INTO `util`.`notificationConfig` - SET `cleanDays` = 90; - -INSERT IGNORE INTO `util`.`notification` (`id`, `name`, `description`, `delay`) - VALUES - (1, 'print-email', 'notification fixture one', NULL), - (2, 'invoice-electronic', 'A electronic invoice has been generated', NULL), - (3, 'backup-printer-selected', 'A printer distinct than main has been configured', 600000), - (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); -UPDATE `util`.`notification` - SET `id` = 3 - WHERE `name` = 'backup-printer-selected'; +INSERT INTO `util`.`notificationConfig` + SET `cleanDays` = 90; -INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) - VALUES - (1, 9), - (1, 1), - (2, 1), - (3, 9), - (4, 1), - (5, 9), - (6, 9); +INSERT IGNORE INTO `util`.`notification` (`name`, `description`, `delay`) + VALUES ('print-email', 'notification fixture one', NULL); -INSERT INTO `util`.`notificationQueue` (`id`, `notificationFk`, `params`, `authorFk`, `status`, `created`) - VALUES - (1, 'print-email', '{"id": "1"}', 9, 'pending', util.VN_CURDATE()), - (2, 'print-email', '{"id": "2"}', null, 'pending', util.VN_CURDATE()), - (3, 'print-email', null, null, 'pending', util.VN_CURDATE()); +INSERT INTO `util`.`notificationQueue` (`notificationFk`, `params`, `authorFk`, `status`, `created`) + VALUES ('print-email', '{"id": "1"}', 9, 'pending', util.VN_CURDATE()), + ('print-email', '{"id": "2"}', null, 'pending', util.VN_CURDATE()), + ('print-email', null, null, 'pending', util.VN_CURDATE()); INSERT INTO `util`.`notificationSubscription` (`notificationFk`, `userFk`) - VALUES - (1, 1109), - (1, 1110), + VALUES (12, 1109), + (12, 1110), (2, 1110), (4, 1110), (2, 1109), - (1, 9), - (1, 3), - (6, 9); + (12, 9), + (12, 3); +INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) + VALUES (12, 9), + (12, 1), + (4, 1), + (2, 1), + (3, 9), + (5, 9), + (10,1); INSERT INTO `vn`.`routeConfig` (`id`, `defaultWorkCenterFk`) VALUES diff --git a/db/export-data.sh b/db/export-data.sh index 97092da4f..96a8754f9 100755 --- a/db/export-data.sh +++ b/db/export-data.sh @@ -16,6 +16,8 @@ TABLES=( config version versionLog + notification + notificationAcl ) dump_tables ${TABLES[@]}