Skip to content

Commit

Permalink
fix(measurement service): Implemented correct check of schema keys in…
Browse files Browse the repository at this point in the history
… _isValidMeasurment. (#3750)
  • Loading branch information
jbocce authored Oct 30, 2023
1 parent 423ba7c commit db39585
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,25 @@ describe('MeasurementService.js', () => {
}).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', () => {
measurementService.addMapping(
source,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -691,14 +691,14 @@ class MeasurementService extends PubSubService {
* @return {boolean} Measurement validation
*/
_isValidMeasurement(measurementData) {
Object.keys(measurementData).forEach(key => {
return Object.keys(measurementData).every(key => {
if (!MEASUREMENT_SCHEMA_KEYS.includes(key)) {
log.warn(`Invalid measurement key: ${key}`);
return false;
}
});

return true;
return true;
});
}

/**
Expand Down

0 comments on commit db39585

Please sign in to comment.