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-10-04 06:46:56 +00:00
|
|
|
|
|
|
|
describe('ticket ticketCalculateClon()', () => {
|
|
|
|
const today = new Date();
|
2019-01-02 12:33:30 +00:00
|
|
|
it('should add the ticket to the order containing the original ticket', async() => {
|
2018-10-14 15:09:05 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-10-08 12:13:18 +00:00
|
|
|
let params = {
|
2021-06-23 11:24:23 +00:00
|
|
|
clientFk: 1101,
|
2018-10-08 12:13:18 +00:00
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
|
|
|
addressFk: 121,
|
|
|
|
agencyType: 23,
|
|
|
|
routeFk: 1,
|
|
|
|
landed: today,
|
|
|
|
userId: 21,
|
|
|
|
originalTicketId: 11
|
|
|
|
};
|
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
stmt = new ParameterizedSQL('CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @result)', [
|
2018-10-08 12:13:18 +00:00
|
|
|
params.clientFk,
|
|
|
|
params.shipped,
|
|
|
|
params.warehouseFk,
|
|
|
|
params.companyFk,
|
|
|
|
params.addressFk,
|
|
|
|
params.agencyType,
|
|
|
|
params.routeFk,
|
|
|
|
params.landed,
|
2018-10-14 15:09:05 +00:00
|
|
|
params.userId
|
2018-10-04 06:46:56 +00:00
|
|
|
]);
|
2018-10-14 15:09:05 +00:00
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.ticketCalculateClon(@result, ?)', [params.originalTicketId]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
let orderIndex = stmts.push(`SELECT * FROM vn.orderTicket WHERE ticketFk = @result`) - 1;
|
|
|
|
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Ticket.rawStmt(sql);
|
2018-10-04 06:46:56 +00:00
|
|
|
|
|
|
|
let expectedOrder = 11;
|
|
|
|
let newestTicketIdInFixtures = 21;
|
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
expect(result[orderIndex][0].orderFk).toEqual(expectedOrder);
|
|
|
|
expect(result[orderIndex][0].ticketFk).toBeGreaterThan(newestTicketIdInFixtures);
|
2018-10-04 06:46:56 +00:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:33:30 +00:00
|
|
|
it('should add the ticket to the order containing the original ticket and generate landed value if it was null', async() => {
|
2018-10-14 15:09:05 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-10-08 12:13:18 +00:00
|
|
|
let params = {
|
2021-06-23 11:24:23 +00:00
|
|
|
clientFk: 1101,
|
2018-10-08 12:13:18 +00:00
|
|
|
shipped: today,
|
|
|
|
warehouseFk: 1,
|
|
|
|
companyFk: 442,
|
|
|
|
addressFk: 121,
|
|
|
|
agencyType: 23,
|
|
|
|
routeFk: 1,
|
|
|
|
landed: null,
|
|
|
|
userId: 21,
|
|
|
|
originalTicketId: 11
|
|
|
|
};
|
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
stmt = new ParameterizedSQL('CALL vn.ticketCreateWithUser(?, ?, ?, ?, ?, ?, ?, ?, ?, @result)', [
|
2018-10-08 12:13:18 +00:00
|
|
|
params.clientFk,
|
|
|
|
params.shipped,
|
|
|
|
params.warehouseFk,
|
|
|
|
params.companyFk,
|
|
|
|
params.addressFk,
|
|
|
|
params.agencyType,
|
|
|
|
params.routeFk,
|
|
|
|
params.landed,
|
2018-10-14 15:09:05 +00:00
|
|
|
params.userId
|
2018-10-04 06:46:56 +00:00
|
|
|
]);
|
2018-10-14 15:09:05 +00:00
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL vn.ticketCalculateClon(@result, ?)', [params.originalTicketId]);
|
|
|
|
stmts.push(stmt);
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
2018-10-04 06:46:56 +00:00
|
|
|
|
2019-06-19 05:20:02 +00:00
|
|
|
let error;
|
2018-10-04 06:46:56 +00:00
|
|
|
|
2019-06-19 05:20:02 +00:00
|
|
|
try {
|
|
|
|
await app.models.Ticket.rawStmt(sql);
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(error).toBeDefined();
|
|
|
|
expect(error.statusCode).toBe(500);
|
|
|
|
expect(error.code).toBe('ER_SIGNAL_EXCEPTION');
|
2018-10-04 06:46:56 +00:00
|
|
|
});
|
|
|
|
});
|