fix(measurement service): Implemented correct check of schema keys in _isValidMeasurment. (#3750)
This commit is contained in:
parent
423ba7c269
commit
db395852b6
@ -324,6 +324,25 @@ describe('MeasurementService.js', () => {
|
|||||||
}).toThrow();
|
}).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws Error if adding measurement with unknown schema key', () => {
|
||||||
|
measurementService.addMapping(
|
||||||
|
source,
|
||||||
|
annotationType,
|
||||||
|
matchingCriteria,
|
||||||
|
toSourceSchema,
|
||||||
|
() => {
|
||||||
|
return {
|
||||||
|
...measurement,
|
||||||
|
invalidSchemaKey: 0,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(() => {
|
||||||
|
source.annotationToMeasurement(annotationType, measurement);
|
||||||
|
}).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
it('updates existing measurement', () => {
|
it('updates existing measurement', () => {
|
||||||
measurementService.addMapping(
|
measurementService.addMapping(
|
||||||
source,
|
source,
|
||||||
|
|||||||
@ -691,14 +691,14 @@ class MeasurementService extends PubSubService {
|
|||||||
* @return {boolean} Measurement validation
|
* @return {boolean} Measurement validation
|
||||||
*/
|
*/
|
||||||
_isValidMeasurement(measurementData) {
|
_isValidMeasurement(measurementData) {
|
||||||
Object.keys(measurementData).forEach(key => {
|
return Object.keys(measurementData).every(key => {
|
||||||
if (!MEASUREMENT_SCHEMA_KEYS.includes(key)) {
|
if (!MEASUREMENT_SCHEMA_KEYS.includes(key)) {
|
||||||
log.warn(`Invalid measurement key: ${key}`);
|
log.warn(`Invalid measurement key: ${key}`);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user