fix: refs #6776 test
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Jorge Penadés 2024-02-15 11:18:01 +01:00
parent bec574ff99
commit be7a570314
1 changed files with 33 additions and 32 deletions

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);
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;
}
});
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);
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;
}
});
});