salix/db/tests/vn/ticketCreateWithUser.spec.js

204 lines
6.6 KiB
JavaScript
Raw Normal View History

const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('ticket ticket_add()', () => {
2023-01-16 14:18:24 +00:00
const today = Date.vnNew();
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');
let params = {
clientFk: 1101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
2019-06-19 05:20:02 +00:00
addressFk: 121,
agencyModeFk: 1,
routeFk: null,
landed: today,
userId: 18
};
stmt = new ParameterizedSQL(`CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
params.clientFk,
params.shipped,
params.warehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
params.landed,
params.userId,
true
]);
2018-11-21 10:50:30 +00:00
stmts.push(stmt);
let ticketResultIndex = stmts.push(`SELECT * FROM vn.ticket WHERE id = @newTicketId`) - 1;
2018-11-21 10:50:30 +00:00
stmts.push('ROLLBACK');
2018-11-21 10:50:30 +00:00
let sql = ParameterizedSQL.join(stmts, ';');
let result = await app.models.Ticket.rawStmt(sql);
2018-11-21 10:50:30 +00:00
let ticketResult = result[ticketResultIndex][0];
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);
});
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');
let params = {
clientFk: 1101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
2019-06-19 05:20:02 +00:00
addressFk: 121,
agencyModeFk: 1,
routeFk: null,
landed: today,
userId: 18
};
stmt = new ParameterizedSQL('CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)', [
params.clientFk,
params.shipped,
params.warehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
params.landed,
params.userId,
true
]);
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-11-21 10:50:30 +00:00
let firstTicketObservation = result[ticketObsevationsIndex][0];
let secondTicketObservation = result[ticketObsevationsIndex][1];
let thirdTicketObservation = result[ticketObsevationsIndex][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');
});
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');
let params = {
clientFk: 1101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
addressFk: 0,
2019-06-19 05:20:02 +00:00
agencyModeFk: 1,
routeFk: null,
landed: today,
userId: 18
};
stmt = new ParameterizedSQL(`CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
params.clientFk,
params.shipped,
params.warehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
params.landed,
params.userId,
true
]);
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-11-21 10:50:30 +00:00
expect(ticketAddress.addressFk).toEqual(clientDefaultAddress.id);
});
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');
let params = {
clientFk: 1101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
2019-06-19 05:20:02 +00:00
addressFk: 121,
agencyModeFk: 1,
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 = ?`, [
params.clientFk,
2018-11-21 10:50:30 +00:00
]);
stmts.push(stmt);
stmt = new ParameterizedSQL(`CALL vn.ticket_add(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
params.clientFk,
params.shipped,
params.warehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
params.landed,
params.userId,
true
]);
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-11-21 10:50:30 +00:00
let ticketStateCode = result[ticketStateCodeIndex][0].code;
2019-06-19 05:20:02 +00:00
expect(ticketStateCode).toEqual('FREE');
});
});