fix(measurement service): Implemented correct check of schema keys in _isValidMeasurment. (#3750)

This commit is contained in:
Joe Boccanfuso 2023-10-30 10:44:21 -04:00 committed by GitHub
parent 423ba7c269
commit db395852b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 3 deletions

View File

@ -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,

View File

@ -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;
});
} }
/** /**