2019-02-13 07:34:40 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-12-21 19:22:13 +00:00
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
2018-09-26 13:49:35 +00:00
|
|
|
|
|
|
|
describe('ticket ticketCreateWithUser()', () => {
|
|
|
|
const today = new Date();
|
2019-01-02 12:33:30 +00:00
|
|
|
it('should confirm the procedure creates the expected ticket', async() => {
|
2018-11-21 10:50:30 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-09-26 13:49:35 +00:00
|
|
|
let params = {
|
|
|
|
clientFk: 101,
|
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
2019-06-19 05:20:02 +00:00
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 1,
|
2018-09-26 13:49:35 +00:00
|
|
|
routeFk: null,
|
|
|
|
landed: today,
|
|
|
|
userId: 18
|
|
|
|
};
|
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
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-11-21 10:50:30 +00:00
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
let ticketResultIndex = stmts.push(`SELECT * FROM vn.ticket WHERE id = @newTicketId`) - 1;
|
2018-09-26 13:49:35 +00:00
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
stmts.push('ROLLBACK');
|
2018-09-26 13:49:35 +00:00
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Ticket.rawStmt(sql);
|
2018-09-26 13:49:35 +00:00
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
let ticketResult = result[ticketResultIndex][0];
|
2018-09-26 13:49:35 +00:00
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
expect(ticketResult.id).toBeGreaterThan(21);
|
|
|
|
expect(ticketResult.clientFk).toEqual(params.clientFk);
|
|
|
|
expect(ticketResult.warehouseFk).toEqual(params.warehouseFk);
|
|
|
|
expect(ticketResult.companyFk).toEqual(params.companyFk);
|
|
|
|
expect(ticketResult.addressFk).toEqual(params.addressFk);
|
|
|
|
expect(ticketResult.agencyModeFk).toEqual(params.agencyModeFk);
|
|
|
|
expect(ticketResult.routeFk).toEqual(params.routeFk);
|
2018-09-26 13:49:35 +00:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:33:30 +00:00
|
|
|
it('should confirm the procedure creates the expected observations in the ticket', async() => {
|
2018-11-21 10:50:30 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-09-26 13:49:35 +00:00
|
|
|
let params = {
|
|
|
|
clientFk: 101,
|
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
2019-06-19 05:20:02 +00:00
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 1,
|
2018-09-26 13:49:35 +00:00
|
|
|
routeFk: null,
|
|
|
|
landed: today,
|
|
|
|
userId: 18
|
|
|
|
};
|
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
stmt = new ParameterizedSQL('CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)', [
|
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-11-21 10:50:30 +00:00
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
let ticketObsevationsIndex = stmts.push(`SELECT * FROM vn.ticketObservation WHERE ticketFk = @newTicketId`) - 1;
|
|
|
|
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Ticket.rawStmt(sql);
|
2018-09-26 13:49:35 +00:00
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
let firstTicketObservation = result[ticketObsevationsIndex][0];
|
|
|
|
let secondTicketObservation = result[ticketObsevationsIndex][1];
|
|
|
|
let thirdTicketObservation = result[ticketObsevationsIndex][2];
|
2018-09-26 13:49:35 +00:00
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2019-01-02 12:33:30 +00:00
|
|
|
it('should confirm the procedure sets address if it received it null', async() => {
|
2018-11-21 10:50:30 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-10-04 11:32:28 +00:00
|
|
|
let params = {
|
|
|
|
clientFk: 101,
|
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
|
|
|
addressFk: 0,
|
2019-06-19 05:20:02 +00:00
|
|
|
agencyModeFk: 1,
|
2018-10-04 11:32:28 +00:00
|
|
|
routeFk: null,
|
|
|
|
landed: today,
|
|
|
|
userId: 18
|
|
|
|
};
|
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
2018-10-04 11:32:28 +00:00
|
|
|
params.clientFk,
|
|
|
|
params.shipped,
|
|
|
|
params.warehouseFk,
|
|
|
|
params.companyFk,
|
|
|
|
params.addressFk,
|
|
|
|
params.agencyModeFk,
|
|
|
|
params.routeFk,
|
|
|
|
params.landed,
|
2018-11-21 10:50:30 +00:00
|
|
|
params.userId
|
2018-10-04 11:32:28 +00:00
|
|
|
]);
|
2019-03-04 07:13:09 +00:00
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
let ticketAddressIndex = stmts.push(`SELECT addressFk FROM vn.ticket WHERE id = @newTicketId`) - 1;
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL(`SELECT id FROM vn.address WHERE clientFk = ? AND isDefaultAddress = 1`, [
|
|
|
|
params.clientFk,
|
|
|
|
]);
|
|
|
|
let clientDefaultAddressIndex = stmts.push(stmt) - 1;
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Ticket.rawStmt(sql);
|
|
|
|
let ticketAddress = result[ticketAddressIndex][0];
|
|
|
|
let clientDefaultAddress = result[clientDefaultAddressIndex][0];
|
2018-10-04 11:32:28 +00:00
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
expect(ticketAddress.addressFk).toEqual(clientDefaultAddress.id);
|
2018-10-04 11:32:28 +00:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:33:30 +00:00
|
|
|
it('should confirm the procedure creates the state as delivered if the client has isCreatedAsServed TRUE', async() => {
|
2018-11-21 10:50:30 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-10-04 11:32:28 +00:00
|
|
|
let params = {
|
|
|
|
clientFk: 101,
|
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
2019-06-19 05:20:02 +00:00
|
|
|
addressFk: 121,
|
|
|
|
agencyModeFk: 1,
|
2018-10-04 11:32:28 +00:00
|
|
|
routeFk: null,
|
|
|
|
landed: today,
|
|
|
|
userId: 18
|
|
|
|
};
|
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
stmt = new ParameterizedSQL(`UPDATE vn.client SET isCreatedAsServed = 1 WHERE id = ?`, [
|
2018-10-04 11:32:28 +00:00
|
|
|
params.clientFk,
|
2018-11-21 10:50:30 +00:00
|
|
|
]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
|
2018-10-04 11:32:28 +00:00
|
|
|
params.clientFk,
|
|
|
|
params.shipped,
|
|
|
|
params.warehouseFk,
|
|
|
|
params.companyFk,
|
|
|
|
params.addressFk,
|
|
|
|
params.agencyModeFk,
|
|
|
|
params.routeFk,
|
|
|
|
params.landed,
|
2018-11-21 10:50:30 +00:00
|
|
|
params.userId
|
2018-10-04 11:32:28 +00:00
|
|
|
]);
|
2018-11-21 10:50:30 +00:00
|
|
|
stmts.push(stmt);
|
2019-07-11 05:19:22 +00:00
|
|
|
stmts.push(`select @newTicketId`);
|
2018-11-21 10:50:30 +00:00
|
|
|
let ticketStateCodeIndex = stmts.push(`SELECT code FROM vn.ticketState WHERE ticketFk = @newTicketId`) - 1;
|
|
|
|
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Ticket.rawStmt(sql);
|
2018-10-04 11:32:28 +00:00
|
|
|
|
2018-11-21 10:50:30 +00:00
|
|
|
let ticketStateCode = result[ticketStateCodeIndex][0].code;
|
2018-10-04 11:32:28 +00:00
|
|
|
|
2019-06-19 05:20:02 +00:00
|
|
|
expect(ticketStateCode).toEqual('FREE');
|
2018-09-26 13:49:35 +00:00
|
|
|
});
|
|
|
|
});
|