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

54 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-01-30 13:00:08 +00:00
const {models} = require('vn-loopback/server/server');
2024-03-21 11:02:57 +00:00
describe('ItemShelving upsertItem()', () => {
2024-01-30 13:00:08 +00:00
const warehouseFk = 1;
2024-04-01 09:00:55 +00:00
2024-06-14 06:39:57 +00:00
const ctx = beforeAll.getCtx();
2024-02-15 10:18:01 +00:00
let options;
let tx;
2024-01-30 13:00:08 +00:00
2024-02-15 10:18:01 +00:00
beforeEach(async() => {
options = {transaction: tx};
tx = await models.ItemShelving.beginTransaction({});
options.transaction = tx;
});
afterEach(async() => {
await tx.rollback();
2024-01-30 13:00:08 +00:00
});
2024-04-25 12:28:47 +00:00
it('should add two new records', async() => {
2024-11-13 10:51:23 +00:00
const shelvingCode = 'GVC';
2024-01-30 13:00:08 +00:00
const items = [1, 1, 1, 2];
2024-11-13 10:51:23 +00:00
const {id: shelvingFk} = await models.Shelving.findOne({
where: {
code: shelvingCode
}
});
await models.ItemShelving.upsertItem(ctx, shelvingCode, items, warehouseFk, options);
2024-02-15 10:18:01 +00:00
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
expect(itemShelvings.length).toEqual(2);
2024-01-30 13:00:08 +00:00
});
2024-04-25 12:28:47 +00:00
it('should update the visible items', async() => {
2024-11-13 10:51:23 +00:00
const shelvingCode = 'GVC';
2024-01-30 13:00:08 +00:00
const items = [2, 2];
2024-11-13 10:51:23 +00:00
const {id: shelvingFk} = await models.Shelving.findOne({
where: {
code: shelvingCode
}
});
2024-04-25 12:28:47 +00:00
const {visible: visibleItemsBefore} = await models.ItemShelving.findOne({
2024-02-15 10:18:01 +00:00
where: {shelvingFk, itemFk: items[0]}
}, options);
2024-11-13 10:51:23 +00:00
await models.ItemShelving.upsertItem(ctx, shelvingCode, items, warehouseFk, options);
2024-04-09 05:38:28 +00:00
2024-04-25 12:28:47 +00:00
const {visible: visibleItemsAfter} = await models.ItemShelving.findOne({
2024-02-15 10:18:01 +00:00
where: {shelvingFk, itemFk: items[0]}
}, options);
2024-04-09 05:38:28 +00:00
expect(visibleItemsAfter).toEqual(visibleItemsBefore + 2);
2024-01-30 13:00:08 +00:00
});
});