2024-01-30 13:00:08 +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-02-19 10:18:05 +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-02-15 10:18:01 +00:00
|
|
|
beforeEach(async() => {
|
2024-01-30 13:00:08 +00:00
|
|
|
ctx = {
|
|
|
|
req: {
|
2024-02-15 10:18:01 +00:00
|
|
|
accessToken: {userId: 9},
|
|
|
|
headers: {origin: 'http://localhost'}
|
|
|
|
},
|
|
|
|
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
|
|
|
|
});
|
|
|
|
|
|
|
|
options = {transaction: tx};
|
|
|
|
tx = await models.ItemShelving.beginTransaction({});
|
|
|
|
options.transaction = tx;
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(async() => {
|
|
|
|
await tx.rollback();
|
2024-01-30 13:00:08 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should add two new records', async() => {
|
|
|
|
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-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
|
|
|
});
|
|
|
|
|
|
|
|
it('should update the visible items', async() => {
|
|
|
|
const shelvingFk = 'GVC';
|
|
|
|
const items = [2, 2];
|
2024-02-15 10:18:01 +00:00
|
|
|
const {visible: itemsBefore} = await models.ItemShelving.findOne({
|
|
|
|
where: {shelvingFk, itemFk: items[0]}
|
|
|
|
}, options);
|
2024-02-19 10:18:05 +00:00
|
|
|
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options);
|
2024-02-15 10:18:01 +00:00
|
|
|
const {visible: itemsAfter} = await models.ItemShelving.findOne({
|
|
|
|
where: {shelvingFk, itemFk: items[0]}
|
|
|
|
}, options);
|
|
|
|
|
|
|
|
expect(itemsAfter).toEqual(itemsBefore + 2);
|
2024-01-30 13:00:08 +00:00
|
|
|
});
|
|
|
|
});
|