salix/db/tests/vn/buyUltimateFromInterval.spe...

133 lines
4.3 KiB
JavaScript
Raw Normal View History

const app = require('vn-loopback/server/server');
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('buyUltimateFromInterval()', () => {
let today;
let future;
beforeAll(() => {
2019-11-14 12:40:53 +00:00
let now = new Date();
now.setHours(0, 0, 0, 0);
today = now;
let futureDate = new Date(now);
let futureMonth = now.getMonth() + 1;
futureDate.setMonth(futureMonth);
future = futureDate;
});
2019-01-02 12:33:30 +00:00
it(`should create a temporal table with it's data`, async() => {
let stmts = [];
let stmt;
stmts.push('START TRANSACTION');
let params = {
warehouseFk: 1,
started: today,
ended: today
};
stmt = new ParameterizedSQL('CALL vn.buyUltimateFromInterval(?, ?, ?)', [
params.warehouseFk,
params.started,
params.ended
]);
stmts.push(stmt);
let buyUltimateFromIntervalTableIndex = stmts.push(`SELECT * FROM tmp.buyUltimateFromInterval`) - 1;
stmts.push('ROLLBACK');
let sql = ParameterizedSQL.join(stmts, ';');
let result = await app.models.Ticket.rawStmt(sql);
let buyUltimateFromIntervalTable = result[buyUltimateFromIntervalTableIndex];
expect(buyUltimateFromIntervalTable.length).toEqual(2);
expect(buyUltimateFromIntervalTable[0].itemFk).toEqual(1);
expect(buyUltimateFromIntervalTable[1].itemFk).toEqual(3);
expect(buyUltimateFromIntervalTable[0].warehouseFk).toEqual(1);
expect(buyUltimateFromIntervalTable[1].warehouseFk).toEqual(1);
expect(buyUltimateFromIntervalTable[0].buyFk).toEqual(3);
expect(buyUltimateFromIntervalTable[1].buyFk).toEqual(5);
2019-11-14 12:40:53 +00:00
expect(buyUltimateFromIntervalTable[0].landed).toEqual(today);
expect(buyUltimateFromIntervalTable[1].landed).toEqual(today);
});
2019-01-02 12:33:30 +00:00
it(`should create a temporal table with it's data in which started value is assigned to ended`, async() => {
let params = {
warehouseFk: 1,
started: today,
ended: null
};
let query = `
START TRANSACTION;
CALL vn.buyUltimateFromInterval(?, ?, ?);
SELECT * FROM tmp.buyUltimateFromInterval;
ROLLBACK;`;
let result = await app.models.Ticket.rawSql(query, [
params.warehouseFk,
params.started,
params.ended
]);
let buyUltimateFromIntervalTable = result[2];
expect(buyUltimateFromIntervalTable.length).toEqual(2);
expect(buyUltimateFromIntervalTable[0].itemFk).toEqual(1);
expect(buyUltimateFromIntervalTable[1].itemFk).toEqual(3);
expect(buyUltimateFromIntervalTable[0].warehouseFk).toEqual(1);
expect(buyUltimateFromIntervalTable[1].warehouseFk).toEqual(1);
expect(buyUltimateFromIntervalTable[0].buyFk).toEqual(3);
expect(buyUltimateFromIntervalTable[1].buyFk).toEqual(5);
2019-11-14 12:40:53 +00:00
expect(buyUltimateFromIntervalTable[0].landed).toEqual(today);
expect(buyUltimateFromIntervalTable[1].landed).toEqual(today);
});
2019-01-02 12:33:30 +00:00
it(`should create a temporal table with it's data in which ended value is a date in the future`, async() => {
let params = {
warehouseFk: 1,
started: today,
ended: future
};
let query = `
START TRANSACTION;
CALL vn.buyUltimateFromInterval(?, ?, ?);
SELECT * FROM tmp.buyUltimateFromInterval;
ROLLBACK;`;
let result = await app.models.Ticket.rawSql(query, [
params.warehouseFk,
params.started,
params.ended
]);
let buyUltimateFromIntervalTable = result[2];
expect(buyUltimateFromIntervalTable.length).toEqual(2);
expect(buyUltimateFromIntervalTable[0].itemFk).toEqual(1);
expect(buyUltimateFromIntervalTable[1].itemFk).toEqual(3);
expect(buyUltimateFromIntervalTable[0].warehouseFk).toEqual(1);
expect(buyUltimateFromIntervalTable[1].warehouseFk).toEqual(1);
expect(buyUltimateFromIntervalTable[0].buyFk).toEqual(3);
expect(buyUltimateFromIntervalTable[1].buyFk).toEqual(5);
2019-11-14 12:40:53 +00:00
expect(buyUltimateFromIntervalTable[0].landed).toEqual(today);
expect(buyUltimateFromIntervalTable[1].landed).toEqual(today);
});
});