salix/db/tests/cache/last_buy_refresh.spec.js

43 lines
1.6 KiB
JavaScript

const app = require(`${loopbackApp}`);
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
describe('last_buy_refresh()', () => {
it(`should store some data on cache.last_buy`, async() => {
const stmts = [];
stmts.push('START TRANSACTION');
const lastBuyTableIndex = stmts.push(`SELECT * FROM cache.last_buy ORDER BY item_id ASC`) - 1;
stmts.push('ROLLBACK');
const sql = ParameterizedSQL.join(stmts, ';');
const result = await app.models.Ticket.rawStmt(sql);
const lastBuyTable = result[lastBuyTableIndex];
expect(lastBuyTable.length).toEqual(12);
expect(lastBuyTable[0].item_id).toEqual(1);
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);
expect(lastBuyTable[0].warehouse_id).toEqual(1);
expect(lastBuyTable[1].warehouse_id).toEqual(3);
expect(lastBuyTable[2].warehouse_id).toEqual(5);
expect(lastBuyTable[3].warehouse_id).toEqual(1);
expect(lastBuyTable[4].warehouse_id).toEqual(5);
expect(lastBuyTable[5].warehouse_id).toEqual(1);
expect(lastBuyTable[1].buy_id).toEqual(10);
expect(lastBuyTable[0].buy_id).toEqual(3);
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);
});
});