fix: refs #6276 test & procedure
gitea/salix/pipeline/pr-test Build queued... Details

This commit is contained in:
Jorge Penadés 2024-03-20 15:53:48 +01:00
parent 58b324577a
commit 7a06d1217e
3 changed files with 121 additions and 45 deletions

View File

@ -1,56 +1,132 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context');
// #6276 describe('machineWorker updateInTime()', () => {
xdescribe('ItemShelving upsertItem()', () => { const itBoss = 104;
const warehouseFk = 1; const davidCharles = 1106;
let ctx;
let options;
let tx;
beforeEach(async() => { beforeAll(async() => {
ctx = { ctx = {
req: { req: {
accessToken: {userId: 9}, accessToken: {},
headers: {origin: 'http://localhost'} headers: {origin: 'http://localhost'},
}, __: value => value
args: {} }
}; };
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: ctx.req
}); });
options = {transaction: tx}; it('should throw an error if the plate does not exist', async() => {
tx = await models.ItemShelving.beginTransaction({}); const tx = await models.MachineWorker.beginTransaction({});
options.transaction = tx; const options = {transaction: tx};
}); const plate = 'RE-123';
ctx.req.accessToken.userId = 1106;
afterEach(async() => { try {
await models.MachineWorker.updateInTime(ctx, plate, options);
await tx.rollback(); await tx.rollback();
} catch (e) {
const error = e;
expect(error.message).toContain('the plate does not exist');
await tx.rollback();
}
}); });
it('should add two new records', async() => { it('should grab a machine where is not in use', async() => {
const shelvingFk = 'ZPP'; const tx = await models.MachineWorker.beginTransaction({});
const items = [1, 1, 1, 2]; const options = {transaction: tx};
const plate = 'RE-003';
ctx.req.accessToken.userId = 1107;
try {
const totalBefore = await models.MachineWorker.find(null, options);
await models.MachineWorker.updateInTime(ctx, plate, options);
const totalAfter = await models.MachineWorker.find(null, options);
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); expect(totalAfter.length).toEqual(totalBefore.length + 1);
const itemShelvings = await models.ItemShelving.find({where: {shelvingFk}}, options); await tx.rollback();
} catch (e) {
expect(itemShelvings.length).toEqual(2); await tx.rollback();
}
}); });
it('should update the visible items', async() => { describe('less than 12h', () => {
const shelvingFk = 'GVC'; const plate = 'RE-001';
const items = [2, 2]; it('should trow an error if it is not himself', async() => {
const {visible: itemsBefore} = await models.ItemShelving.findOne({ const tx = await models.MachineWorker.beginTransaction({});
where: {shelvingFk, itemFk: items[0]} const options = {transaction: tx};
ctx.req.accessToken.userId = davidCharles;
try {
await models.MachineWorker.updateInTime(ctx, plate, options);
await tx.rollback();
} catch (e) {
const error = e;
expect(error.message).toContain('This machine is already in use');
await tx.rollback();
}
});
it('should throw an error if it is himself with a different machine', async() => {
const tx = await models.MachineWorker.beginTransaction({});
const options = {transaction: tx};
ctx.req.accessToken.userId = itBoss;
const plate = 'RE-003';
try {
await models.MachineWorker.updateInTime(ctx, plate, options);
await tx.rollback();
} catch (e) {
const error = e;
expect(error.message).toEqual('You are already using a machine');
await tx.rollback();
}
});
it('should set the out time if it is himself', async() => {
const tx = await models.MachineWorker.beginTransaction({});
const options = {transaction: tx};
ctx.req.accessToken.userId = itBoss;
try {
const isNotParked = await models.MachineWorker.findOne({
where: {workerFk: itBoss}
}, options); }, options);
await models.ItemShelving.upsertItem(ctx, shelvingFk, items, warehouseFk, options); await models.MachineWorker.updateInTime(ctx, plate, options);
const {visible: itemsAfter} = await models.ItemShelving.findOne({ const isParked = await models.MachineWorker.findOne({
where: {shelvingFk, itemFk: items[0]} where: {workerFk: itBoss}
}, options); }, options);
expect(itemsAfter).toEqual(itemsBefore + 2); expect(isNotParked.outTime).toBeNull();
expect(isParked.outTime).toBeDefined();
await tx.rollback();
} catch (e) {
await tx.rollback();
}
});
});
describe('equal or more than 12h', () => {
const plate = 'RE-002';
it('should set the out time and grab the machine', async() => {
const tx = await models.MachineWorker.beginTransaction({});
const options = {transaction: tx};
ctx.req.accessToken.userId = davidCharles;
const filter = {
where: {workerFk: davidCharles, machineFk: 2}
};
try {
const isNotParked = await models.MachineWorker.findOne(filter, options);
const totalBefore = await models.MachineWorker.find(null, options);
await models.MachineWorker.updateInTime(ctx, plate, options);
const isParked = await models.MachineWorker.findOne(filter, options);
const totalAfter = await models.MachineWorker.find(null, options);
expect(isNotParked.outTime).toBeNull();
expect(isParked.outTime).toBeDefined();
expect(totalAfter.length).toEqual(totalBefore.length);
await tx.rollback();
} catch (e) {
await tx.rollback();
}
});
}); });
}); });

View File

@ -20,9 +20,9 @@ BEGIN
SELECT barcodeToItem(vBarcode) INTO vItemFk; SELECT barcodeToItem(vBarcode) INTO vItemFk;
SET vPacking = COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1)); SELECT COALESCE(vPacking, GREATEST(vn.itemPacking(vBarcode,vWarehouseFk), 1)) INTO vPacking;
SET vQuantity = vQuantity * vPacking; SELECT vQuantity * vPacking INTO vQuantity;
IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN IF (SELECT COUNT(*) FROM shelving WHERE code = vShelvingFk COLLATE utf8_unicode_ci) = 0 THEN

View File

@ -2,7 +2,7 @@ const {models} = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
// #6276 // #6276
xdescribe('ItemShelving upsertItem()', () => { describe('ItemShelving upsertItem()', () => {
const warehouseFk = 1; const warehouseFk = 1;
let ctx; let ctx;
let options; let options;