#6776 makeMulti & itemShelvin_add refactor #1970

Merged
jorgep merged 11 commits from 6776-makeMulti into dev 2024-02-19 12:23:45 +00:00
1 changed files with 33 additions and 32 deletions
Showing only changes of commit be7a570314 - Show all commits

View File

@ -1,54 +1,55 @@
const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
describe('ItemShelving makeMulti()', () => {
fdescribe('ItemShelving makeMulti()', () => {
const warehouseFk = 1;
let ctx;
let options;
let tx;
beforeAll(async() => {
beforeEach(async() => {
ctx = {
accessToken: {userId: 9},
req: {
headers: {origin: 'http://localhost'},
}
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
},
args: {}
};
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
});
options = {transaction: tx};
tx = await models.ItemShelving.beginTransaction({});
options.transaction = tx;
});
afterEach(async() => {
await tx.rollback();
});
it('should add two new records', async() => {
const shelvingFk = 'ZPP';
const items = [1, 1, 1, 2];
const tx = await models.ItemShelving.beginTransaction({});
const options = {transaction: tx};
try {
await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options);
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
await models.ItemShelving.makeMulti(ctx, shelvingFk, items, warehouseFk, options);
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
expect(itemShelvings.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
expect(itemShelvings.length).toEqual(2);
});
it('should update the visible items', async() => {
const shelvingFk = 'GVC';
const items = [2, 2];
const tx = await models.ItemShelving.beginTransaction({});
const options = {transaction: tx};
try {
const {visible: itemsBefore} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options);
const {visible: itemsAfter} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
const {visible: itemsBefore} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
await models.ItemShelving.makeMulti(ctx, shelvingFk, items, warehouseFk, options);
const {visible: itemsAfter} = await models.ItemShelving.findOne({
where: {shelvingFk, itemFk: items[0]}
}, options);
expect(itemsAfter).toEqual(itemsBefore + 2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
expect(itemsAfter).toEqual(itemsBefore + 2);
});
});