From 039eec7d26de8478aceb557a314ce473a6356f1a Mon Sep 17 00:00:00 2001 From: jgallego Date: Tue, 30 Jun 2020 10:16:22 +0200 Subject: [PATCH] test excepto fallo e2e --- db/changes/10170-NOFallas/00-aclWorkerDms.sql | 5 - .../10170-NOFallas/00-zone_getEvents.sql | 119 ------------------ .../10170-NOFallas/00-zone_getWarehouse.sql | 87 ------------- .../00-manaSpellersRequery.sql | 71 ----------- db/dump/fixtures.sql | 3 + e2e/paths/05-ticket/14_create_ticket.spec.js | 2 +- loopback/locale/en.json | 3 +- .../methods/sale/specs/updatePrice.spec.js | 5 - .../ticket/back/methods/sale/updatePrice.js | 3 +- .../ticket/specs/updateDiscount.spec.js | 25 +++- .../back/methods/ticket/updateDiscount.js | 1 - .../worker-mana/getCurrentWorkerMana.js | 5 +- 12 files changed, 32 insertions(+), 297 deletions(-) delete mode 100644 db/changes/10170-NOFallas/00-aclWorkerDms.sql delete mode 100644 db/changes/10170-NOFallas/00-zone_getEvents.sql delete mode 100644 db/changes/10170-NOFallas/00-zone_getWarehouse.sql delete mode 100644 db/changes/10200-Desescalada/00-manaSpellersRequery.sql diff --git a/db/changes/10170-NOFallas/00-aclWorkerDms.sql b/db/changes/10170-NOFallas/00-aclWorkerDms.sql deleted file mode 100644 index 46e56f77e..000000000 --- a/db/changes/10170-NOFallas/00-aclWorkerDms.sql +++ /dev/null @@ -1,5 +0,0 @@ -INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) -VALUES -('WorkerDms', 'filter', 'READ', 'ALLOW', 'ROLE', 'employee'), -('WorkerDms', 'downloadFile', 'READ', 'ALLOW', 'ROLE', 'employee'); -DELETE FROM `salix`.`ACL` WHERE (`id` = '205'); diff --git a/db/changes/10170-NOFallas/00-zone_getEvents.sql b/db/changes/10170-NOFallas/00-zone_getEvents.sql deleted file mode 100644 index 991150db7..000000000 --- a/db/changes/10170-NOFallas/00-zone_getEvents.sql +++ /dev/null @@ -1,119 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `zone_getEvents`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents`( - vGeoFk INT, - vAgencyModeFk INT) -BEGIN -/** - * Returns available events for the passed province/postcode and agency. - * - * @param vGeoFk The geo id - * @param vAgencyModeFk The agency mode id - */ - DECLARE vDeliveryMethodFk VARCHAR(255); - - DROP TEMPORARY TABLE IF EXISTS tZone; - CREATE TEMPORARY TABLE tZone - (id INT PRIMARY KEY) - ENGINE = MEMORY; - - SELECT dm.`code` INTO vDeliveryMethodFk - FROM agencyMode am - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE am.id = vAgencyModeFk; - - IF vDeliveryMethodFk = 'PICKUP' THEN - INSERT INTO tZone - SELECT id - FROM zone - WHERE agencyModeFk = vAgencyModeFk; - ELSE - CALL zone_getFromGeo(vGeoFk); - - IF vAgencyModeFk IS NOT NULL THEN - INSERT INTO tZone - SELECT t.id - FROM tmp.zone t - JOIN zone z ON z.id = t.id - WHERE z.agencyModeFk = vAgencyModeFk; - ELSE - INSERT INTO tZone - SELECT t.id - FROM tmp.zone t - JOIN zone z ON z.id = t.id - JOIN agencyMode am ON am.id = z.agencyModeFk - JOIN deliveryMethod dm ON dm.id = am.deliveryMethodFk - WHERE dm.`code` IN ('AGENCY', 'DELIVERY'); - END IF; - DROP TEMPORARY TABLE tmp.zone; - END IF; - - SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays - FROM tZone t - JOIN zoneEvent e ON e.zoneFk = t.id; - - SELECT e.zoneFk, e.dated - FROM tZone t - JOIN zoneExclusion e ON e.zoneFk = t.id; - - DROP TEMPORARY TABLE tZone; -END$$ - -DELIMITER ; - -USE `vn`; -DROP procedure IF EXISTS `zone_getEvents__`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getEvents__`( - vProvinceFk INT, - vPostCode VARCHAR(255), - vAgencyModeFk INT) -BEGIN -/** - * Returns available events for the passed province/postcode and agency. - * - * @param vAgencyModeFk The agency mode id - * @param vProvinceFk The province id - * @param vPostCode The postcode or %NULL to use the province - */ - - DECLARE vGeoFk INT; - - IF vPostCode IS NOT NULL THEN - SELECT p.geoFk INTO vGeoFk - FROM postCode p - JOIN town t ON t.id = p.townFk - WHERE p.`code` = vPostCode - AND t.provinceFk = vProvinceFk; - ELSE - SELECT geoFk INTO vGeoFk - FROM province - WHERE id = vProvinceFk; - END IF; - - CALL zone_getFromGeo(vGeoFk); - - IF vAgencyModeFk IS NOT NULL THEN - DELETE t FROM tmp.zone t - JOIN zone z ON z.id = t.id - WHERE z.agencyModeFk != vAgencyModeFk; - END IF; - - SELECT e.zoneFk, e.`type`, e.dated, e.`started`, e.`ended`, e.weekDays - FROM tmp.zone t - JOIN zoneEvent e ON e.zoneFk = t.id; - - SELECT e.zoneFk, e.dated - FROM tmp.zone t - JOIN zoneExclusion e ON e.zoneFk = t.id; - - DROP TEMPORARY TABLE tmp.zone; -END$$ - -DELIMITER ; - diff --git a/db/changes/10170-NOFallas/00-zone_getWarehouse.sql b/db/changes/10170-NOFallas/00-zone_getWarehouse.sql deleted file mode 100644 index a65643ff5..000000000 --- a/db/changes/10170-NOFallas/00-zone_getWarehouse.sql +++ /dev/null @@ -1,87 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `zone_getWarehouse`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse`(vAddress INT, vLanded DATE, vWarehouse INT) -BEGIN -/** - * Devuelve el listado de agencias disponibles para la fecha, - * dirección y almacén pasados. - * - * @param vAddress - * @param vWarehouse warehouse - * @param vLanded Fecha de recogida - * @select Listado de agencias disponibles - */ - - CALL zone_getFromGeo(address_getGeo(vAddress)); - CALL zone_getOptionsForLanding(vLanded, FALSE); - - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, - am.deliveryMethodFk, - TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, - zw.warehouseFk, - z.id zoneFk - FROM tmp.zoneOption zo - JOIN zone z ON z.id = zo.zoneFk - JOIN agencyMode am ON am.id = z.agencyModeFk - JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk - WHERE zw.warehouseFk = vWarehouse - GROUP BY z.agencyModeFk - ORDER BY agencyMode; - - DROP TEMPORARY TABLE - tmp.zone, - tmp.zoneOption; - -END$$ - -DELIMITER ; - -USE `vn`; -DROP procedure IF EXISTS `zone_getWarehouse__`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `zone_getWarehouse__`(vAddress INT, vLanded DATE, vWarehouse INT) -BEGIN -/** - * Devuelve el listado de agencias disponibles para la fecha, - * dirección y almacén pasados. - * - * @param vAddress - * @param vWarehouse warehouse - * @param vLanded Fecha de recogida - * @select Listado de agencias disponibles - */ - - CALL zone_getFromGeo(address_getGeo(vAddress)); - CALL zone_getOptionsForLanding(vLanded, FALSE); - - SELECT am.id agencyModeFk, - am.name agencyMode, - am.description, - am.deliveryMethodFk, - TIMESTAMPADD(DAY, -zo.travelingDays, vLanded) shipped, - zw.warehouseFk, - z.id zoneFk - FROM tmp.zoneOption zo - JOIN zone z ON z.id = zo.zoneFk - JOIN agencyMode am ON am.id = z.agencyModeFk - JOIN zoneWarehouse zw ON zw.zoneFk = zo.zoneFk - WHERE zw.warehouseFk - GROUP BY z.agencyModeFk - ORDER BY agencyMode; - - DROP TEMPORARY TABLE - tmp.zone, - tmp.zoneOption; - -END$$ - -DELIMITER ; - - diff --git a/db/changes/10200-Desescalada/00-manaSpellersRequery.sql b/db/changes/10200-Desescalada/00-manaSpellersRequery.sql deleted file mode 100644 index fe9407ed3..000000000 --- a/db/changes/10200-Desescalada/00-manaSpellersRequery.sql +++ /dev/null @@ -1,71 +0,0 @@ -USE `vn`; -DROP procedure IF EXISTS `manaSpellersRequery`; - -DELIMITER $$ -USE `vn`$$ -CREATE DEFINER=`root`@`%` PROCEDURE `manaSpellersRequery`(vWorkerFk INTEGER) -BEGIN - DECLARE vWorkerHasMana BOOLEAN; - DECLARE vFromDated DATE; - DECLARE vToDated DATE DEFAULT TIMESTAMPADD(DAY,1,CURDATE()); - DECLARE vMana INT; - DECLARE vAutoMana INT; - DECLARE vManaBank INT; - DECLARE vManaGreugeType INT; - - SELECT id INTO vMana - FROM `component` WHERE code = 'mana'; - - SELECT id INTO vAutoMana - FROM `component` WHERE code = 'autoMana'; - - SELECT id INTO vManaBank - FROM `bank` WHERE code = 'mana'; - - SELECT id INTO vManaGreugeType - FROM `greugeType` WHERE code = 'mana'; - - SELECT COUNT(*) INTO vWorkerHasMana - FROM vn.workerMana wm - LEFT JOIN vn.workerManaExcluded wme ON wm.workerFk = wme.workerFk - WHERE wm.workerFk = vWorkerFk AND wme.workerFk IS NULL; - - IF vWorkerHasMana THEN - - SELECT max(dated) INTO vFromDated - FROM clientManaCache; - - REPLACE workerMana (workerFk, amount) - SELECT vWorkerFk, sum(mana) FROM - ( - SELECT s.quantity * sc.value as mana - FROM ticket t - JOIN address a ON a.id = t.addressFk - JOIN client c ON c.id = a.clientFk - JOIN sale s ON s.ticketFk = t.id - JOIN saleComponent sc ON sc.saleFk = s.id - WHERE c.salesPersonFk = vWorkerFk AND sc.componentFk IN (vMana, vAutoMana) - AND t.shipped > vFromDated AND t.shipped < vToDated - UNION ALL - SELECT - r.amountPaid - FROM receipt r - JOIN client c ON c.id = r.clientFk - WHERE c.salesPersonFk = vWorkerFk AND bankFk = vManaBank - AND payed > vFromDated - UNION ALL - SELECT g.amount - FROM greuge g - JOIN client c ON c.id = g.clientFk - WHERE c.salesPersonFk = vWorkerFk AND g.greugeTypeFk = vManaGreugeType - AND g.shipped > vFromDated and g.shipped < CURDATE() - UNION ALL - SELECT cc.mana - FROM clientManaCache cc - JOIN client c ON c.id = cc.clientFk - WHERE c.salesPersonFk = vWorkerFk AND cc.dated = vFromDated - ) sub; - END IF; -END$$ - -DELIMITER ; - diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index e48a20ec6..95de30b06 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1455,6 +1455,9 @@ INSERT INTO `vn`.`clientContact`(`id`, `clientFk`, `name`, `phone`) (3, 101, 'contact 3', 222333444), (4, 102, 'contact 1', 876543219); +INSERT INTO `vn`.`workerManaExcluded`(`workerFk`) + VALUES + (9); /* el mana de los trabajadores lo podemos poner a mano en la tabla si lo calculamos antes, pero si hazemos alguna modificacion en alguna tabla que utiliza para calcularlo ya no seria correcto diff --git a/e2e/paths/05-ticket/14_create_ticket.spec.js b/e2e/paths/05-ticket/14_create_ticket.spec.js index 26c22ad3d..1d80f7f1f 100644 --- a/e2e/paths/05-ticket/14_create_ticket.spec.js +++ b/e2e/paths/05-ticket/14_create_ticket.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -describe('Ticket create path', () => { +fdescribe('Ticket create path', () => { let browser; let page; let nextMonth = new Date(); diff --git a/loopback/locale/en.json b/loopback/locale/en.json index 6f20b947b..114b07edf 100644 --- a/loopback/locale/en.json +++ b/loopback/locale/en.json @@ -67,5 +67,6 @@ "Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member", "Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member", "Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}", - "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment" + "Landing cannot be lesser than shipment": "Landing cannot be lesser than shipment", + "NOT_ZONE_WITH_THIS_PARAMETERS": "NOT_ZONE_WITH_THIS_PARAMETERS" } \ No newline at end of file diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index c4a0127ac..2ca266769 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -66,11 +66,6 @@ describe('sale updatePrice()', () => { let saleUpdated = await app.models.Sale.findById(saleId); createdSaleComponent = await app.models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponentId}}); - console.log(manaComponentId); - console.log(saleId); - console.log(saleUpdated); - console.log(createdSaleComponent); - expect(saleUpdated.price).toBe(price); expect(createdSaleComponent.value).toEqual(-2.04); }); diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index dac388034..200eeb444 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -56,7 +56,9 @@ module.exports = Self => { throw new UserError(`The sales of this ticket can't be modified`); const userId = ctx.req.accessToken.userId; + let usesMana = await models.WorkerMana.findOne({where: {workerFk: userId}, fields: 'amount'}, options); + let componentCode = usesMana ? 'mana' : 'buyerDiscount'; let discount = await models.Component.findOne({where: {code: componentCode}}, options); @@ -80,7 +82,6 @@ module.exports = Self => { value: componentValue }, options); } - await sale.updateAttributes({price: newPrice}, options); query = `CALL vn.manaSpellersRequery(?)`; diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 111897efe..42689c73e 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -8,7 +8,7 @@ describe('sale updateDiscount()', () => { beforeAll(async done => { originalSale = await app.models.Sale.findById(originalSaleId); - let manaDiscount = await app.models.Component.findOne({where: {code: 'mana'}}); + let manaDiscount = await app.models.Component.findOne({where: {code: 'buyerDiscount'}}); componentId = manaDiscount.id; let ticket = await app.models.Ticket.findById(originalSale.ticketFk); @@ -26,7 +26,6 @@ describe('sale updateDiscount()', () => { done(); }); - it('should throw an error if no sales were selected', async() => { let ctx = {req: {accessToken: {userId: 9}}}; let error; @@ -76,6 +75,28 @@ describe('sale updateDiscount()', () => { }); it('should update the discount if the salesPerson has mana', async() => { + let ctx = {req: {accessToken: {userId: 18}}}; + const ticketId = 11; + const sales = [originalSaleId]; + const newDiscount = 100; + let manaDiscount = await app.models.Component.findOne({where: {code: 'mana'}}); + componentId = manaDiscount.id; + + await app.models.Ticket.updateDiscount(ctx, ticketId, sales, newDiscount); + + let updatedSale = await app.models.Sale.findById(originalSaleId); + let createdSaleComponent = await app.models.SaleComponent.findOne({ + where: { + componentFk: componentId, + saleFk: originalSaleId + } + }); + + expect(createdSaleComponent.componentFk).toEqual(componentId); + expect(updatedSale.discount).toEqual(100); + }); + + it('should update the discount and add company discount component if the worker does not have mana', async() => { let ctx = {req: {accessToken: {userId: 9}}}; const ticketId = 11; const sales = [originalSaleId]; diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index d06ac8b27..7c9f9ae48 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -90,7 +90,6 @@ module.exports = Self => { where: {code: componentCode}}, options); const componentId = discountComponent.id; - let promises = []; for (let sale of sales) { const value = ((-sale.price * newDiscount) / 100); diff --git a/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js b/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js index 03973057d..fa34af475 100644 --- a/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js +++ b/modules/worker/back/methods/worker-mana/getCurrentWorkerMana.js @@ -16,14 +16,11 @@ module.exports = Self => { Self.getCurrentWorkerMana = async ctx => { let userId = ctx.req.accessToken.userId; - console.log(userId); let workerMana = await Self.app.models.WorkerMana.findOne({ where: {workerFk: userId}, fields: 'amount' }); - let workerMana1 = await Self.app.models.WorkerMana.find(); - console.log(workerMana); - console.log(workerMana1); + return workerMana ? workerMana.amount : 0; }; };