2018-10-04 12:42:44 +00:00
|
|
|
const app = require(`../../../ticket/server/server`);
|
2018-10-14 15:09:05 +00:00
|
|
|
const server = require(`../../../loopback/server/server`);
|
|
|
|
const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL;
|
2018-10-04 12:42:44 +00:00
|
|
|
|
|
|
|
describe('buyUltimate()', () => {
|
|
|
|
const today = new Date();
|
|
|
|
it(`should create buyUltimate temporal table and update it's values`, async() => {
|
2018-10-14 15:09:05 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-10-04 12:42:44 +00:00
|
|
|
let params = {
|
|
|
|
warehouseFk: 1,
|
|
|
|
date: today
|
|
|
|
};
|
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
stmt = new ParameterizedSQL('CALL vn.buyUltimate(?, ?)', [
|
2018-10-04 12:42:44 +00:00
|
|
|
params.warehouseFk,
|
|
|
|
params.date
|
|
|
|
]);
|
2018-10-14 15:09:05 +00:00
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
let buyUltimateTableIndex = stmts.push(`SELECT * FROM tmp.buyUltimate ORDER BY itemFk ASC`) - 1;
|
|
|
|
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Ticket.rawStmt(sql);
|
2018-10-04 12:42:44 +00:00
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
let buyUltimateTable = result[buyUltimateTableIndex];
|
2018-10-04 12:42:44 +00:00
|
|
|
|
|
|
|
expect(buyUltimateTable.length).toEqual(4);
|
|
|
|
|
|
|
|
expect(buyUltimateTable[0].itemFk).toEqual(1);
|
|
|
|
expect(buyUltimateTable[1].itemFk).toEqual(2);
|
|
|
|
expect(buyUltimateTable[2].itemFk).toEqual(3);
|
|
|
|
expect(buyUltimateTable[3].itemFk).toEqual(4);
|
|
|
|
|
|
|
|
expect(buyUltimateTable[0].warehouseFk).toEqual(1);
|
|
|
|
expect(buyUltimateTable[1].warehouseFk).toEqual(1);
|
|
|
|
expect(buyUltimateTable[2].warehouseFk).toEqual(1);
|
|
|
|
expect(buyUltimateTable[3].warehouseFk).toEqual(1);
|
|
|
|
|
|
|
|
expect(buyUltimateTable[1].buyFk).toEqual(4);
|
|
|
|
expect(buyUltimateTable[0].buyFk).toEqual(3);
|
|
|
|
expect(buyUltimateTable[2].buyFk).toEqual(5);
|
|
|
|
expect(buyUltimateTable[3].buyFk).toEqual(6);
|
|
|
|
});
|
|
|
|
});
|