salix/back/methods/machine-worker/specs/updateInTime.spec.js

57 lines
1.7 KiB
JavaScript
Raw Normal View History

2024-03-14 07:36:19 +00:00
const {models} = require('vn-loopback/server/server');
2024-03-20 13:36:08 +00:00
const LoopBackContext = require('loopback-context');
2024-03-14 07:36:19 +00:00
2024-03-20 13:36:08 +00:00
// #6276
xdescribe('ItemShelving upsertItem()', () => {
const warehouseFk = 1;
let ctx;
let options;
let tx;
2024-03-14 07:36:19 +00:00
2024-03-20 13:36:08 +00:00
beforeEach(async() => {
2024-03-14 07:36:19 +00:00
ctx = {
req: {
2024-03-20 13:36:08 +00:00
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
2024-03-14 07:36:19 +00:00
};
2024-03-20 13:36:08 +00:00
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
2024-03-14 07:36:19 +00:00
2024-03-20 13:36:08 +00:00
options = {transaction: tx};
tx = await models.ItemShelving.beginTransaction({});
options.transaction = tx;
2024-03-14 07:36:19 +00:00
});
2024-03-20 13:36:08 +00:00
afterEach(async() => {
await tx.rollback();
2024-03-14 07:36:19 +00:00
});
2024-03-20 13:36:08 +00:00
it('should add two new records', async() => {
const shelvingFk = 'ZPP';
const items = [1, 1, 1, 2];
2024-03-14 07:36:19 +00:00
2024-03-20 13:36:08 +00:00
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
2024-03-14 07:36:19 +00:00
2024-03-20 13:36:08 +00:00
expect(itemShelvings.length).toEqual(2);
2024-03-14 07:36:19 +00:00
});
2024-03-20 13:36:08 +00:00
it('should update the visible items', async() => {
const shelvingFk = 'GVC';
const items = [2, 2];
const {visible: itemsBefore} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
const {visible: itemsAfter} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
expect(itemsAfter).toEqual(itemsBefore + 2);
2024-03-14 07:36:19 +00:00
});
});