refactor: refs #6346 requested changes

This commit is contained in:
Jon Elias 2024-09-10 07:50:40 +02:00
parent b3aa263cea
commit 125c0c9b3b
5 changed files with 67 additions and 11 deletions

View File

@ -1,6 +1,6 @@
DROP TABLE IF EXISTS vn.wagonTypeTray; DROP TABLE IF EXISTS vn.wagonTypeTray;
CREATE TABLE vn.wagonTypeTray ( CREATE OR REPLACE TABLE vn.wagonTypeTray (
id INT UNSIGNED auto_increment NULL, id INT UNSIGNED auto_increment NULL,
wagonTypeFk int(11) unsigned NULL, wagonTypeFk int(11) unsigned NULL,
height INT UNSIGNED NULL, height INT UNSIGNED NULL,

View File

@ -236,6 +236,8 @@
"Cannot send mail": "Cannot send mail", "Cannot send mail": "Cannot send mail",
"CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`", "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`": "CONSTRAINT `chkParkingCodeFormat` failed for `vn`.`parking`",
"This postcode already exists": "This postcode already exists", "This postcode already exists": "This postcode already exists",
"Original invoice not found": "Original invoice not found" "Original invoice not found": "Original invoice not found",
"There is already a tray with the same height": "There is already a tray with the same height",
"The height must be greater than 50cm": "The height must be greater than 50cm",
"The maximum height of the wagon is 200cm": "The maximum height of the wagon is 200cm"
} }

View File

@ -374,7 +374,6 @@
"Original invoice not found": "Factura original no encontrada", "Original invoice not found": "Factura original no encontrada",
"The entry has no lines or does not exist": "La entrada no tiene lineas o no existe", "The entry has no lines or does not exist": "La entrada no tiene lineas o no existe",
"There is already a tray with the same height": "Ya existe una bandeja con la misma altura", "There is already a tray with the same height": "Ya existe una bandeja con la misma altura",
"You must define wagon and height": "Debes definir un tipo de vagón y la altura", "The height must be greater than 50cm": "La altura debe ser superior a 50cm",
"The maximum height of the wagon is": "La altura máxima es %d", "The maximum height of the wagon is 200cm": "La altura máxima es 200cm"
"The height must be greater than": "The height must be greater than %d"
} }

View File

@ -0,0 +1,58 @@
const models = require('vn-loopback/server/server').models;
fdescribe('WagonTray max height()', () => {
it(`should throw an error if the tray's height is above the maximum of the wagon`, async() => {
const tx = await models.WagonTypeTray.beginTransaction({});
let error;
try {
const options = {transaction: tx};
await models.WagonTypeTray.create({height: 210, wagonTypeFk: 1, wagonTypeColorFk: 4}, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toBe('The maximum height of the wagon is 200cm');
});
it(`should throw an error if the tray's height is already in the wagon`, async() => {
const tx = await models.WagonTypeTray.beginTransaction({});
let error;
try {
const options = {transaction: tx};
await models.WagonTypeTray.create({height: 50, wagonTypeFk: 1, wagonTypeColorFk: 2}, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toBe('There is already a tray with the same height');
});
it(`should throw an error if the tray's height is below the minimum between the trays`, async() => {
const tx = await models.WagonTypeTray.beginTransaction({});
let error;
try {
const options = {transaction: tx};
await models.WagonTypeTray.create({height: 40, wagonTypeFk: 1, wagonTypeColorFk: 4}, options);
await tx.rollback();
} catch (e) {
await tx.rollback();
error = e;
}
expect(error.message).toBe('The height must be greater than 50cm');
});
});

View File

@ -15,14 +15,11 @@ module.exports = Self => {
if (tray.length) if (tray.length)
throw new UserError('There is already a tray with the same height'); throw new UserError('There is already a tray with the same height');
if (!wagonTypeFk && !height)
throw new UserError('You must define wagon and height');
if (height < config.minHeightBetweenTrays) if (height < config.minHeightBetweenTrays)
throw new UserError('The height must be greater than', 'HEIGHT_GREATER_THAN', config.minHeightBetweenTrays); throw new UserError('The height must be greater than 50cm');
if (height > config.maxWagonHeight) if (height > config.maxWagonHeight)
throw new UserError('The maximum height of the wagon is', 'MAX_WAGON_HEIGHT', config.maxWagonHeight); throw new UserError('The maximum height of the wagon is 200cm');
} }
}); });
}; };