From 3620b864b7669656c1764435cda9bf85d0963c6f Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Wed, 21 Nov 2018 11:48:04 +0100 Subject: [PATCH] #712 PROCEDURE cache.last_buy_refresh() unit test --- .../db/tests/cache/last_buy_refresh.spec.js | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 services/db/tests/cache/last_buy_refresh.spec.js diff --git a/services/db/tests/cache/last_buy_refresh.spec.js b/services/db/tests/cache/last_buy_refresh.spec.js new file mode 100644 index 000000000..44d25c27e --- /dev/null +++ b/services/db/tests/cache/last_buy_refresh.spec.js @@ -0,0 +1,41 @@ +const app = require(`../../../ticket/server/server`); +const server = require(`../../../loopback/server/server`); +const ParameterizedSQL = server.loopbackConnector.ParameterizedSQL; + +describe('last_buy_refresh()', () => { + it(`should store some data on cache.last_buy`, async () => { + 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]; + + expect(lastBuyTable.length).toEqual(4); + + expect(lastBuyTable[0].item_id).toEqual(1); + expect(lastBuyTable[1].item_id).toEqual(2); + expect(lastBuyTable[2].item_id).toEqual(3); + expect(lastBuyTable[3].item_id).toEqual(4); + + expect(lastBuyTable[0].warehouse_id).toEqual(1); + expect(lastBuyTable[1].warehouse_id).toEqual(1); + expect(lastBuyTable[2].warehouse_id).toEqual(1); + expect(lastBuyTable[3].warehouse_id).toEqual(1); + + expect(lastBuyTable[1].buy_id).toEqual(4); + expect(lastBuyTable[0].buy_id).toEqual(3); + expect(lastBuyTable[2].buy_id).toEqual(5); + expect(lastBuyTable[3].buy_id).toEqual(6); + }); +});