From ded8e0e141d2a8612ec5c0f64ae6b4243cd0d8a2 Mon Sep 17 00:00:00 2001 From: alexandre Date: Wed, 10 May 2023 13:22:53 +0200 Subject: [PATCH 1/7] refs #5137 added trigger, template and test --- db/changes/232001/.gitkeep | 0 db/changes/232001/00-printer.sql | 3 + db/dump/fixtures.sql | 3 + modules/shelving/back/models/sector.json | 4 +- .../methods/operator/spec/operator.spec.js | 63 +++++++++++++++++++ modules/worker/back/models/operator.js | 30 +++++++++ modules/worker/back/models/operator.json | 6 +- .../assets/css/import.js | 11 ++++ .../not-main-printer-configured/locale/en.yml | 3 + .../not-main-printer-configured/locale/es.yml | 3 + .../not-main-printer-configured.html | 8 +++ .../not-main-printer-configured.js | 27 ++++++++ 12 files changed, 156 insertions(+), 5 deletions(-) delete mode 100644 db/changes/232001/.gitkeep create mode 100644 db/changes/232001/00-printer.sql create mode 100644 modules/worker/back/methods/operator/spec/operator.spec.js create mode 100644 modules/worker/back/models/operator.js create mode 100644 print/templates/email/not-main-printer-configured/assets/css/import.js create mode 100644 print/templates/email/not-main-printer-configured/locale/en.yml create mode 100644 print/templates/email/not-main-printer-configured/locale/es.yml create mode 100644 print/templates/email/not-main-printer-configured/not-main-printer-configured.html create mode 100755 print/templates/email/not-main-printer-configured/not-main-printer-configured.js diff --git a/db/changes/232001/.gitkeep b/db/changes/232001/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/232001/00-printer.sql b/db/changes/232001/00-printer.sql new file mode 100644 index 000000000..6280c2c6d --- /dev/null +++ b/db/changes/232001/00-printer.sql @@ -0,0 +1,3 @@ +ALTER TABLE `vn`.`sector` DROP COLUMN `printerFk`; +ALTER TABLE `vn`.`sector` ADD COLUMN `mainPrinterFk` tinyint(3) unsigned; +ALTER TABLE `vn`.`sector` ADD CONSTRAINT sector_FK_1 FOREIGN KEY (mainPrinterFk) REFERENCES vn.printer(id) ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e69974d08..79924292e 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -179,6 +179,8 @@ INSERT INTO `vn`.`printer` (`id`, `name`, `path`, `isLabeler`, `sectorFk`, `ipAd (2, 'printer2', 'path2', 1, 1 , NULL), (4, 'printer4', 'path4', 0, NULL, '10.1.10.4'); +UPDATE `vn`.`sector` SET mainPrinterFk = 1 WHERE id = 1; + INSERT INTO `vn`.`worker`(`id`, `code`, `firstName`, `lastName`, `userFk`,`bossFk`, `phone`, `sectorFk`, `labelerFk`) VALUES (1106, 'LGN', 'David Charles', 'Haller', 1106, 19, 432978106, NULL, NULL), @@ -2719,6 +2721,7 @@ INSERT INTO `util`.`notification` (`id`, `name`, `description`) 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'); INSERT INTO `util`.`notificationAcl` (`notificationFk`, `roleFk`) diff --git a/modules/shelving/back/models/sector.json b/modules/shelving/back/models/sector.json index 0dc502cd0..47d66bd8d 100644 --- a/modules/shelving/back/models/sector.json +++ b/modules/shelving/back/models/sector.json @@ -56,7 +56,7 @@ "type": "number", "required": false }, - "printerFk": { + "mainPrinterFk": { "type": "number", "required": false }, @@ -69,4 +69,4 @@ "required": true } } -} \ No newline at end of file +} diff --git a/modules/worker/back/methods/operator/spec/operator.spec.js b/modules/worker/back/methods/operator/spec/operator.spec.js new file mode 100644 index 000000000..5f099040a --- /dev/null +++ b/modules/worker/back/methods/operator/spec/operator.spec.js @@ -0,0 +1,63 @@ +const models = require('vn-loopback/server/server').models; + +describe('Operator', () => { + const authorFk = 9; + const sectorId = 1; + const mainPrinter = 1; + const notificationName = 'not-main-printer-configured'; + const operator = { + workerFk: 1, + trainFk: 1, + itemPackingTypeFk: 'H', + warehouseFk: 1, + sectorFk: sectorId + }; + + async function createOperator(labelerFk, options) { + operator.labelerFk = labelerFk; + await models.Operator.create(operator, options); + return models.NotificationQueue.findOne({ + where: { + notificationFk: notificationName + } + }, options); + } + + it('should create notification when configured a not main printer in the sector', async() => { + const tx = await models.Operator.beginTransaction({}); + + try { + const options = {transaction: tx, accessToken: {userId: authorFk}}; + const notificationQueue = await createOperator(2, options); + const params = JSON.parse(notificationQueue.params); + + expect(notificationQueue.notificationFk).toEqual(notificationName); + expect(notificationQueue.authorFk).toEqual(authorFk); + expect(params.labeler).toContain('2'); + expect(params.sector).toContain('1'); + expect(params.mainPrinter).toContain('1'); + expect(params.worker).toContain('9'); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should not create notification when configured the main printer in the sector', async() => { + const tx = await models.Operator.beginTransaction({}); + + try { + const options = {transaction: tx, accessToken: {userId: authorFk}}; + const notificationQueue = await createOperator(mainPrinter, options); + + expect(notificationQueue).toEqual(null); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js new file mode 100644 index 000000000..d2887111c --- /dev/null +++ b/modules/worker/back/models/operator.js @@ -0,0 +1,30 @@ +module.exports = function(Self) { + Self.observe('after save', async function(ctx) { + const instance = ctx.instance; + const models = Self.app.models; + const options = ctx.options; + + if (!instance.sectorFk || !instance.labelerFk) return; + const sector = await models.Sector.findById(instance.sectorFk, { + fields: ['description', 'mainPrinterFk'] + }, options); + if (sector.mainPrinterFk && sector.mainPrinterFk != instance.labelerFk) { + const userId = ctx.options.accessToken.userId; + const user = await models.VnUser.findById(userId, {fields: ['nickname']}, options); + const labeler = await models.Printer.findById(instance.labelerFk, {fields: ['name']}, options); + const mainPrinter = await models.Printer.findById(sector.mainPrinterFk, {fields: ['name']}, options); + await models.NotificationQueue.create({ + notificationFk: 'not-main-printer-configured', + authorFk: userId, + params: JSON.stringify( + { + 'labeler': `#${instance.labelerFk} ${labeler.name}`, + 'sector': `#${instance.sectorFk} ${sector.description}`, + 'mainPrinter': `#${sector.mainPrinterFk} ${mainPrinter.name}`, + 'worker': `#${userId} ${user.nickname}` + } + ) + }, options); + } + }); +}; diff --git a/modules/worker/back/models/operator.json b/modules/worker/back/models/operator.json index db8a8c451..9433a0fd5 100644 --- a/modules/worker/back/models/operator.json +++ b/modules/worker/back/models/operator.json @@ -27,10 +27,10 @@ "type": "number", "required": true }, - "sectorFk ": { + "sectorFk": { "type": "number" }, - "labelerFk ": { + "labelerFk": { "type": "number" } }, @@ -41,4 +41,4 @@ "foreignKey": "sectorFk" } } -} \ No newline at end of file +} diff --git a/print/templates/email/not-main-printer-configured/assets/css/import.js b/print/templates/email/not-main-printer-configured/assets/css/import.js new file mode 100644 index 000000000..4b4bb7086 --- /dev/null +++ b/print/templates/email/not-main-printer-configured/assets/css/import.js @@ -0,0 +1,11 @@ +const Stylesheet = require(`vn-print/core/stylesheet`); + +const path = require('path'); +const vnPrintPath = path.resolve('print'); + +module.exports = new Stylesheet([ + `${vnPrintPath}/common/css/spacing.css`, + `${vnPrintPath}/common/css/misc.css`, + `${vnPrintPath}/common/css/layout.css`, + `${vnPrintPath}/common/css/email.css`]) + .mergeStyles(); diff --git a/print/templates/email/not-main-printer-configured/locale/en.yml b/print/templates/email/not-main-printer-configured/locale/en.yml new file mode 100644 index 000000000..5da9d2595 --- /dev/null +++ b/print/templates/email/not-main-printer-configured/locale/en.yml @@ -0,0 +1,3 @@ +subject: Not main printer configured +title: Not main printer configured +description: Printer {0} has been configured in sector {1} (the main printer for that sector is {2}). Ask the worker {3} diff --git a/print/templates/email/not-main-printer-configured/locale/es.yml b/print/templates/email/not-main-printer-configured/locale/es.yml new file mode 100644 index 000000000..a8b207a54 --- /dev/null +++ b/print/templates/email/not-main-printer-configured/locale/es.yml @@ -0,0 +1,3 @@ +subject: Configurada impresora no principal +title: Configurada impresora no principal +description: Se ha configurado la impresora {0} en el sector {1} (la impresora principal de ese sector es la {2}). Preguntar al trabajador {3}. diff --git a/print/templates/email/not-main-printer-configured/not-main-printer-configured.html b/print/templates/email/not-main-printer-configured/not-main-printer-configured.html new file mode 100644 index 000000000..06ab6d0b0 --- /dev/null +++ b/print/templates/email/not-main-printer-configured/not-main-printer-configured.html @@ -0,0 +1,8 @@ + +
+
+

{{ $t('title') }}

+

+
+
+
diff --git a/print/templates/email/not-main-printer-configured/not-main-printer-configured.js b/print/templates/email/not-main-printer-configured/not-main-printer-configured.js new file mode 100755 index 000000000..2c3e3521a --- /dev/null +++ b/print/templates/email/not-main-printer-configured/not-main-printer-configured.js @@ -0,0 +1,27 @@ +const Component = require(`vn-print/core/component`); +const emailBody = new Component('email-body'); + +module.exports = { + name: 'not-main-printer-configured', + components: { + 'email-body': emailBody.build(), + }, + props: { + labeler: { + type: String, + required: true + }, + sector: { + type: String, + required: true + }, + mainPrinter: { + type: String, + required: true + }, + worker: { + type: String, + required: true + } + } +}; From 62d0af25d3504ed399292b4cf34f6c08aa70416d Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 16 May 2023 13:31:22 +0200 Subject: [PATCH 2/7] refs #5642 uncommented tests --- .../05-ticket/01-sale/02_edit_sale.spec.js | 2 +- e2e/paths/05-ticket/21_future.spec.js | 91 +++++++++---------- e2e/paths/05-ticket/22_advance.spec.js | 63 +++++++------ 3 files changed, 77 insertions(+), 79 deletions(-) diff --git a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js index 2c9646708..a87e00543 100644 --- a/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js +++ b/e2e/paths/05-ticket/01-sale/02_edit_sale.spec.js @@ -316,7 +316,7 @@ describe('Ticket Edit sale path', () => { it('should confirm the transfered quantity is the correct one', async() => { const result = await page.waitToGetProperty(selectors.ticketSales.secondSaleQuantityCell, 'innerText'); - expect(result).toContain('10'); + expect(result).toContain('20'); }); it('should go back to the original ticket sales section', async() => { diff --git a/e2e/paths/05-ticket/21_future.spec.js b/e2e/paths/05-ticket/21_future.spec.js index 82525c1db..1a101e9f1 100644 --- a/e2e/paths/05-ticket/21_future.spec.js +++ b/e2e/paths/05-ticket/21_future.spec.js @@ -1,8 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -// 'https:// redmine.verdnatura.es/issues/5642' -xdescribe('Ticket Future path', () => { +describe('Ticket Future path', () => { let browser; let page; let httpRequest; @@ -45,67 +44,67 @@ xdescribe('Ticket Future path', () => { expect(message.text).toContain('originDated is a required argument'); }); - // it('should search with the required data', async() => { - // await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); - // await page.waitToClick(selectors.ticketFuture.submit); + it('should search with the required data', async() => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketFuture.submit); - // expect(httpRequest).toBeDefined(); - // }); + expect(httpRequest).toBeDefined(); + }); - // it('should search with the origin IPT', async() => { - // await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + it('should search with the origin IPT', async() => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); - // await page.autocompleteSearch(selectors.ticketFuture.ipt, 'H'); - // await page.waitToClick(selectors.ticketFuture.submit); + await page.autocompleteSearch(selectors.ticketFuture.ipt, 'H'); + await page.waitToClick(selectors.ticketFuture.submit); - // expect(httpRequest).toContain('ipt=H'); - // }); + expect(httpRequest).toContain('ipt=H'); + }); - // it('should search with the destination IPT', async() => { - // await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + it('should search with the destination IPT', async() => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); - // await page.clearInput(selectors.ticketFuture.ipt); + await page.clearInput(selectors.ticketFuture.ipt); - // await page.autocompleteSearch(selectors.ticketFuture.futureIpt, 'H'); - // await page.waitToClick(selectors.ticketFuture.submit); + await page.autocompleteSearch(selectors.ticketFuture.futureIpt, 'H'); + await page.waitToClick(selectors.ticketFuture.submit); - // expect(httpRequest).toContain('futureIpt=H'); - // }); + expect(httpRequest).toContain('futureIpt=H'); + }); - // it('should search with the origin grouped state', async() => { - // await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + it('should search with the origin grouped state', async() => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); - // await page.clearInput(selectors.ticketFuture.futureIpt); + await page.clearInput(selectors.ticketFuture.futureIpt); - // await page.autocompleteSearch(selectors.ticketFuture.state, 'Free'); - // await page.waitToClick(selectors.ticketFuture.submit); + await page.autocompleteSearch(selectors.ticketFuture.state, 'Free'); + await page.waitToClick(selectors.ticketFuture.submit); - // expect(httpRequest).toContain('state=FREE'); - // }); + expect(httpRequest).toContain('state=FREE'); + }); - // it('should search with the destination grouped state', async() => { - // await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + it('should search with the destination grouped state', async() => { + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); - // await page.clearInput(selectors.ticketFuture.state); + await page.clearInput(selectors.ticketFuture.state); - // await page.autocompleteSearch(selectors.ticketFuture.futureState, 'Free'); - // await page.waitToClick(selectors.ticketFuture.submit); + await page.autocompleteSearch(selectors.ticketFuture.futureState, 'Free'); + await page.waitToClick(selectors.ticketFuture.submit); - // expect(httpRequest).toContain('futureState=FREE'); + expect(httpRequest).toContain('futureState=FREE'); - // await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); - // await page.clearInput(selectors.ticketFuture.futureState); - // await page.waitToClick(selectors.ticketFuture.submit); - // }); + await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.clearInput(selectors.ticketFuture.futureState); + await page.waitToClick(selectors.ticketFuture.submit); + }); - // it('should check the three last tickets and move to the future', async() => { - // await page.waitForNumberOfElements(selectors.ticketFuture.searchResult, 4); - // await page.waitToClick(selectors.ticketFuture.multiCheck); - // await page.waitToClick(selectors.ticketFuture.firstCheck); - // await page.waitToClick(selectors.ticketFuture.moveButton); - // await page.waitToClick(selectors.globalItems.acceptButton); - // const message = await page.waitForSnackbar(); + it('should check the three last tickets and move to the future', async() => { + await page.waitForNumberOfElements(selectors.ticketFuture.searchResult, 4); + await page.waitToClick(selectors.ticketFuture.multiCheck); + await page.waitToClick(selectors.ticketFuture.firstCheck); + await page.waitToClick(selectors.ticketFuture.moveButton); + await page.waitToClick(selectors.globalItems.acceptButton); + const message = await page.waitForSnackbar(); - // expect(message.text).toContain('Tickets moved successfully!'); - // }); + expect(message.text).toContain('Tickets moved successfully!'); + }); }); diff --git a/e2e/paths/05-ticket/22_advance.spec.js b/e2e/paths/05-ticket/22_advance.spec.js index f27120b3b..d845219c5 100644 --- a/e2e/paths/05-ticket/22_advance.spec.js +++ b/e2e/paths/05-ticket/22_advance.spec.js @@ -1,8 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -// 'https:// redmine.verdnatura.es/issues/5642' -xdescribe('Ticket Advance path', () => { +describe('Ticket Advance path', () => { let browser; let page; let httpRequest; @@ -46,43 +45,43 @@ xdescribe('Ticket Advance path', () => { expect(message.text).toContain('dateFuture is a required argument'); }); - // it('should search with the required data', async() => { - // await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - // await page.waitToClick(selectors.ticketAdvance.submit); + it('should search with the required data', async() => { + await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); + await page.waitToClick(selectors.ticketAdvance.submit); - // expect(httpRequest).toBeDefined(); - // }); + expect(httpRequest).toBeDefined(); + }); - // it('should search with the origin IPT', async() => { - // await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - // await page.autocompleteSearch(selectors.ticketAdvance.futureIpt, 'H'); - // await page.waitToClick(selectors.ticketAdvance.submit); + it('should search with the origin IPT', async() => { + await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); + await page.autocompleteSearch(selectors.ticketAdvance.futureIpt, 'H'); + await page.waitToClick(selectors.ticketAdvance.submit); - // expect(httpRequest).toContain('futureIpt=H'); + expect(httpRequest).toContain('futureIpt=H'); - // await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - // await page.clearInput(selectors.ticketAdvance.futureIpt); - // await page.waitToClick(selectors.ticketAdvance.submit); - // }); + await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); + await page.clearInput(selectors.ticketAdvance.futureIpt); + await page.waitToClick(selectors.ticketAdvance.submit); + }); - // it('should search with the destination IPT', async() => { - // await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - // await page.autocompleteSearch(selectors.ticketAdvance.ipt, 'H'); - // await page.waitToClick(selectors.ticketAdvance.submit); + it('should search with the destination IPT', async() => { + await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); + await page.autocompleteSearch(selectors.ticketAdvance.ipt, 'H'); + await page.waitToClick(selectors.ticketAdvance.submit); - // expect(httpRequest).toContain('ipt=H'); + expect(httpRequest).toContain('ipt=H'); - // await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); - // await page.clearInput(selectors.ticketAdvance.ipt); - // await page.waitToClick(selectors.ticketAdvance.submit); - // }); + await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); + await page.clearInput(selectors.ticketAdvance.ipt); + await page.waitToClick(selectors.ticketAdvance.submit); + }); - // it('should check the first ticket and move to the present', async() => { - // await page.waitToClick(selectors.ticketAdvance.firstCheck); - // await page.waitToClick(selectors.ticketAdvance.moveButton); - // await page.waitToClick(selectors.ticketAdvance.acceptButton); - // const message = await page.waitForSnackbar(); + it('should check the first ticket and move to the present', async() => { + await page.waitToClick(selectors.ticketAdvance.firstCheck); + await page.waitToClick(selectors.ticketAdvance.moveButton); + await page.waitToClick(selectors.ticketAdvance.acceptButton); + const message = await page.waitForSnackbar(); - // expect(message.text).toContain('Tickets moved successfully!'); - // }); + expect(message.text).toContain('Tickets moved successfully!'); + }); }); From ca9d76db77a54e9929be16079eeff7e54958bdf7 Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 18 May 2023 14:47:41 +0200 Subject: [PATCH 3/7] refs #5137 moved sql --- db/changes/232201/.gitkeep | 0 db/changes/{232001 => 232201}/00-printer.sql | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 db/changes/232201/.gitkeep rename db/changes/{232001 => 232201}/00-printer.sql (100%) diff --git a/db/changes/232201/.gitkeep b/db/changes/232201/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/232001/00-printer.sql b/db/changes/232201/00-printer.sql similarity index 100% rename from db/changes/232001/00-printer.sql rename to db/changes/232201/00-printer.sql From 1ed8000be963c101867397e8804035a15af8e15c Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 29 May 2023 09:58:49 +0200 Subject: [PATCH 4/7] refs #5642 e2es refactored --- e2e/paths/05-ticket/21_future.spec.js | 17 +++-------------- e2e/paths/05-ticket/22_advance.spec.js | 12 ++---------- 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/e2e/paths/05-ticket/21_future.spec.js b/e2e/paths/05-ticket/21_future.spec.js index 1a101e9f1..c854dcbaf 100644 --- a/e2e/paths/05-ticket/21_future.spec.js +++ b/e2e/paths/05-ticket/21_future.spec.js @@ -21,7 +21,7 @@ describe('Ticket Future path', () => { await browser.close(); }); - it('should show errors snackbar because of the required data', async() => { + it('should search with required data, check three last tickets and move to the future', async() => { await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); await page.clearInput(selectors.ticketFuture.warehouseFk); await page.waitToClick(selectors.ticketFuture.submit); @@ -42,25 +42,19 @@ describe('Ticket Future path', () => { message = await page.waitForSnackbar(); expect(message.text).toContain('originDated is a required argument'); - }); - it('should search with the required data', async() => { await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); await page.waitToClick(selectors.ticketFuture.submit); expect(httpRequest).toBeDefined(); - }); - it('should search with the origin IPT', async() => { await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); await page.autocompleteSearch(selectors.ticketFuture.ipt, 'H'); await page.waitToClick(selectors.ticketFuture.submit); expect(httpRequest).toContain('ipt=H'); - }); - it('should search with the destination IPT', async() => { await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); await page.clearInput(selectors.ticketFuture.ipt); @@ -69,9 +63,7 @@ describe('Ticket Future path', () => { await page.waitToClick(selectors.ticketFuture.submit); expect(httpRequest).toContain('futureIpt=H'); - }); - it('should search with the origin grouped state', async() => { await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); await page.clearInput(selectors.ticketFuture.futureIpt); @@ -80,9 +72,7 @@ describe('Ticket Future path', () => { await page.waitToClick(selectors.ticketFuture.submit); expect(httpRequest).toContain('state=FREE'); - }); - it('should search with the destination grouped state', async() => { await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); await page.clearInput(selectors.ticketFuture.state); @@ -93,17 +83,16 @@ describe('Ticket Future path', () => { expect(httpRequest).toContain('futureState=FREE'); await page.waitToClick(selectors.ticketFuture.openAdvancedSearchButton); + await page.clearInput(selectors.ticketFuture.state); await page.clearInput(selectors.ticketFuture.futureState); await page.waitToClick(selectors.ticketFuture.submit); - }); - it('should check the three last tickets and move to the future', async() => { await page.waitForNumberOfElements(selectors.ticketFuture.searchResult, 4); await page.waitToClick(selectors.ticketFuture.multiCheck); await page.waitToClick(selectors.ticketFuture.firstCheck); await page.waitToClick(selectors.ticketFuture.moveButton); await page.waitToClick(selectors.globalItems.acceptButton); - const message = await page.waitForSnackbar(); + message = await page.waitForSnackbar(); expect(message.text).toContain('Tickets moved successfully!'); }); diff --git a/e2e/paths/05-ticket/22_advance.spec.js b/e2e/paths/05-ticket/22_advance.spec.js index d845219c5..0e5b5e0c3 100644 --- a/e2e/paths/05-ticket/22_advance.spec.js +++ b/e2e/paths/05-ticket/22_advance.spec.js @@ -21,7 +21,7 @@ describe('Ticket Advance path', () => { await browser.close(); }); - it('should show errors snackbar because of the required data', async() => { + it('should search with the required data, check the first ticket and move to the present', async() => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.clearInput(selectors.ticketAdvance.warehouseFk); @@ -43,16 +43,12 @@ describe('Ticket Advance path', () => { message = await page.waitForSnackbar(); expect(message.text).toContain('dateFuture is a required argument'); - }); - it('should search with the required data', async() => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.waitToClick(selectors.ticketAdvance.submit); expect(httpRequest).toBeDefined(); - }); - it('should search with the origin IPT', async() => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.autocompleteSearch(selectors.ticketAdvance.futureIpt, 'H'); await page.waitToClick(selectors.ticketAdvance.submit); @@ -62,9 +58,7 @@ describe('Ticket Advance path', () => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.clearInput(selectors.ticketAdvance.futureIpt); await page.waitToClick(selectors.ticketAdvance.submit); - }); - it('should search with the destination IPT', async() => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.autocompleteSearch(selectors.ticketAdvance.ipt, 'H'); await page.waitToClick(selectors.ticketAdvance.submit); @@ -74,13 +68,11 @@ describe('Ticket Advance path', () => { await page.waitToClick(selectors.ticketAdvance.openAdvancedSearchButton); await page.clearInput(selectors.ticketAdvance.ipt); await page.waitToClick(selectors.ticketAdvance.submit); - }); - it('should check the first ticket and move to the present', async() => { await page.waitToClick(selectors.ticketAdvance.firstCheck); await page.waitToClick(selectors.ticketAdvance.moveButton); await page.waitToClick(selectors.ticketAdvance.acceptButton); - const message = await page.waitForSnackbar(); + message = await page.waitForSnackbar(); expect(message.text).toContain('Tickets moved successfully!'); }); From 059467a383b09b176d4ef02b2ff97d9d0a9fbba5 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 29 May 2023 12:55:20 +0200 Subject: [PATCH 5/7] refs #5137 sql moved to template --- modules/worker/back/models/operator.js | 14 +++++----- .../not-main-printer-configured/locale/en.yml | 2 +- .../not-main-printer-configured/locale/es.yml | 2 +- .../not-main-printer-configured.html | 2 +- .../not-main-printer-configured.js | 26 ++++++++++++------- .../sql/printer.sql | 3 +++ .../sql/sector.sql | 3 +++ .../sql/worker.sql | 3 +++ 8 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 print/templates/email/not-main-printer-configured/sql/printer.sql create mode 100644 print/templates/email/not-main-printer-configured/sql/sector.sql create mode 100644 print/templates/email/not-main-printer-configured/sql/worker.sql diff --git a/modules/worker/back/models/operator.js b/modules/worker/back/models/operator.js index d2887111c..e9b590fa6 100644 --- a/modules/worker/back/models/operator.js +++ b/modules/worker/back/models/operator.js @@ -5,23 +5,21 @@ module.exports = function(Self) { const options = ctx.options; if (!instance.sectorFk || !instance.labelerFk) return; + const sector = await models.Sector.findById(instance.sectorFk, { - fields: ['description', 'mainPrinterFk'] + fields: ['mainPrinterFk'] }, options); + if (sector.mainPrinterFk && sector.mainPrinterFk != instance.labelerFk) { const userId = ctx.options.accessToken.userId; - const user = await models.VnUser.findById(userId, {fields: ['nickname']}, options); - const labeler = await models.Printer.findById(instance.labelerFk, {fields: ['name']}, options); - const mainPrinter = await models.Printer.findById(sector.mainPrinterFk, {fields: ['name']}, options); await models.NotificationQueue.create({ notificationFk: 'not-main-printer-configured', authorFk: userId, params: JSON.stringify( { - 'labeler': `#${instance.labelerFk} ${labeler.name}`, - 'sector': `#${instance.sectorFk} ${sector.description}`, - 'mainPrinter': `#${sector.mainPrinterFk} ${mainPrinter.name}`, - 'worker': `#${userId} ${user.nickname}` + 'labelerId': instance.labelerFk, + 'sectorId': instance.sectorFk, + 'workerId': userId } ) }, options); diff --git a/print/templates/email/not-main-printer-configured/locale/en.yml b/print/templates/email/not-main-printer-configured/locale/en.yml index 5da9d2595..2a3051145 100644 --- a/print/templates/email/not-main-printer-configured/locale/en.yml +++ b/print/templates/email/not-main-printer-configured/locale/en.yml @@ -1,3 +1,3 @@ subject: Not main printer configured title: Not main printer configured -description: Printer {0} has been configured in sector {1} (the main printer for that sector is {2}). Ask the worker {3} +description: 'Printer #{0} {1} has been configured in sector #{2} {3} (the main printer for that sector is #{4} {5}). Ask the worker {6}.' diff --git a/print/templates/email/not-main-printer-configured/locale/es.yml b/print/templates/email/not-main-printer-configured/locale/es.yml index a8b207a54..b6fe5f9a0 100644 --- a/print/templates/email/not-main-printer-configured/locale/es.yml +++ b/print/templates/email/not-main-printer-configured/locale/es.yml @@ -1,3 +1,3 @@ subject: Configurada impresora no principal title: Configurada impresora no principal -description: Se ha configurado la impresora {0} en el sector {1} (la impresora principal de ese sector es la {2}). Preguntar al trabajador {3}. +description: 'Se ha configurado la impresora #{0} {1} en el sector #{2} {3} (la impresora principal de ese sector es la #{4} {5}). Preguntar al trabajador {6}.' diff --git a/print/templates/email/not-main-printer-configured/not-main-printer-configured.html b/print/templates/email/not-main-printer-configured/not-main-printer-configured.html index 06ab6d0b0..1e9ffed7a 100644 --- a/print/templates/email/not-main-printer-configured/not-main-printer-configured.html +++ b/print/templates/email/not-main-printer-configured/not-main-printer-configured.html @@ -2,7 +2,7 @@

{{ $t('title') }}

-

+

diff --git a/print/templates/email/not-main-printer-configured/not-main-printer-configured.js b/print/templates/email/not-main-printer-configured/not-main-printer-configured.js index 2c3e3521a..c381991fa 100755 --- a/print/templates/email/not-main-printer-configured/not-main-printer-configured.js +++ b/print/templates/email/not-main-printer-configured/not-main-printer-configured.js @@ -3,24 +3,30 @@ const emailBody = new Component('email-body'); module.exports = { name: 'not-main-printer-configured', + async serverPrefetch() { + this.sector = await this.findOneFromDef('sector', [this.sectorId]); + + if (!this.sector) + throw new Error('Something went wrong'); + + this.labeler = await this.findOneFromDef('printer', [this.labelerId]); + this.mainPrinter = await this.findOneFromDef('printer', [this.sector.mainPrinterFk]); + this.worker = await this.findOneFromDef('worker', [this.workerId]); + }, components: { 'email-body': emailBody.build(), }, props: { - labeler: { - type: String, + labelerId: { + type: Number, required: true }, - sector: { - type: String, + sectorId: { + type: Number, required: true }, - mainPrinter: { - type: String, - required: true - }, - worker: { - type: String, + workerId: { + type: Number, required: true } } diff --git a/print/templates/email/not-main-printer-configured/sql/printer.sql b/print/templates/email/not-main-printer-configured/sql/printer.sql new file mode 100644 index 000000000..265818129 --- /dev/null +++ b/print/templates/email/not-main-printer-configured/sql/printer.sql @@ -0,0 +1,3 @@ +SELECT id, name + FROM vn.printer + WHERE id = ? diff --git a/print/templates/email/not-main-printer-configured/sql/sector.sql b/print/templates/email/not-main-printer-configured/sql/sector.sql new file mode 100644 index 000000000..5d54eeeb9 --- /dev/null +++ b/print/templates/email/not-main-printer-configured/sql/sector.sql @@ -0,0 +1,3 @@ +SELECT id, description, mainPrinterFk + FROM vn.sector + WHERE id = ? diff --git a/print/templates/email/not-main-printer-configured/sql/worker.sql b/print/templates/email/not-main-printer-configured/sql/worker.sql new file mode 100644 index 000000000..0c7327851 --- /dev/null +++ b/print/templates/email/not-main-printer-configured/sql/worker.sql @@ -0,0 +1,3 @@ +SELECT nickname + FROM account.user + WHERE id = ? From ba850415be822aa7aabd3f2283d605efd48185a1 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 29 May 2023 12:56:54 +0200 Subject: [PATCH 6/7] refs #5137 moved sql --- db/changes/{232201 => 232401}/00-printer.sql | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename db/changes/{232201 => 232401}/00-printer.sql (100%) diff --git a/db/changes/232201/00-printer.sql b/db/changes/232401/00-printer.sql similarity index 100% rename from db/changes/232201/00-printer.sql rename to db/changes/232401/00-printer.sql From 138f03d89173033b0073307a07866e81218f631b Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 30 May 2023 11:34:53 +0200 Subject: [PATCH 7/7] refs #5137 fix back test --- modules/worker/back/methods/operator/spec/operator.spec.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/worker/back/methods/operator/spec/operator.spec.js b/modules/worker/back/methods/operator/spec/operator.spec.js index 5f099040a..1253be474 100644 --- a/modules/worker/back/methods/operator/spec/operator.spec.js +++ b/modules/worker/back/methods/operator/spec/operator.spec.js @@ -33,10 +33,9 @@ describe('Operator', () => { expect(notificationQueue.notificationFk).toEqual(notificationName); expect(notificationQueue.authorFk).toEqual(authorFk); - expect(params.labeler).toContain('2'); - expect(params.sector).toContain('1'); - expect(params.mainPrinter).toContain('1'); - expect(params.worker).toContain('9'); + expect(params.labelerId).toEqual(2); + expect(params.sectorId).toEqual(1); + expect(params.workerId).toEqual(9); await tx.rollback(); } catch (e) {