salix/modules/item/back/methods/item-shelving/specs/upsertItem.spec.js

54 lines
1.7 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 shelvingCode = 'GVC';
const items = [1, 1, 1, 2];
const {id: shelvingFk} = await models.Shelving.findOne({
where: {
code: shelvingCode
}
});
await models.ItemShelving.upsertItem(ctx, shelvingCode, 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 shelvingCode = 'GVC';
const items = [2, 2];
const {id: shelvingFk} = await models.Shelving.findOne({
where: {
code: shelvingCode
}
});
const {visible: visibleItemsBefore} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
await models.ItemShelving.upsertItem(ctx, shelvingCode, items, warehouseFk, options);
const {visible: visibleItemsAfter} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
expect(visibleItemsAfter).toEqual(visibleItemsBefore + 2);
});
});