Skip to content

Commit a271220

Browse files
committed
test(flag-evaluation): enhance tests for SET and NOT_SET operators
- Added tests to verify behavior of `SET` and `NOT_SET` operators when field values are missing or empty strings. - Improved clarity and organization of test cases for better readability and maintainability.
1 parent 9250d13 commit a271220

File tree

1 file changed

+106
-104
lines changed

1 file changed

+106
-104
lines changed

packages/flag-evaluation/test/index.test.ts

Lines changed: 106 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -311,123 +311,125 @@ describe("evaluate feature targeting integration ", () => {
311311
});
312312
});
313313

314-
it("should not report missing context fields for `SET` operator when field doesn't exist", () => {
315-
const res = evaluateFeatureRules({
316-
featureKey: "test_feature",
317-
rules: [
318-
{
319-
value: true,
320-
filter: {
321-
type: "context",
322-
field: "user.name",
323-
operator: "SET",
324-
values: [],
314+
describe("SET and NOT_SET operators", () => {
315+
it("should handle `SET` operator with missing field value", () => {
316+
const res = evaluateFeatureRules({
317+
featureKey: "test_feature",
318+
rules: [
319+
{
320+
value: true,
321+
filter: {
322+
type: "context",
323+
field: "user.name",
324+
operator: "SET",
325+
values: [],
326+
},
325327
},
326-
},
327-
],
328-
context: {},
329-
});
330-
331-
expect(res).toEqual({
332-
featureKey: "test_feature",
333-
value: undefined,
334-
context: {},
335-
ruleEvaluationResults: [false],
336-
reason: "no matched rules",
337-
missingContextFields: [],
338-
});
339-
});
340-
341-
it("should not report missing context fields for `NOT_SET` operator when field doesn't exist", () => {
342-
const res = evaluateFeatureRules({
343-
featureKey: "test_feature",
344-
rules: [
345-
{
346-
value: true,
347-
filter: {
348-
type: "context",
349-
field: "user.name",
350-
operator: "NOT_SET",
351-
values: [],
328+
],
329+
context: {},
330+
});
331+
332+
expect(res).toEqual({
333+
featureKey: "test_feature",
334+
value: undefined,
335+
context: {},
336+
ruleEvaluationResults: [false],
337+
reason: "no matched rules",
338+
missingContextFields: [],
339+
});
340+
});
341+
342+
it("should handle `NOT_SET` operator with missing field value", () => {
343+
const res = evaluateFeatureRules({
344+
featureKey: "test_feature",
345+
rules: [
346+
{
347+
value: true,
348+
filter: {
349+
type: "context",
350+
field: "user.name",
351+
operator: "NOT_SET",
352+
values: [],
353+
},
352354
},
353-
},
354-
],
355-
context: {},
356-
});
355+
],
356+
context: {},
357+
});
357358

358-
expect(res).toEqual({
359-
featureKey: "test_feature",
360-
value: true,
361-
context: {},
362-
ruleEvaluationResults: [true],
363-
reason: "rule #0 matched",
364-
missingContextFields: [],
359+
expect(res).toEqual({
360+
featureKey: "test_feature",
361+
value: true,
362+
context: {},
363+
ruleEvaluationResults: [true],
364+
reason: "rule #0 matched",
365+
missingContextFields: [],
366+
});
365367
});
366-
});
367368

368-
it("should handle `SET` operator with empty string field value", () => {
369-
const res = evaluateFeatureRules({
370-
featureKey: "test_feature",
371-
rules: [
372-
{
373-
value: true,
374-
filter: {
375-
type: "context",
376-
field: "user.name",
377-
operator: "SET",
378-
values: [],
369+
it("should handle `SET` operator with empty string field value", () => {
370+
const res = evaluateFeatureRules({
371+
featureKey: "test_feature",
372+
rules: [
373+
{
374+
value: true,
375+
filter: {
376+
type: "context",
377+
field: "user.name",
378+
operator: "SET",
379+
values: [],
380+
},
381+
},
382+
],
383+
context: {
384+
user: {
385+
name: "",
379386
},
380387
},
381-
],
382-
context: {
383-
user: {
384-
name: "",
385-
},
386-
},
387-
});
388+
});
388389

389-
expect(res).toEqual({
390-
featureKey: "test_feature",
391-
value: undefined,
392-
context: {
393-
"user.name": "",
394-
},
395-
ruleEvaluationResults: [false],
396-
reason: "no matched rules",
397-
missingContextFields: [],
390+
expect(res).toEqual({
391+
featureKey: "test_feature",
392+
value: undefined,
393+
context: {
394+
"user.name": "",
395+
},
396+
ruleEvaluationResults: [false],
397+
reason: "no matched rules",
398+
missingContextFields: [],
399+
});
398400
});
399-
});
400401

401-
it("should handle `NOT_SET` operator with empty string field value", () => {
402-
const res = evaluateFeatureRules({
403-
featureKey: "test_feature",
404-
rules: [
405-
{
406-
value: true,
407-
filter: {
408-
type: "context",
409-
field: "user.name",
410-
operator: "NOT_SET",
411-
values: [],
402+
it("should handle `NOT_SET` operator with empty string field value", () => {
403+
const res = evaluateFeatureRules({
404+
featureKey: "test_feature",
405+
rules: [
406+
{
407+
value: true,
408+
filter: {
409+
type: "context",
410+
field: "user.name",
411+
operator: "NOT_SET",
412+
values: [],
413+
},
414+
},
415+
],
416+
context: {
417+
user: {
418+
name: "",
412419
},
413420
},
414-
],
415-
context: {
416-
user: {
417-
name: "",
418-
},
419-
},
420-
});
421+
});
421422

422-
expect(res).toEqual({
423-
featureKey: "test_feature",
424-
value: true,
425-
context: {
426-
"user.name": "",
427-
},
428-
ruleEvaluationResults: [true],
429-
reason: "rule #0 matched",
430-
missingContextFields: [],
423+
expect(res).toEqual({
424+
featureKey: "test_feature",
425+
value: true,
426+
context: {
427+
"user.name": "",
428+
},
429+
ruleEvaluationResults: [true],
430+
reason: "rule #0 matched",
431+
missingContextFields: [],
432+
});
431433
});
432434
});
433435

0 commit comments

Comments
 (0)