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

252 lines
8.0 KiB
JavaScript
Raw Normal View History

const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
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');
let params = {
clientFk: 101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
addressFk: 1,
agencyModeFk: 2,
routeFk: null,
landed: today,
userId: 18
};
2018-11-21 10:50:30 +00:00
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
params.clientFk,
params.shipped,
params.warehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
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-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: 101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
addressFk: 1,
agencyModeFk: 2,
routeFk: null,
landed: today,
userId: 18
};
2018-11-21 10:50:30 +00:00
stmt = new ParameterizedSQL('CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)', [
params.clientFk,
params.shipped,
params.warehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
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-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 companyFk as Tenerife if vProvinceName is SANTA CRUZ DE TENERIFE', async() => {
2018-11-21 10:50:30 +00:00
let stmts = [];
let stmt;
stmts.push('START TRANSACTION');
let params = {
clientFk: 101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
addressFk: 1,
agencyModeFk: 2,
routeFk: null,
landed: today,
userId: 18
};
let tenerife = 1381;
2018-11-21 10:50:30 +00:00
stmt = new ParameterizedSQL(`UPDATE province p, client c SET p.name ='SANTA CRUZ DE TENERIFE' WHERE p.id = c.provinceFk AND c.id = ?`, [
params.clientFk,
2018-11-21 10:50:30 +00:00
]);
stmts.push(stmt);
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
params.clientFk,
params.shipped,
params.warehouseFk,
params.companyFk,
params.addressFk,
params.agencyModeFk,
params.routeFk,
params.landed,
params.userId
]);
2018-11-21 10:50:30 +00:00
stmts.push(stmt);
let ticketCompanyIndex = stmts.push(`SELECT companyFk FROM vn.ticket WHERE id = @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 ticket = result[ticketCompanyIndex][0];
expect(ticket.companyFk).toEqual(tenerife);
});
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: 101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
addressFk: 0,
agencyModeFk: 2,
routeFk: null,
landed: today,
userId: 18
};
2018-11-21 10:50:30 +00:00
stmt = new ParameterizedSQL(`CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
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-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: 101,
shipped: today,
warehouseFk: 1,
companyFk: 442,
addressFk: 0,
agencyModeFk: 2,
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.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @newTicketId)`, [
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-11-21 10:50:30 +00:00
stmts.push(stmt);
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;
2018-11-21 10:50:30 +00:00
expect(ticketStateCode).toEqual('DELIVERED');
});
});