Skip to content

Commit 491ed34

Browse files
Enhance input validation to ignore empty object properties
1 parent bffcdaf commit 491ed34

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/sdkClient/__tests__/clientInputValidation.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,14 @@ describe('clientInputValidationDecorator', () => {
9494
expect(logSpy).toHaveBeenLastCalledWith('[WARN] splitio => getTreatment: Property "toSanitize" is of invalid type. Setting value to null.');
9595
expect(client.getTreatment).toBeCalledWith('key', 'ff', undefined, { properties: { toSanitize: null, correct: 100 }});
9696
});
97+
98+
test('should ignore the properties in the 4th argument if an empty object is passed', () => {
99+
expect(clientWithValidation.getTreatment('key', 'ff', undefined, { properties: {} })).toBe(EVALUATION_RESULT);
100+
expect(client.getTreatment).toHaveBeenLastCalledWith('key', 'ff', undefined, undefined);
101+
102+
expect(clientWithValidation.getTreatment('key', 'ff', undefined, { properties: undefined })).toBe(EVALUATION_RESULT);
103+
expect(client.getTreatment).toHaveBeenLastCalledWith('key', 'ff', undefined, undefined);
104+
105+
expect(logSpy).not.toBeCalled();
106+
});
97107
});

src/utils/inputValidation/eventProperties.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export function validateEventProperties(log: ILogger, maybeProperties: any, meth
7070
export function validateEvaluationOptions(log: ILogger, maybeOptions: any, method: string): SplitIO.EvaluationOptions | undefined {
7171
if (isObject(maybeOptions)) {
7272
const properties = validateEventProperties(log, maybeOptions.properties, method).properties;
73-
return properties ? { properties } : undefined;
73+
return properties && Object.keys(properties).length > 0 ? { properties } : undefined;
7474
} else if (maybeOptions) {
7575
log.error(ERROR_NOT_PLAIN_OBJECT, [method, 'evaluation options']);
7676
}

0 commit comments

Comments
 (0)