-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed issue with nested fractional evaluations (#686)
Signed-off-by: Michael Beemer <[email protected]>
- Loading branch information
Showing
7 changed files
with
150 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,3 +160,38 @@ describe('flagd-core validations', () => { | |
expect(() => core.resolveNumberEvaluation('myIntFlag', 100, {}, console)).toThrow(GeneralError); | ||
}); | ||
}); | ||
|
||
describe('flagd-core common flag definitions', () => { | ||
it('should support boolean variant shorthand', () => { | ||
const core = new FlagdCore(); | ||
const flagCfg = `{"flags":{"myBoolFlag":{"state":"ENABLED","variants":{"true":true,"false":false},"defaultVariant":"false", "targeting":{"in":["@openfeature.dev",{"var":"email"}]}}}}`; | ||
core.setConfigurations(flagCfg); | ||
|
||
const resolved = core.resolveBooleanEvaluation('myBoolFlag', false, { email: '[email protected]' }, console); | ||
expect(resolved.value).toBe(true); | ||
expect(resolved.reason).toBe(StandardResolutionReasons.TARGETING_MATCH); | ||
expect(resolved.variant).toBe('true'); | ||
}); | ||
|
||
it('should support fractional logic', () => { | ||
const core = new FlagdCore(); | ||
const flagCfg = `{"flags":{"headerColor":{"state":"ENABLED","variants":{"red":"red","blue":"blue","grey":"grey"},"defaultVariant":"grey", "targeting":{"fractional":[{"var":"email"},["red",50],["blue",50]]}}}}`; | ||
core.setConfigurations(flagCfg); | ||
|
||
const resolved = core.resolveStringEvaluation('headerColor', 'grey', { email: '[email protected]' }, console); | ||
expect(resolved.value).toBe('red'); | ||
expect(resolved.reason).toBe(StandardResolutionReasons.TARGETING_MATCH); | ||
expect(resolved.variant).toBe('red'); | ||
}); | ||
|
||
it('should support nested fractional logic', () => { | ||
const core = new FlagdCore(); | ||
const flagCfg = `{"flags":{"headerColor":{"state":"ENABLED","variants":{"red":"red","blue":"blue","grey":"grey"},"defaultVariant":"grey", "targeting":{"if":[true,{"fractional":[{"var":"email"},["red",50],["blue",50]]}]}}}}`; | ||
core.setConfigurations(flagCfg); | ||
|
||
const resolved = core.resolveStringEvaluation('headerColor', 'grey', { email: '[email protected]' }, console); | ||
expect(resolved.value).toBe('red'); | ||
expect(resolved.reason).toBe(StandardResolutionReasons.TARGETING_MATCH); | ||
expect(resolved.variant).toBe('red'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.