7152-devToTest_2414 #2228

Merged
alexm merged 636 commits from 7152-devToTest_2414 into test 2024-03-28 08:26:34 +00:00
5 changed files with 29 additions and 6 deletions
Showing only changes of commit b7ce6cac9c - Show all commits

View File

@ -1,6 +1,6 @@
const {models} = require('vn-loopback/server/server');
fdescribe('machineWorker updateInTime()', () => {
describe('machineWorker updateInTime()', () => {
const itBoss = 104;
const davidCharles = 1106;
@ -65,6 +65,22 @@ fdescribe('machineWorker updateInTime()', () => {
}
});
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};

View File

@ -51,15 +51,19 @@ module.exports = Self => {
const {maxHours} = await models.MachineWorkerConfig.findOne({fields: ['maxHours']}, myOptions);
const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000);
const isHimSelf = userId == machineWorker.workerFk;
const isSameMachine = machine.id == machineWorker.machineFk;
if (maxHours > hoursDifference && !isHimSelf)
if (hoursDifference < maxHours && !isHimSelf)
throw new UserError($t('This machine is already in use.'));
if (hoursDifference < maxHours && isHimSelf && !isSameMachine)
throw new UserError($t('You are already using a machine'));
await machineWorker.updateAttributes({
outTime: Date.vnNew()
}, myOptions);
if (maxHours <= hoursDifference)
if (hoursDifference >= maxHours)
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);
} else
await models.MachineWorker.create({machineFk: machine.id, workerFk: userId}, myOptions);

View File

@ -20,8 +20,8 @@ describe('mobileAppVersionControl getVersion()', () => {
});
it('should get the beta version app', async() => {
const {version, versionBeta} = await models.MobileAppVersionControl.getVersion(ctx, appName);
ctx.req.accessToken.userId = 66;
const {version, versionBeta} = await models.MobileAppVersionControl.getVersion(ctx, appName);
expect(versionBeta).toBeDefined();
expect(version).toBeUndefined();

View File

@ -207,5 +207,7 @@
"This machine is already in use.": "This machine is already in use.",
"the plate does not exist": "The plate {{plate}} does not exist",
"This pallet does not exist": "This pallet does not exist",
"We do not have availability for the selected item": "We do not have availability for the selected item"
"We do not have availability for the selected item": "We do not have availability for the selected item",
"You are already using a machine": "You are already using a machine"
}

View File

@ -344,5 +344,6 @@
"the plate does not exist": "La máquina {{plate}} no existe",
"This pallet does not exist": "Este palet no existe",
"We do not have availability for the selected item": "No tenemos disponible el item seleccionado",
"Esta máquina ya está en uso.": "Esta máquina ya está en uso."
"You are already using a machine": "Ya estás usando una máquina.",
"Ya estás usando una máquina.": "Ya estás usando una máquina."
}