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

58 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-04-09 05:38:28 +00:00
const { models } = require('vn-loopback/server/server');
2024-02-15 10:18:01 +00:00
const LoopBackContext = require('loopback-context');
2024-01-30 13:00:08 +00:00
2024-03-07 10:38:30 +00:00
// #6276
2024-03-21 11:02:57 +00:00
describe('ItemShelving upsertItem()', () => {
2024-01-30 13:00:08 +00:00
const warehouseFk = 1;
2024-02-15 10:18:01 +00:00
let ctx;
let options;
let tx;
2024-01-30 13:00:08 +00:00
2024-04-09 05:38:28 +00:00
beforeEach(async () => {
2024-01-30 13:00:08 +00:00
ctx = {
req: {
2024-04-09 05:38:28 +00:00
accessToken: { userId: 9 },
headers: { origin: 'http://localhost' }
2024-02-15 10:18:01 +00:00
},
args: {}
2024-01-30 13:00:08 +00:00
};
2024-02-15 10:18:01 +00:00
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
2024-04-09 05:38:28 +00:00
options = { transaction: tx };
2024-02-15 10:18:01 +00:00
tx = await models.ItemShelving.beginTransaction({});
options.transaction = tx;
});
2024-04-09 05:38:28 +00:00
afterEach(async () => {
2024-02-15 10:18:01 +00:00
await tx.rollback();
2024-01-30 13:00:08 +00:00
});
2024-04-09 05:38:28 +00:00
it('should add two new records', async () => {
2024-01-30 13:00:08 +00:00
const shelvingFk = 'ZPP';
const items = [1, 1, 1, 2];
2024-02-15 10:18:01 +00:00
2024-02-19 10:18:05 +00:00
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
2024-04-09 05:38:28 +00:00
const itemShelvings = await models.ItemShelving.find({ where: { shelvingFk } }, options);
2024-02-15 10:18:01 +00:00
expect(itemShelvings.length).toEqual(2);
2024-01-30 13:00:08 +00:00
});
2024-04-09 05:38:28 +00:00
it('should update the visible items', async () => {
2024-01-30 13:00:08 +00:00
const shelvingFk = 'GVC';
const items = [2, 2];
2024-04-09 05:38:28 +00:00
const { visible: visibleItemsBefore } = await models.ItemShelving.findOne({
where: { shelvingFk, itemFk: items[0] }
2024-02-15 10:18:01 +00:00
}, options);
2024-02-19 10:18:05 +00:00
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
2024-04-09 05:38:28 +00:00
const { visible: visibleItemsAfter } = await models.ItemShelving.findOne({
where: { shelvingFk, itemFk: items[0] }
2024-02-15 10:18:01 +00:00
}, options);
2024-04-09 05:38:28 +00:00
expect(visibleItemsAfter).toEqual(visibleItemsBefore + 2);
2024-01-30 13:00:08 +00:00
});
});