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

56 lines
2.0 KiB
JavaScript
Raw Normal View History

const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('buyUltimate()', () => {
2023-01-16 14:18:24 +00:00
const today = Date.vnNew();
2019-01-02 12:33:30 +00:00
it(`should create buyUltimate temporal table and update it's values`, async() => {
let stmts = [];
let stmt;
stmts.push('START TRANSACTION');
let params = {
warehouseFk: 1,
date: today
};
stmt = new ParameterizedSQL('CALL vn.buyUltimate(?, ?)', [
params.warehouseFk,
params.date
]);
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);
let buyUltimateTable = result[buyUltimateTableIndex];
2019-06-19 05:20:02 +00:00
expect(buyUltimateTable.length).toEqual(6);
expect(buyUltimateTable[0].itemFk).toEqual(1);
expect(buyUltimateTable[1].itemFk).toEqual(2);
expect(buyUltimateTable[2].itemFk).toEqual(3);
expect(buyUltimateTable[3].itemFk).toEqual(4);
2019-06-19 05:20:02 +00:00
expect(buyUltimateTable[4].itemFk).toEqual(8);
expect(buyUltimateTable[5].itemFk).toEqual(9);
expect(buyUltimateTable[0].warehouseFk).toEqual(1);
expect(buyUltimateTable[1].warehouseFk).toEqual(1);
expect(buyUltimateTable[2].warehouseFk).toEqual(1);
expect(buyUltimateTable[3].warehouseFk).toEqual(1);
2019-06-19 05:20:02 +00:00
expect(buyUltimateTable[4].warehouseFk).toEqual(1);
expect(buyUltimateTable[5].warehouseFk).toEqual(1);
expect(buyUltimateTable[1].buyFk).toEqual(4);
expect(buyUltimateTable[0].buyFk).toEqual(3);
expect(buyUltimateTable[2].buyFk).toEqual(5);
2020-01-23 12:01:29 +00:00
expect(buyUltimateTable[3].buyFk).toEqual(9);
2019-06-19 05:20:02 +00:00
expect(buyUltimateTable[4].buyFk).toEqual(6);
expect(buyUltimateTable[5].buyFk).toEqual(7);
});
});