2019-01-02 12:33:30 +00:00
|
|
|
const app = require(`${loopbackApp}`);
|
2018-12-21 19:22:13 +00:00
|
|
|
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
2018-10-08 08:59:05 +00:00
|
|
|
|
|
|
|
describe('buyUltimateFromInterval()', () => {
|
|
|
|
let today;
|
|
|
|
let future;
|
|
|
|
beforeAll(() => {
|
|
|
|
let date = new Date();
|
|
|
|
let month = `${date.getMonth() + 1}`;
|
|
|
|
let futureMonth = `${date.getMonth() + 2}`;
|
|
|
|
let day = date.getDate();
|
|
|
|
let year = date.getFullYear();
|
2019-01-02 12:33:30 +00:00
|
|
|
let futureYear = year;
|
2018-10-08 08:59:05 +00:00
|
|
|
|
|
|
|
if (month.toString().length < 2) month = '0' + month;
|
2019-01-02 12:33:30 +00:00
|
|
|
if (futureMonth.toString().length < 2) futureMonth = '0' + futureMonth;
|
|
|
|
if (futureMonth.toString() == '13') {
|
|
|
|
futureMonth = '01';
|
|
|
|
futureYear + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-08 08:59:05 +00:00
|
|
|
if (day.toString().length < 2) day = `0${day}`;
|
|
|
|
|
|
|
|
today = [year, month, day].join('-');
|
2019-01-02 12:33:30 +00:00
|
|
|
future = [futureYear, futureMonth, day].join('-');
|
2018-10-08 08:59:05 +00:00
|
|
|
});
|
|
|
|
|
2019-01-02 12:33:30 +00:00
|
|
|
it(`should create a temporal table with it's data`, async() => {
|
2018-10-14 15:09:05 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
2018-10-08 08:59:05 +00:00
|
|
|
let params = {
|
|
|
|
warehouseFk: 1,
|
|
|
|
started: today,
|
|
|
|
ended: today
|
|
|
|
};
|
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
stmt = new ParameterizedSQL('CALL vn.buyUltimateFromInterval(?, ?, ?)', [
|
2018-10-08 08:59:05 +00:00
|
|
|
params.warehouseFk,
|
|
|
|
params.started,
|
|
|
|
params.ended
|
|
|
|
]);
|
2018-10-14 15:09:05 +00:00
|
|
|
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);
|
2018-10-08 08:59:05 +00:00
|
|
|
|
2018-10-14 15:09:05 +00:00
|
|
|
let buyUltimateFromIntervalTable = result[buyUltimateFromIntervalTableIndex];
|
2018-10-08 08:59:05 +00:00
|
|
|
|
|
|
|
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-01-02 12:33:30 +00:00
|
|
|
expect(buyUltimateFromIntervalTable[0].landed).toEqual(new Date(today));
|
|
|
|
expect(buyUltimateFromIntervalTable[1].landed).toEqual(new Date(today));
|
2018-10-08 08:59:05 +00:00
|
|
|
});
|
|
|
|
|
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() => {
|
2018-10-08 08:59:05 +00:00
|
|
|
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-01-02 12:33:30 +00:00
|
|
|
expect(buyUltimateFromIntervalTable[0].landed).toEqual(new Date(today));
|
|
|
|
expect(buyUltimateFromIntervalTable[1].landed).toEqual(new Date(today));
|
2018-10-08 08:59:05 +00:00
|
|
|
});
|
|
|
|
|
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() => {
|
2018-10-08 08:59:05 +00:00
|
|
|
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-01-02 12:33:30 +00:00
|
|
|
expect(buyUltimateFromIntervalTable[0].landed).toEqual(new Date(today));
|
|
|
|
expect(buyUltimateFromIntervalTable[1].landed).toEqual(new Date(today));
|
2018-10-08 08:59:05 +00:00
|
|
|
});
|
|
|
|
});
|