From b50ae7b8ca31546a1097e997df9f92e6d32fbb2f Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 30 Oct 2020 15:50:59 +0100 Subject: [PATCH] testback arreglados --- .../00-ticket_beforeUpdate.sql | 25 ++++++++ db/dump/fixtures.sql | 2 +- .../ticket-request/specs/filter.spec.js | 58 ++++++++++--------- .../back/methods/ticket/componentUpdate.js | 3 +- .../ticket/specs/componentUpdate.spec.js | 11 ++-- 5 files changed, 65 insertions(+), 34 deletions(-) create mode 100644 db/changes/10240-allSaints/00-ticket_beforeUpdate.sql diff --git a/db/changes/10240-allSaints/00-ticket_beforeUpdate.sql b/db/changes/10240-allSaints/00-ticket_beforeUpdate.sql new file mode 100644 index 000000000..183636081 --- /dev/null +++ b/db/changes/10240-allSaints/00-ticket_beforeUpdate.sql @@ -0,0 +1,25 @@ +DROP TRIGGER IF EXISTS `vn`.`ticket_afterUpdate`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` TRIGGER `ticket_afterUpdate` + AFTER UPDATE ON `ticket` + FOR EACH ROW +BEGIN + IF !(NEW.id <=> OLD.id) + OR !(NEW.warehouseFk <=> OLD.warehouseFk) + OR !(NEW.shipped <=> OLD.shipped) THEN + CALL stock.log_add('ticket', NEW.id, OLD.id); + END IF; + + IF NEW.clientFk = 2067 AND !(NEW.clientFk <=> OLD.clientFk) THEN + -- Fallo que se insertan no se sabe como tickets en este cliente + INSERT INTO vn.mail SET + `sender` = 'jgallego@verdnatura.es', + `replyTo` = 'jgallego@verdnatura.es', + `subject` = 'Modificado ticket al cliente 2067', + `body` = CONCAT(account.myUserGetName(), ' ha modificado el ticket ', + NEW.id); + END IF; +END$$ +DELIMITER ; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 56c3aca4a..cde371050 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -325,7 +325,7 @@ INSERT INTO `vn`.`address`(`id`, `nickname`, `street`, `city`, `postalCode`, `pr (119, 'address 19', 'Somewhere in Alberic', 'Silla', 46460, 1, 1111111111, 222222222, 1, 109, 2, NULL, NULL, 0, 0), (120, 'address 20', 'Somewhere in Montortal', 'Silla', 46460, 1, 1111111111, 222222222, 1, 109, 2, NULL, NULL, 0, 0), (121, 'address 21', 'the bat cave', 'Silla', 46460, 1, 1111111111, 222222222, 1, 101, 2, NULL, NULL, 0, 0), - (122, 'address 22', 'NY roofs', 'Silla', 46460, 1, 1111111111, 222222222, 1, 102, 2, NULL, NULL, 0, 0), + (122, 'NY roofs', 'address 22', 'Silla', 46460, 1, 1111111111, 222222222, 1, 102, 2, NULL, NULL, 0, 0), (123, 'address 23', 'The phone box', 'Silla', 46460, 1, 1111111111, 222222222, 1, 103, 2, NULL, NULL, 0, 0), (124, 'address 24', 'Stark tower Silla', 'Silla', 46460, 1, 1111111111, 222222222, 1, 104, 2, NULL, NULL, 0, 0), (125, 'address 25', 'The plastic cell', 'Silla', 46460, 1, 1111111111, 222222222, 1, 105, 2, NULL, NULL, 0, 0), diff --git a/modules/ticket/back/methods/ticket-request/specs/filter.spec.js b/modules/ticket/back/methods/ticket-request/specs/filter.spec.js index 68d7601e4..13636341c 100644 --- a/modules/ticket/back/methods/ticket-request/specs/filter.spec.js +++ b/modules/ticket/back/methods/ticket-request/specs/filter.spec.js @@ -1,82 +1,84 @@ const app = require('vn-loopback/server/server'); describe('ticket-request filter()', () => { - it('should now return all ticket requests', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {}}; + const userId = 9; + let ctx = {req: {accessToken: {userId: userId}}}; - let result = await app.models.TicketRequest.filter(ctx); + it('should now return all ticket requests', async() => { + ctx.args = {}; + + const result = await app.models.TicketRequest.filter(ctx); expect(result.length).toEqual(3); }); it('should return the ticket request matching a generic search value which is the ticket ID', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {search: 11}}; + ctx.args = {search: 11}; - let result = await app.models.TicketRequest.filter(ctx); - let requestId = result[0].id; + const result = await app.models.TicketRequest.filter(ctx); + const requestId = result[0].id; expect(requestId).toEqual(4); }); it('should return the ticket request matching a generic search value which is the client address alias', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {search: 'NY roofs'}}; + ctx.args = {search: 'NY roofs'}; - let result = await app.models.TicketRequest.filter(ctx); - let requestId = result[0].id; + const result = await app.models.TicketRequest.filter(ctx); + const requestId = result[0].id; expect(requestId).toEqual(4); }); it('should return the ticket request matching the ticket ID', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {ticketFk: 11}}; - - let result = await app.models.TicketRequest.filter(ctx); - let requestId = result[0].id; + ctx.args = {ticketFk: 11}; + const result = await app.models.TicketRequest.filter(ctx); + const requestId = result[0].id; expect(requestId).toEqual(4); }); it('should return the ticket request matching the atender ID', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {attenderFk: 35}}; + ctx.args = {attenderFk: 35}; - let result = await app.models.TicketRequest.filter(ctx); - let requestId = result[0].id; + const result = await app.models.TicketRequest.filter(ctx); + const requestId = result[0].id; expect(requestId).toEqual(3); }); it('should return the ticket request matching the isOk triple-state', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {isOk: null}}; + ctx.args = {isOk: null}; - let result = await app.models.TicketRequest.filter(ctx); - let requestId = result[0].id; + const result = await app.models.TicketRequest.filter(ctx); + const requestId = result[0].id; expect(requestId).toEqual(3); }); it('should return the ticket request matching the client ID', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {clientFk: 102}}; + ctx.args = {clientFk: 102}; - let result = await app.models.TicketRequest.filter(ctx); - let requestId = result[0].id; + const result = await app.models.TicketRequest.filter(ctx); + const requestId = result[0].id; expect(requestId).toEqual(4); }); it('should return the ticket request matching the warehouse ID', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {warehouse: 1}}; + ctx.args = {warehouse: 1}; - let result = await app.models.TicketRequest.filter(ctx, {order: 'id'}); - let requestId = result[0].id; + const result = await app.models.TicketRequest.filter(ctx, {order: 'id'}); + const requestId = result[0].id; expect(requestId).toEqual(3); }); it('should return the ticket request matching the salesPerson ID', async() => { - let ctx = {req: {accessToken: {userId: 9}}, args: {salesPersonFk: 18}}; + ctx.args = {salesPersonFk: 18}; - let result = await app.models.TicketRequest.filter(ctx); - let requestId = result[0].id; + const result = await app.models.TicketRequest.filter(ctx); + const requestId = result[0].id; expect(requestId).toEqual(3); }); diff --git a/modules/ticket/back/methods/ticket/componentUpdate.js b/modules/ticket/back/methods/ticket/componentUpdate.js index 53a1593bc..fe395e562 100644 --- a/modules/ticket/back/methods/ticket/componentUpdate.js +++ b/modules/ticket/back/methods/ticket/componentUpdate.js @@ -92,6 +92,7 @@ module.exports = Self => { const observationTypeDelivery = await models.ObservationType.findOne({ where: {code: 'delivery'} }); + const originalTicket = await models.Ticket.findOne({ where: {id: id}, fields: ['id', 'clientFk', 'agencyModeFk', 'addressFk', 'zoneFk', @@ -151,7 +152,7 @@ module.exports = Self => { }); const [observation] = address.observations(); if (observation) { - await models.TicketObservation.upsert({ + await models.TicketObservation.create({ ticketFk: id, observationTypeFk: observation.observationTypeFk, description: observation.description diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 6126f3dcb..76733f2c6 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -5,6 +5,7 @@ describe('ticket componentUpdate()', () => { const ticketID = 11; const today = new Date(); const tomorrow = new Date(); + tomorrow.setDate(tomorrow.getDate() + 1); let deliveryComponentId; @@ -124,22 +125,24 @@ describe('ticket componentUpdate()', () => { const observationTypeDelivery = await app.models.ObservationType.findOne({ where: {code: 'delivery'} }); - const ticketObservation = await app.models.TicketObservation.findOne({ + const originalTicketObservation = await app.models.TicketObservation.findOne({ where: { ticketFk: ticketID, observationTypeFk: observationTypeDelivery.id} }); + expect(originalTicketObservation).toBeDefined(); + await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, newAddressID, zoneID, warehouseID, companyID, shipped, landed, isDeleted, option); - const newTicketObservation = await app.models.TicketObservation.findOne({ + const removedTicketObservation = await app.models.TicketObservation.findOne({ where: { ticketFk: ticketID, observationTypeFk: observationTypeDelivery.id} }); - expect(newTicketObservation).toBeNull(); + expect(removedTicketObservation).toBeNull(); // restores await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, addressID, @@ -151,6 +154,6 @@ describe('ticket componentUpdate()', () => { observationTypeFk: observationTypeDelivery.id} }); - expect(restoredTicketObservation.description).toEqual(ticketObservation.description); + expect(restoredTicketObservation.description).toEqual(originalTicketObservation.description); }); });