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-11-21 10:48:04 +00:00
|
|
|
|
|
|
|
describe('last_buy_refresh()', () => {
|
2019-01-02 12:33:30 +00:00
|
|
|
it(`should store some data on cache.last_buy`, async() => {
|
2018-11-21 10:48:04 +00:00
|
|
|
let stmts = [];
|
|
|
|
let stmt;
|
|
|
|
|
|
|
|
stmts.push('START TRANSACTION');
|
|
|
|
|
|
|
|
stmt = new ParameterizedSQL('CALL cache.last_buy_refresh(true)');
|
|
|
|
stmts.push(stmt);
|
|
|
|
|
|
|
|
let lastBuyTableIndex = stmts.push(`SELECT * FROM cache.last_buy ORDER BY item_id ASC`) - 1;
|
|
|
|
|
|
|
|
stmts.push('ROLLBACK');
|
|
|
|
|
|
|
|
let sql = ParameterizedSQL.join(stmts, ';');
|
|
|
|
let result = await app.models.Ticket.rawStmt(sql);
|
|
|
|
|
|
|
|
let lastBuyTable = result[lastBuyTableIndex];
|
|
|
|
|
2019-07-25 11:32:25 +00:00
|
|
|
expect(lastBuyTable.length).toEqual(12);
|
2018-11-21 10:48:04 +00:00
|
|
|
|
|
|
|
expect(lastBuyTable[0].item_id).toEqual(1);
|
2019-07-25 11:32:25 +00:00
|
|
|
expect(lastBuyTable[1].item_id).toEqual(1);
|
|
|
|
expect(lastBuyTable[2].item_id).toEqual(1);
|
|
|
|
expect(lastBuyTable[3].item_id).toEqual(2);
|
|
|
|
expect(lastBuyTable[4].item_id).toEqual(2);
|
|
|
|
expect(lastBuyTable[5].item_id).toEqual(3);
|
2018-11-21 10:48:04 +00:00
|
|
|
|
|
|
|
expect(lastBuyTable[0].warehouse_id).toEqual(1);
|
2019-07-25 11:32:25 +00:00
|
|
|
expect(lastBuyTable[1].warehouse_id).toEqual(3);
|
|
|
|
expect(lastBuyTable[2].warehouse_id).toEqual(5);
|
2018-11-21 10:48:04 +00:00
|
|
|
expect(lastBuyTable[3].warehouse_id).toEqual(1);
|
2019-07-25 11:32:25 +00:00
|
|
|
expect(lastBuyTable[4].warehouse_id).toEqual(5);
|
2019-06-19 05:20:02 +00:00
|
|
|
expect(lastBuyTable[5].warehouse_id).toEqual(1);
|
2018-11-21 10:48:04 +00:00
|
|
|
|
2019-07-25 11:32:25 +00:00
|
|
|
expect(lastBuyTable[1].buy_id).toEqual(10);
|
2018-11-21 10:48:04 +00:00
|
|
|
expect(lastBuyTable[0].buy_id).toEqual(3);
|
2019-07-25 11:32:25 +00:00
|
|
|
expect(lastBuyTable[2].buy_id).toEqual(13);
|
|
|
|
expect(lastBuyTable[3].buy_id).toEqual(4);
|
|
|
|
expect(lastBuyTable[4].buy_id).toEqual(14);
|
|
|
|
expect(lastBuyTable[5].buy_id).toEqual(5);
|
2018-11-21 10:48:04 +00:00
|
|
|
});
|
|
|
|
});
|