45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
const {models} = require('vn-loopback/server/server');
|
|
|
|
describe('ItemShelving upsertItem()', () => {
|
|
const warehouseFk = 1;
|
|
|
|
const ctx = beforeAll.getCtx();
|
|
let options;
|
|
let tx;
|
|
|
|
beforeEach(async() => {
|
|
options = {transaction: tx};
|
|
tx = await models.ItemShelving.beginTransaction({});
|
|
options.transaction = tx;
|
|
});
|
|
|
|
afterEach(async() => {
|
|
await tx.rollback();
|
|
});
|
|
|
|
it('should add two new records', async() => {
|
|
const shelvingFk = 'GVC';
|
|
const items = [1, 1, 1, 2];
|
|
|
|
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
|
|
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
|
|
|
|
expect(itemShelvings.length).toEqual(2);
|
|
});
|
|
|
|
it('should update the visible items', async() => {
|
|
const shelvingFk = 'GVC';
|
|
const items = [2, 2];
|
|
const {visible: visibleItemsBefore} = await models.ItemShelving.findOne({
|
|
where: {shelvingFk, itemFk: items[0]}
|
|
}, options);
|
|
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
|
|
|
|
const {visible: visibleItemsAfter} = await models.ItemShelving.findOne({
|
|
where: {shelvingFk, itemFk: items[0]}
|
|
}, options);
|
|
|
|
expect(visibleItemsAfter).toEqual(visibleItemsBefore + 2);
|
|
});
|
|
});
|