2018-09-26 13:49:35 +00:00
|
|
|
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,
|
2018-10-04 11:32:28 +00:00
|
|
|
params.companyFk,
|
2018-09-26 13:49:35 +00:00
|
|
|
params.addressFk,
|
|
|
|
params.agencyModeFk,
|
2018-10-04 11:32:28 +00:00
|
|
|
params.routeFk,
|
2018-09-26 13:49:35 +00:00
|
|
|
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,
|
2018-10-04 11:32:28 +00:00
|
|
|
params.companyFk,
|
2018-09-26 13:49:35 +00:00
|
|
|
params.addressFk,
|
|
|
|
params.agencyModeFk,
|
2018-10-04 11:32:28 +00:00
|
|
|
params.routeFk,
|
2018-09-26 13:49:35 +00:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2018-10-04 11:32:28 +00:00
|
|
|
it('should confirm the procedure sets companyFk as Tenerife if vProvinceName is SANTA CRUZ DE TENERIFE', async() => {
|
2018-09-26 13:49:35 +00:00
|
|
|
let params = {
|
|
|
|
clientFk: 101,
|
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
|
|
|
addressFk: 1,
|
|
|
|
agencyModeFk: 2,
|
|
|
|
routeFk: null,
|
|
|
|
landed: today,
|
|
|
|
userId: 18
|
|
|
|
};
|
|
|
|
|
2018-10-04 11:32:28 +00:00
|
|
|
let tenerife = 1381;
|
|
|
|
|
|
|
|
let changeProvinceToTenerife = `UPDATE province p, client c SET p.name ='SANTA CRUZ DE TENERIFE' WHERE p.id = c.provinceFk AND c.id = ?;`;
|
|
|
|
|
2018-09-26 13:49:35 +00:00
|
|
|
let query = `
|
|
|
|
START TRANSACTION;
|
2018-10-04 11:32:28 +00:00
|
|
|
${changeProvinceToTenerife}
|
2018-09-26 13:49:35 +00:00
|
|
|
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId);
|
|
|
|
SELECT @newTicketId newTicketId;
|
2018-10-04 11:32:28 +00:00
|
|
|
SELECT companyFk FROM vn.ticket WHERE id = @newTicketId;
|
2018-09-26 13:49:35 +00:00
|
|
|
ROLLBACK;`;
|
|
|
|
let result = await app.models.Ticket.rawSql(query, [
|
2018-10-04 11:32:28 +00:00
|
|
|
params.clientFk,
|
2018-09-26 13:49:35 +00:00
|
|
|
params.clientFk,
|
|
|
|
params.shipped,
|
|
|
|
params.warehouseFk,
|
2018-10-04 11:32:28 +00:00
|
|
|
params.companyFk,
|
2018-09-26 13:49:35 +00:00
|
|
|
params.addressFk,
|
|
|
|
params.agencyModeFk,
|
2018-10-04 11:32:28 +00:00
|
|
|
params.routeFk,
|
2018-09-26 13:49:35 +00:00
|
|
|
params.landed,
|
|
|
|
params.userId
|
|
|
|
]);
|
|
|
|
|
2018-10-04 11:32:28 +00:00
|
|
|
let ticket = result[4][0];
|
2018-09-26 13:49:35 +00:00
|
|
|
|
2018-10-04 11:32:28 +00:00
|
|
|
expect(ticket.companyFk).toEqual(tenerife);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should confirm the procedure sets address if it received it null', async() => {
|
|
|
|
let params = {
|
|
|
|
clientFk: 101,
|
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
|
|
|
addressFk: 0,
|
|
|
|
agencyModeFk: 2,
|
|
|
|
routeFk: null,
|
|
|
|
landed: today,
|
|
|
|
userId: 18
|
|
|
|
};
|
|
|
|
|
|
|
|
let query = `
|
|
|
|
START TRANSACTION;
|
|
|
|
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId);
|
|
|
|
SELECT @newTicketId newTicketId;
|
|
|
|
SELECT addressFk FROM vn.ticket WHERE id = @newTicketId;
|
|
|
|
SELECT id FROM vn.address WHERE clientFk = ? AND isDefaultAddress = 1;
|
|
|
|
ROLLBACK;`;
|
|
|
|
let result = await app.models.Ticket.rawSql(query, [
|
|
|
|
params.clientFk,
|
|
|
|
params.shipped,
|
|
|
|
params.warehouseFk,
|
|
|
|
params.companyFk,
|
|
|
|
params.addressFk,
|
|
|
|
params.agencyModeFk,
|
|
|
|
params.routeFk,
|
|
|
|
params.landed,
|
|
|
|
params.userId,
|
|
|
|
params.clientFk
|
|
|
|
]);
|
|
|
|
|
|
|
|
let ticket = result[2][0];
|
|
|
|
let clientDefaultAddress = result[3][0];
|
|
|
|
|
|
|
|
expect(ticket.addressFk).toEqual(clientDefaultAddress.id);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should confirm the procedure creates the state as delivered if the client has isCreatedAsServed TRUE', async() => {
|
|
|
|
let params = {
|
|
|
|
clientFk: 101,
|
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
|
|
|
addressFk: 0,
|
|
|
|
agencyModeFk: 2,
|
|
|
|
routeFk: null,
|
|
|
|
landed: today,
|
|
|
|
userId: 18
|
|
|
|
};
|
|
|
|
|
|
|
|
let setAsIsDelivered = `UPDATE vn.client SET isCreatedAsServed = 1 WHERE id = ?;`;
|
|
|
|
|
|
|
|
let query = `
|
|
|
|
START TRANSACTION;
|
|
|
|
${setAsIsDelivered}
|
|
|
|
CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId);
|
|
|
|
SELECT @newTicketId newTicketId;
|
|
|
|
SELECT code FROM vn.ticketState WHERE ticketFk = @newTicketId;
|
|
|
|
ROLLBACK;`;
|
|
|
|
let result = await app.models.Ticket.rawSql(query, [
|
|
|
|
params.clientFk,
|
|
|
|
params.clientFk,
|
|
|
|
params.shipped,
|
|
|
|
params.warehouseFk,
|
|
|
|
params.companyFk,
|
|
|
|
params.addressFk,
|
|
|
|
params.agencyModeFk,
|
|
|
|
params.routeFk,
|
|
|
|
params.landed,
|
|
|
|
params.userId,
|
|
|
|
params.clientFk
|
|
|
|
]);
|
|
|
|
|
|
|
|
let ticketState = result[4][0];
|
|
|
|
|
|
|
|
expect(ticketState.code).toEqual('DELIVERED');
|
2018-09-26 13:49:35 +00:00
|
|
|
});
|
|
|
|
});
|