From b3a53fbe821b5dac68431bc5ac88886e399808ac Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 26 Sep 2018 15:49:35 +0200 Subject: [PATCH] #686 PROCEDURE unit test vn.ticketCreateWithUser --- .../db/tests/vn/ticketCreateWithUser.spec.js | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 services/db/tests/vn/ticketCreateWithUser.spec.js diff --git a/services/db/tests/vn/ticketCreateWithUser.spec.js b/services/db/tests/vn/ticketCreateWithUser.spec.js new file mode 100644 index 000000000..55c81ccee --- /dev/null +++ b/services/db/tests/vn/ticketCreateWithUser.spec.js @@ -0,0 +1,135 @@ +const app = require(`../../../ticket/server/server`); + +describe('ticket ticketCreateWithUser()', () => { + const today = new Date(); + it('should confirm the procedure creates the expected ticket', async() => { + let params = { + clientFk: 101, + shipped: today, + warehouseFk: 1, + companyFk: 442, + addressFk: 1, + agencyModeFk: 2, + routeFk: null, + landed: today, + userId: 18 + }; + + let query = ` + START TRANSACTION; + CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId); + SELECT @newTicketId newTicketId; + SELECT * FROM vn.ticket WHERE id = @newTicketId; + ROLLBACK;`; + let result = await app.models.Ticket.rawSql(query, [ + params.clientFk, + params.shipped, + params.warehouseFk, + params.companyFk | 442, + params.addressFk, + params.agencyModeFk, + params.routeFk | null, + params.landed, + params.userId + ]); + + let ticketResult = result[2][0]; + + expect(ticketResult.newTicketId).toBeGreaterThan(21); + + let createdTicket = result[3][0]; + + expect(createdTicket.clientFk).toEqual(params.clientFk); + expect(createdTicket.warehouseFk).toEqual(params.warehouseFk); + expect(createdTicket.companyFk).toEqual(params.companyFk); + expect(createdTicket.addressFk).toEqual(params.addressFk); + expect(createdTicket.agencyModeFk).toEqual(params.agencyModeFk); + expect(createdTicket.routeFk).toEqual(params.routeFk); + }); + + it('should confirm the procedure creates the expected observations in the ticket', async() => { + let params = { + clientFk: 101, + shipped: today, + warehouseFk: 1, + companyFk: 442, + addressFk: 1, + agencyModeFk: 2, + routeFk: null, + landed: today, + userId: 18 + }; + + let query = ` + START TRANSACTION; + CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId); + SELECT @newTicketId newTicketId; + SELECT * FROM vn.ticketObservation WHERE ticketFk = @newTicketId; + ROLLBACK;`; + let result = await app.models.Ticket.rawSql(query, [ + params.clientFk, + params.shipped, + params.warehouseFk, + params.companyFk | 442, + params.addressFk, + params.agencyModeFk, + params.routeFk | null, + params.landed, + params.userId + ]); + + let firstTicketObservation = result[3][0]; + let secondTicketObservation = result[3][1]; + let thirdTicketObservation = result[3][2]; + + expect(firstTicketObservation.observationTypeFk).toEqual(1); + expect(firstTicketObservation.description).toEqual('under the floor'); + expect(secondTicketObservation.observationTypeFk).toEqual(2); + expect(secondTicketObservation.description).toEqual('wears leather and goes out at night'); + expect(thirdTicketObservation.observationTypeFk).toEqual(3); + expect(thirdTicketObservation.description).toEqual('care with the dog'); + }); + + it('should confirm the procedure creates the expected observations in the ticket', async() => { + let params = { + clientFk: 101, + shipped: today, + warehouseFk: 1, + companyFk: 442, + addressFk: 1, + agencyModeFk: 2, + routeFk: null, + landed: today, + userId: 18 + }; + + let query = ` + START TRANSACTION; + CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId); + SELECT @newTicketId newTicketId; + SELECT * FROM vn.ticketObservation WHERE ticketFk = @newTicketId; + ROLLBACK;`; + let result = await app.models.Ticket.rawSql(query, [ + params.clientFk, + params.shipped, + params.warehouseFk, + params.companyFk | 442, + params.addressFk, + params.agencyModeFk, + params.routeFk | null, + params.landed, + params.userId + ]); + + let firstTicketObservation = result[3][0]; + let secondTicketObservation = result[3][1]; + let thirdTicketObservation = result[3][2]; + + expect(firstTicketObservation.observationTypeFk).toEqual(1); + expect(firstTicketObservation.description).toEqual('under the floor'); + expect(secondTicketObservation.observationTypeFk).toEqual(2); + expect(secondTicketObservation.description).toEqual('wears leather and goes out at night'); + expect(thirdTicketObservation.observationTypeFk).toEqual(3); + expect(thirdTicketObservation.description).toEqual('care with the dog'); + }); +});