Skip to content

Commit 26c468b

Browse files
authored
[UFC] add missing not_matches operator (#66)
* add missing not_matches operator * bump version
1 parent c8af797 commit 26c468b

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk-common",
3-
"version": "3.0.6",
3+
"version": "3.0.7",
44
"description": "Eppo SDK for client-side JavaScript applications (base for both web and react native)",
55
"main": "dist/index.js",
66
"files": [

src/rules.spec.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,16 @@ describe('rules', () => {
203203
expect(matchesRule(ruleWithMatchesCondition, failingAttributes, false)).toBe(false);
204204
});
205205

206-
it('should return true for a rule with not_matches condition that matches the subject attributes', () => {
207-
expect(matchesRule(ruleWithNotMatchesCondition, subjectAttributes, false)).toBe(false);
206+
it('should return false for a rule with NOT_MATCHES condition when the subject attribute matches the condition value', () => {
207+
expect(matchesRule(ruleWithNotMatchesCondition, { user_id: 'user123' }, false)).toBe(false);
208+
});
209+
210+
it('should return true for a rule with NOT_MATCHES condition when the subject attribute does not match the condition value', () => {
211+
expect(matchesRule(ruleWithNotMatchesCondition, { user_id: 'admin' }, false)).toBe(true);
212+
});
213+
214+
it('should return true for a rule with NOT_MATCHES condition when the subject attribute does not match the condition value', () => {
215+
expect(matchesRule(ruleWithNotMatchesCondition, { country: 'uk' }, false)).toBe(false);
208216
});
209217
});
210218

src/rules.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ function evaluateCondition(subjectAttributes: Record<string, any>, condition: Co
187187
return compareNumber(value, condition.value, (a, b) => a < b);
188188
case OperatorType.MATCHES:
189189
return new RegExp(condition.value as string).test(value as string);
190+
case OperatorType.NOT_MATCHES:
191+
return !new RegExp(condition.value as string).test(value as string);
190192
case OperatorType.ONE_OF:
191193
return isOneOf(value.toString(), condition.value);
192194
case OperatorType.NOT_ONE_OF:

0 commit comments

Comments
 (0)