From 31b5a140d435ed51c25d5da9fedcc33f7f8380b5 Mon Sep 17 00:00:00 2001 From: jgallego Date: Fri, 30 Oct 2020 10:07:53 +0100 Subject: [PATCH] test completados --- db/dump/fixtures.sql | 6 +- .../ticket/specs/componentUpdate.spec.js | 68 +++++++++++++++---- 2 files changed, 58 insertions(+), 16 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 605b6d2a8..02bb2edbd 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -412,7 +412,8 @@ INSERT INTO `vn`.`addressObservation`(`id`,`addressFk`,`observationTypeFk`,`desc VALUES (1, 121, 1, 'under the floor'), (2, 121, 2, 'wears leather and goes out at night'), - (3, 121, 3, 'care with the dog'); + (3, 121, 3, 'care with the dog'), + (5, 122, 5, 'Delivery after 10am'); INSERT INTO `vn`.`creditClassification`(`id`, `client`, `dateStart`, `dateEnd`) VALUES @@ -606,7 +607,8 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des (8, 23, 2, 'wears leather and goes out at night'), (9, 23, 3, 'care with the dog'), (10, 23, 4, 'Reclama ticket: 8'), - (11, 24, 4, 'Reclama ticket: 7'); + (11, 24, 4, 'Reclama ticket: 7'), + (12, 11, 5, 'Delivery after 10am'); -- FIX for state hours on local, inter_afterInsert UPDATE vncontrol.inter SET odbc_date = DATE_ADD(CURDATE(), INTERVAL -10 SECOND); diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 4bc9fe17b..6126f3dcb 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -97,20 +97,60 @@ describe('ticket componentUpdate()', () => { expect(firstvalueBeforeChange).toEqual(firstvalueAfterChange); expect(secondvalueBeforeChange).toEqual(secondvalueAfterChange); }); -}); -it('should change the addressFk to modify the observations and then undo the changes', async() => { - const clientID = 102; - const addressID = 122; - const agencyModeID = 8; - const warehouseID = 1; - const zoneID = 5; - const shipped = today; - const companyID = 442; - const isDeleted = false; - const landed = tomorrow; - const option = 1; + it('should change the addressFk and check that delivery observations have been changed and then undo the changes', async() => { + const clientID = 102; + const addressID = 122; + const newAddressID = 2; + const agencyModeID = 8; + const warehouseID = 1; + const zoneID = 5; + const shipped = today; + const companyID = 442; + const isDeleted = false; + const landed = tomorrow; + const option = 1; + const ctx = { + args: {clientFk: clientID, + agencyModeFk: agencyModeID}, + req: { + accessToken: {userId: userID}, + headers: {origin: 'http://localhost'}, + __: value => { + return value; + } + } + }; + const observationTypeDelivery = await app.models.ObservationType.findOne({ + where: {code: 'delivery'} + }); + const ticketObservation = await app.models.TicketObservation.findOne({ + where: { + ticketFk: ticketID, + observationTypeFk: observationTypeDelivery.id} + }); - await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, addressID, - zoneID, warehouseID, companyID, shipped, landed, isDeleted, option); + await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, newAddressID, + zoneID, warehouseID, companyID, shipped, landed, isDeleted, option); + + const newTicketObservation = await app.models.TicketObservation.findOne({ + where: { + ticketFk: ticketID, + observationTypeFk: observationTypeDelivery.id} + }); + + expect(newTicketObservation).toBeNull(); + + // restores + await app.models.Ticket.componentUpdate(ctx, ticketID, clientID, agencyModeID, addressID, + zoneID, warehouseID, companyID, shipped, landed, isDeleted, option); + + const restoredTicketObservation = await app.models.TicketObservation.findOne({ + where: { + ticketFk: ticketID, + observationTypeFk: observationTypeDelivery.id} + }); + + expect(restoredTicketObservation.description).toEqual(ticketObservation.description); + }); });