This commit is contained in:
znetsixe
2026-03-11 11:13:05 +01:00
parent c60aa40666
commit 27a6d3c709
20 changed files with 1555 additions and 229 deletions

View File

@@ -25,6 +25,30 @@ const schema = {
default: 'sensor',
rules: { type: 'string' },
},
asset: {
default: {},
rules: {
type: 'object',
schema: {
unit: {
default: 'm3/h',
rules: { type: 'string' },
},
curveUnits: {
default: {},
rules: {
type: 'object',
schema: {
power: {
default: 'kW',
rules: { type: 'string' },
},
},
},
},
},
},
},
};
test('validateSchema applies defaults and type coercion where supported', () => {
@@ -32,7 +56,7 @@ test('validateSchema applies defaults and type coercion where supported', () =>
const result = validation.validateSchema({ enabled: 'true', name: 'SENSOR' }, schema, 'test');
assert.equal(result.enabled, true);
assert.equal(result.name, 'sensor');
assert.equal(result.name, 'SENSOR');
assert.equal(result.mode, 'auto');
assert.equal(result.functionality.softwareType, 'measurement');
});
@@ -60,3 +84,58 @@ test('removeUnwantedKeys handles primitive values without throwing', () => {
};
assert.doesNotThrow(() => validation.removeUnwantedKeys(input));
});
test('unit-like fields preserve case while regular strings are normalized', () => {
const validation = new ValidationUtils(false, 'error');
const result = validation.validateSchema(
{
name: 'RotatingMachine',
asset: {
unit: 'kW',
curveUnits: { power: 'kW' },
},
},
schema,
'machine'
);
assert.equal(result.name, 'RotatingMachine');
assert.equal(result.asset.unit, 'kW');
assert.equal(result.asset.curveUnits.power, 'kW');
});
test('array with minLength 0 accepts empty arrays without fallback warning path', () => {
const validation = new ValidationUtils(false, 'error');
const localSchema = {
functionality: {
softwareType: {
default: 'measurement',
rules: { type: 'string' },
},
},
assetRegistration: {
default: { childAssets: ['default'] },
rules: {
type: 'object',
schema: {
childAssets: {
default: ['default'],
rules: {
type: 'array',
itemType: 'string',
minLength: 0,
},
},
},
},
},
};
const result = validation.validateSchema(
{ assetRegistration: { childAssets: [] } },
localSchema,
'measurement'
);
assert.deepEqual(result.assetRegistration.childAssets, []);
});