7152-devToTest_2414 #2228
|
@ -0,0 +1,116 @@
|
||||||
|
const {models} = require('vn-loopback/server/server');
|
||||||
|
|
||||||
|
fdescribe('machineWorker updateInTime()', () => {
|
||||||
|
const itBoss = 104;
|
||||||
|
const davidCharles = 1106;
|
||||||
|
|
||||||
|
beforeAll(async() => {
|
||||||
|
ctx = {
|
||||||
|
req: {
|
||||||
|
accessToken: {},
|
||||||
|
headers: {origin: 'http://localhost'},
|
||||||
|
__: value => value
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should throw an error if the plate does not exist', async() => {
|
||||||
|
const tx = await models.MachineWorker.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const plate = 'RE-123';
|
||||||
|
ctx.req.accessToken.userId = 1106;
|
||||||
|
try {
|
||||||
|
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
const error = e;
|
||||||
|
|
||||||
|
expect(error.message).toContain('the plate does not exist');
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should grab a machine where is not in use', async() => {
|
||||||
|
const tx = await models.MachineWorker.beginTransaction({});
|
||||||
|
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);
|
||||||
|
|
||||||
|
expect(totalAfter.length).toEqual(totalBefore.length + 1);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('less than 12h', () => {
|
||||||
|
const plate = 'RE-001';
|
||||||
|
it('should trow an error if it is not himself', async() => {
|
||||||
|
const tx = await models.MachineWorker.beginTransaction({});
|
||||||
|
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 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);
|
||||||
|
await models.MachineWorker.updateInTime(ctx, plate, options);
|
||||||
|
const isParked = await models.MachineWorker.findOne({
|
||||||
|
where: {workerFk: itBoss}
|
||||||
|
}, options);
|
||||||
|
|
||||||
|
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 + 1);
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -18,6 +18,7 @@ module.exports = Self => {
|
||||||
Self.updateInTime = async(ctx, plate, options) => {
|
Self.updateInTime = async(ctx, plate, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const userId = ctx.req.accessToken.userId;
|
const userId = ctx.req.accessToken.userId;
|
||||||
|
const $t = ctx.req.__;
|
||||||
|
|
||||||
let tx;
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
@ -35,11 +36,13 @@ module.exports = Self => {
|
||||||
fields: ['id', 'plate'],
|
fields: ['id', 'plate'],
|
||||||
where: {plate}
|
where: {plate}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
if (!machine) throw new Error(`plate ${plate} does not exist.`);
|
|
||||||
|
if (!machine)
|
||||||
|
throw new Error($t('the plate does not exist', {plate}));
|
||||||
|
|
||||||
const machineWorker = await Self.findOne({
|
const machineWorker = await Self.findOne({
|
||||||
where: {
|
where: {
|
||||||
machineFk: machine.id,
|
or: [{machineFk: machine.id}, {workerFk: userId}],
|
||||||
outTime: null,
|
outTime: null,
|
||||||
}
|
}
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
@ -49,7 +52,8 @@ module.exports = Self => {
|
||||||
const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000);
|
const hoursDifference = (Date.vnNow() - machineWorker.inTime.getTime()) / (60 * 60 * 1000);
|
||||||
const isHimSelf = userId == machineWorker.workerFk;
|
const isHimSelf = userId == machineWorker.workerFk;
|
||||||
|
|
||||||
if (maxHours > hoursDifference && !isHimSelf) throw new UserError('This machine is already in use.');
|
if (maxHours > hoursDifference && !isHimSelf)
|
||||||
|
throw new UserError($t('This machine is already in use.'));
|
||||||
|
|
||||||
await machineWorker.updateAttributes({
|
await machineWorker.updateAttributes({
|
||||||
outTime: Date.vnNew()
|
outTime: Date.vnNew()
|
||||||
|
|
|
@ -3700,4 +3700,12 @@ UPDATE vn.sale
|
||||||
INSERT INTO machineWorkerConfig(maxHours)
|
INSERT INTO machineWorkerConfig(maxHours)
|
||||||
VALUES(12);
|
VALUES(12);
|
||||||
|
|
||||||
INSERT INTO workerAppTester(workerFk) VALUES(66)
|
INSERT INTO workerAppTester(workerFk) VALUES(66);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmentFk`, `type`, `use`, `productionYear`, `workerFk`, `companyFk`)
|
||||||
|
VALUES
|
||||||
|
('RE-003', 'IRON', 'JPH-24', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442);
|
||||||
|
|
||||||
|
|
||||||
|
INSERT INTO machineWorker(workerFk,machineFk,inTimed)
|
||||||
|
VALUES (104,1,'2001-01-01 10:00:00.00.000');
|
|
@ -205,6 +205,7 @@
|
||||||
"It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}",
|
"It was not able to remove the next expeditions:": "It was not able to remove the next expeditions: {{expeditions}}",
|
||||||
"Incorrect pin": "Incorrect pin.",
|
"Incorrect pin": "Incorrect pin.",
|
||||||
"This machine is already in use.": "This machine is already in use.",
|
"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",
|
"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"
|
||||||
}
|
}
|
|
@ -341,6 +341,8 @@
|
||||||
"No hay tickets para sacar": "No hay tickets para sacar",
|
"No hay tickets para sacar": "No hay tickets para sacar",
|
||||||
"There is no zone for these parameters 999999": "There is no zone for these parameters 999999",
|
"There is no zone for these parameters 999999": "There is no zone for these parameters 999999",
|
||||||
"This machine is already in use.": "Esta máquina ya está en uso.",
|
"This machine is already in use.": "Esta máquina ya está en uso.",
|
||||||
|
"the plate does not exist": "La máquina {{plate}} no existe",
|
||||||
"This pallet does not exist": "Este palet 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",
|
"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."
|
||||||
}
|
}
|
|
@ -3,7 +3,6 @@ const {models} = require('vn-loopback/server/server');
|
||||||
describe('itemShelving return()', () => {
|
describe('itemShelving return()', () => {
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
ctx = {
|
ctx = {
|
||||||
accessToken: {userId: 9},
|
|
||||||
req: {
|
req: {
|
||||||
headers: {origin: 'http://localhost'},
|
headers: {origin: 'http://localhost'},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('card', {
|
Self.remoteMethod('card', {
|
||||||
description: 'Idk',
|
description: 'Get the data from an item',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
http: {
|
http: {
|
||||||
path: `/card`,
|
path: `/card`,
|
||||||
|
|
|
@ -3,7 +3,6 @@ const {models} = require('vn-loopback/server/server');
|
||||||
describe('expeditonPallet getPallet()', () => {
|
describe('expeditonPallet getPallet()', () => {
|
||||||
beforeAll(async() => {
|
beforeAll(async() => {
|
||||||
ctx = {
|
ctx = {
|
||||||
accessToken: {userId: 9},
|
|
||||||
req: {
|
req: {
|
||||||
headers: {origin: 'http://localhost'},
|
headers: {origin: 'http://localhost'},
|
||||||
__: value => value
|
__: value => value
|
||||||
|
|
Loading…
Reference in New Issue