diff --git a/package.json b/package.json index 08e99ef..27c5a62 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@eppo/js-client-sdk", - "version": "0.0.5", + "version": "0.0.6", "description": "Eppo SDK for client-side JavaScript applications", "main": "dist/index.js", "files": [ diff --git a/src/rule_evaluator.spec.ts b/src/rule_evaluator.spec.ts index 5618d54..8323553 100644 --- a/src/rule_evaluator.spec.ts +++ b/src/rule_evaluator.spec.ts @@ -117,6 +117,33 @@ describe('matchesAnyRule', () => { expect(matchesAnyRule({ userId: 'user15' }, [notOneOfRule])).toEqual(true); }); + it('does case insensitive matching with oneOf operator', () => { + const oneOfRule: Rule = { + conditions: [ + { + operator: OperatorType.ONE_OF, + value: ['CA', 'US'], + attribute: 'country', + }, + ], + }; + expect(matchesAnyRule({ country: 'us' }, [oneOfRule])).toEqual(true); + expect(matchesAnyRule({ country: 'cA' }, [oneOfRule])).toEqual(true); + }); + + it('does case insensitive matching with notOneOf operator', () => { + const notOneOf: Rule = { + conditions: [ + { + operator: OperatorType.NOT_ONE_OF, + value: ['1.0.BB', '1Ab'], + attribute: 'deviceType', + }, + ], + }; + expect(matchesAnyRule({ deviceType: '1ab' }, [notOneOf])).toEqual(false); + }); + it('handles oneOf rule with number', () => { const oneOfRule: Rule = { conditions: [ diff --git a/src/rule_evaluator.ts b/src/rule_evaluator.ts index 08bc604..09fb7b5 100644 --- a/src/rule_evaluator.ts +++ b/src/rule_evaluator.ts @@ -46,11 +46,15 @@ function evaluateCondition(subjectAttributes: Record, condition: Co } function isOneOf(attributeValue: any, conditionValue: string[]) { - return conditionValue.includes(attributeValue.toString()); + return getMatchingStringValues(attributeValue.toString(), conditionValue).length > 0; } function isNotOneOf(attributeValue: any, conditionValue: string[]) { - return !conditionValue.includes(attributeValue.toString()); + return getMatchingStringValues(attributeValue.toString(), conditionValue).length === 0; +} + +function getMatchingStringValues(attributeValue: string, conditionValues: string[]): string[] { + return conditionValues.filter((value) => value.toLowerCase() === attributeValue.toLowerCase()); } function compareNumber(