number prefixes are now not allowed to contain numbers
This commit is contained in:
parent
4100fb428e
commit
ec03e0699c
13
.idea/libraries/dist.xml
Normal file
13
.idea/libraries/dist.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<component name="libraryTable">
|
||||||
|
<library name="dist" type="javaScript">
|
||||||
|
<properties>
|
||||||
|
<sourceFilesUrls>
|
||||||
|
<item url="file://$PROJECT_DIR$/dist" />
|
||||||
|
</sourceFilesUrls>
|
||||||
|
</properties>
|
||||||
|
<CLASSES>
|
||||||
|
<root url="file://$PROJECT_DIR$/dist" />
|
||||||
|
</CLASSES>
|
||||||
|
<SOURCES />
|
||||||
|
</library>
|
||||||
|
</component>
|
@ -4,7 +4,6 @@ import TemplateTreatmentModel from '../models/treatment_template';
|
|||||||
import TemplateMeasurementModel from '../models/measurement_template';
|
import TemplateMeasurementModel from '../models/measurement_template';
|
||||||
import TestHelper from "../test/helper";
|
import TestHelper from "../test/helper";
|
||||||
|
|
||||||
// TODO: check number prefix to have no numbers
|
|
||||||
|
|
||||||
describe('/template', () => {
|
describe('/template', () => {
|
||||||
let server;
|
let server;
|
||||||
@ -371,14 +370,14 @@ describe('/template', () => {
|
|||||||
res: {status: 'Invalid body format', details: '"parameters[0].name" is required'}
|
res: {status: 'Invalid body format', details: '"parameters[0].name" is required'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('rejects a missing number prefix', done => {
|
it('rejects a number prefix containing numbers', done => {
|
||||||
TestHelper.request(server, done, {
|
TestHelper.request(server, done, {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
url: '/template/treatment/new',
|
url: '/template/treatment/new',
|
||||||
auth: {basic: 'admin'},
|
auth: {basic: 'admin'},
|
||||||
httpStatus: 400,
|
httpStatus: 400,
|
||||||
req: {name: 'heat aging', parameters: [{name: 'time', range: {min: 1}}]},
|
req: {name: 'heat aging', number_prefix: 'AB5', parameters: [{name: 'time', range: {min: 1}}]},
|
||||||
res: {status: 'Invalid body format', details: '"number_prefix" is required'}
|
res: {status: 'Invalid body format', details: '"number_prefix" with value "AB5" fails to match the required pattern: /^[a-zA-Z]+$/'}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
it('rejects a missing parameter range', done => {
|
it('rejects a missing parameter range', done => {
|
||||||
|
@ -1,35 +1,36 @@
|
|||||||
import joi from '@hapi/joi';
|
import Joi from '@hapi/joi';
|
||||||
import IdValidate from './id';
|
import IdValidate from './id';
|
||||||
|
|
||||||
export default class TemplateValidate {
|
export default class TemplateValidate {
|
||||||
private static template = {
|
private static template = {
|
||||||
name: joi.string()
|
name: Joi.string()
|
||||||
.max(128),
|
.max(128),
|
||||||
|
|
||||||
version: joi.number()
|
version: Joi.number()
|
||||||
.min(1),
|
.min(1),
|
||||||
|
|
||||||
number_prefix: joi.string()
|
number_prefix: Joi.string()
|
||||||
|
.pattern(/^[a-zA-Z]+$/)
|
||||||
.min(1)
|
.min(1)
|
||||||
.max(16),
|
.max(16),
|
||||||
|
|
||||||
parameters: joi.array()
|
parameters: Joi.array()
|
||||||
.min(1)
|
.min(1)
|
||||||
.items(
|
.items(
|
||||||
joi.object({
|
Joi.object({
|
||||||
name: joi.string()
|
name: Joi.string()
|
||||||
.max(128)
|
.max(128)
|
||||||
.required(),
|
.required(),
|
||||||
|
|
||||||
range: joi.object({
|
range: Joi.object({
|
||||||
values: joi.array()
|
values: Joi.array()
|
||||||
.min(1),
|
.min(1),
|
||||||
|
|
||||||
min: joi.number(),
|
min: Joi.number(),
|
||||||
|
|
||||||
max: joi.number(),
|
max: Joi.number(),
|
||||||
|
|
||||||
type: joi.string()
|
type: Joi.string()
|
||||||
.valid('array')
|
.valid('array')
|
||||||
})
|
})
|
||||||
.oxor('values', 'min')
|
.oxor('values', 'min')
|
||||||
@ -45,14 +46,14 @@ export default class TemplateValidate {
|
|||||||
static input (data, param, template) { // validate data, param: new(everything required)/change(available attributes are validated)
|
static input (data, param, template) { // validate data, param: new(everything required)/change(available attributes are validated)
|
||||||
if (param === 'new') {
|
if (param === 'new') {
|
||||||
if (template === 'treatment') {
|
if (template === 'treatment') {
|
||||||
return joi.object({
|
return Joi.object({
|
||||||
name: this.template.name.required(),
|
name: this.template.name.required(),
|
||||||
number_prefix: this.template.number_prefix.required(),
|
number_prefix: this.template.number_prefix.required(),
|
||||||
parameters: this.template.parameters.required()
|
parameters: this.template.parameters.required()
|
||||||
}).validate(data);
|
}).validate(data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return joi.object({
|
return Joi.object({
|
||||||
name: this.template.name.required(),
|
name: this.template.name.required(),
|
||||||
parameters: this.template.parameters.required()
|
parameters: this.template.parameters.required()
|
||||||
}).validate(data);
|
}).validate(data);
|
||||||
@ -60,14 +61,14 @@ export default class TemplateValidate {
|
|||||||
}
|
}
|
||||||
else if (param === 'change') {
|
else if (param === 'change') {
|
||||||
if (template === 'treatment') {
|
if (template === 'treatment') {
|
||||||
return joi.object({
|
return Joi.object({
|
||||||
name: this.template.name,
|
name: this.template.name,
|
||||||
number_prefix: this.template.number_prefix,
|
number_prefix: this.template.number_prefix,
|
||||||
parameters: this.template.parameters
|
parameters: this.template.parameters
|
||||||
}).validate(data);
|
}).validate(data);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return joi.object({
|
return Joi.object({
|
||||||
name: this.template.name,
|
name: this.template.name,
|
||||||
parameters: this.template.parameters
|
parameters: this.template.parameters
|
||||||
}).validate(data);
|
}).validate(data);
|
||||||
@ -98,7 +99,7 @@ export default class TemplateValidate {
|
|||||||
parameters: this.template.parameters
|
parameters: this.template.parameters
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
const {value, error} = joi.object(joiObject).validate(data, {stripUnknown: true});
|
const {value, error} = Joi.object(joiObject).validate(data, {stripUnknown: true});
|
||||||
return error !== undefined? null : value;
|
return error !== undefined? null : value;
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user