refs #6915 test_master24_8 #2067
|
@ -1,54 +1,55 @@
|
||||||
const {models} = require('vn-loopback/server/server');
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
const LoopBackContext = require('loopback-context');
|
||||||
|
|
||||||
describe('ItemShelving makeMulti()', () => {
|
fdescribe('ItemShelving makeMulti()', () => {
|
||||||
const warehouseFk = 1;
|
const warehouseFk = 1;
|
||||||
|
let ctx;
|
||||||
|
let options;
|
||||||
|
let tx;
|
||||||
|
|
||||||
beforeAll(async() => {
|
beforeEach(async() => {
|
||||||
ctx = {
|
ctx = {
|
||||||
accessToken: {userId: 9},
|
|
||||||
req: {
|
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() => {
|
it('should add two new records', async() => {
|
||||||
const shelvingFk = 'ZPP';
|
const shelvingFk = 'ZPP';
|
||||||
const items = [1, 1, 1, 2];
|
const items = [1, 1, 1, 2];
|
||||||
const tx = await models.ItemShelving.beginTransaction({});
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
try {
|
await models.ItemShelving.makeMulti(ctx, shelvingFk, items, warehouseFk, options);
|
||||||
await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options);
|
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
|
||||||
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options);
|
|
||||||
|
|
||||||
expect(itemShelvings.length).toEqual(2);
|
expect(itemShelvings.length).toEqual(2);
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update the visible items', async() => {
|
it('should update the visible items', async() => {
|
||||||
const shelvingFk = 'GVC';
|
const shelvingFk = 'GVC';
|
||||||
const items = [2, 2];
|
const items = [2, 2];
|
||||||
const tx = await models.ItemShelving.beginTransaction({});
|
const {visible: itemsBefore} = await models.ItemShelving.findOne({
|
||||||
const options = {transaction: tx};
|
where: {shelvingFk, itemFk: items[0]}
|
||||||
try {
|
}, options);
|
||||||
const {visible: itemsBefore} = await models.ItemShelving.findOne({
|
await models.ItemShelving.makeMulti(ctx, shelvingFk, items, warehouseFk, options);
|
||||||
where: {shelvingFk, itemFk: items[0]}
|
const {visible: itemsAfter} = await models.ItemShelving.findOne({
|
||||||
}, options);
|
where: {shelvingFk, itemFk: items[0]}
|
||||||
await models.ItemShelving.makeMulti(shelvingFk, items, warehouseFk, options);
|
}, options);
|
||||||
const {visible: itemsAfter} = await models.ItemShelving.findOne({
|
|
||||||
where: {shelvingFk, itemFk: items[0]}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(itemsAfter).toEqual(itemsBefore + 2);
|
expect(itemsAfter).toEqual(itemsBefore + 2);
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue