const {models} = require('vn-loopback/server/server'); describe('item makeMulti()', () => { const warehouseFk = 1; beforeAll(async() => { ctx = { accessToken: {userId: 9}, req: { headers: {origin: 'http://localhost'}, } }; }); it('should add two new records', async() => { const shelvingFk = 'ZPP'; const items = [1, 1, 1, 2]; const tx = await models.ItemShelving.beginTransaction({}); const options = {transaction: tx}; try { await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options); const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); expect(itemShelvings.length).toEqual(2); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } }); it('should update the visible items', async() => { const shelvingFk = 'GVC'; const items = [2, 2]; const tx = await models.ItemShelving.beginTransaction({}); const options = {transaction: tx}; try { const {visible: itemsBefore} = await models.ItemShelving.findOne({ where: {shelvingFk, itemFk: items[0]} }, options); await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options); const {visible: itemsAfter} = await models.ItemShelving.findOne({ where: {shelvingFk, itemFk: items[0]} }, options); expect(itemsAfter).toEqual(itemsBefore + 2); await tx.rollback(); } catch (e) { await tx.rollback(); throw e; } }); });