136 lines
4.8 KiB
JavaScript
136 lines
4.8 KiB
JavaScript
|
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');
|
||
|
});
|
||
|
});
|