From 4729a7e9a9e98838875eb4e9263459949f651712 Mon Sep 17 00:00:00 2001 From: Bernat Date: Tue, 11 Jun 2019 12:25:17 +0200 Subject: [PATCH] Bug #1514 route.volume No actualiza el volumen --- .../10050-pentecostes/01-routeUpdateM3.sql | 17 +++++++++++++++++ .../methods/route/specs/updateVolume.spec.js | 18 +++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) create mode 100644 db/changes/10050-pentecostes/01-routeUpdateM3.sql diff --git a/db/changes/10050-pentecostes/01-routeUpdateM3.sql b/db/changes/10050-pentecostes/01-routeUpdateM3.sql new file mode 100644 index 000000000..6b74df6d7 --- /dev/null +++ b/db/changes/10050-pentecostes/01-routeUpdateM3.sql @@ -0,0 +1,17 @@ + +DROP procedure IF EXISTS `vn`.`routeUpdateM3`; + +DELIMITER $$ +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`routeUpdateM3`(vRoute INT) +BEGIN + + UPDATE vn.route r + JOIN (SELECT routeFk, SUM(volume) AS m3 + FROM ticketGetVolume + WHERE routeFk = vRoute + ) v ON v.routeFk = r.id + SET r.m3 = v.m3; +END$$ + +DELIMITER ; + diff --git a/modules/route/back/methods/route/specs/updateVolume.spec.js b/modules/route/back/methods/route/specs/updateVolume.spec.js index a0ef283b8..046240555 100644 --- a/modules/route/back/methods/route/specs/updateVolume.spec.js +++ b/modules/route/back/methods/route/specs/updateVolume.spec.js @@ -1,20 +1,17 @@ const app = require('vn-loopback/server/server'); -// Check procedure from task #1514 -xdescribe('route updateVolume()', () => { +describe('route updateVolume()', () => { const routeId = 1; const workerFk = 9; const ctx = {req: {accessToken: {userId: workerFk}}}; let originalRoute; - let firstUpdatedTicket; - let secondUpdatedTicket; + let ticketRestore; let logIdToDestroy; afterAll(async done => { - // await originalRoute.updateAttributes({m3: 0.2}); - // await firstUpdatedTicket.updateAttributes({routeFk: 4}); - // await secondUpdatedTicket.updateAttributes({routeFk: 4}); + await originalRoute.updateAttributes({m3: 0.2}); + await ticketRestore.updateAttributes({routeFk: 4}); await app.models.RouteLog.destroyById(logIdToDestroy); done(); }); @@ -26,11 +23,10 @@ xdescribe('route updateVolume()', () => { }); it('should confirm the route volume is updated when a ticket is added', async() => { - // firstUpdatedTicket = await app.models.Ticket.findById(16); - secondUpdatedTicket = await app.models.Ticket.findById(8); + ticketRestore = await app.models.Ticket.findById(8); + let updatedTicket = await app.models.Ticket.findById(8); - // await firstUpdatedTicket.updateAttributes({routeFk: routeId}); - await secondUpdatedTicket.updateAttributes({routeFk: routeId}); + await updatedTicket.updateAttributes({routeFk: routeId}); await app.models.Route.updateVolume(ctx, routeId); let updatedRoute = await app.models.Route.findById(routeId);