From a66f514ad0606a56bc6dd945425d836b45a66292 Mon Sep 17 00:00:00 2001 From: Michael Beemer Date: Tue, 14 Nov 2023 17:06:06 -0600 Subject: [PATCH] test: add target value casting test (#652) Signed-off-by: Michael Beemer --- .../flagd-core/src/lib/flagd-core.spec.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/libs/shared/flagd-core/src/lib/flagd-core.spec.ts b/libs/shared/flagd-core/src/lib/flagd-core.spec.ts index 3078b72a1..83e682dd9 100644 --- a/libs/shared/flagd-core/src/lib/flagd-core.spec.ts +++ b/libs/shared/flagd-core/src/lib/flagd-core.spec.ts @@ -109,6 +109,24 @@ describe('flagd-core targeting evaluations', () => { expect(resolved.reason).toBe(StandardResolutionReasons.TARGETING_MATCH); expect(resolved.variant).toBe('true'); }); + + it('should match the variant "true" by casting the boolean response from the targeting evaluation', () => { + const caseVariantValueFlag = + '{"flags":{"new-welcome-banner":{"state":"ENABLED","variants":{"true":true,"false":false},"defaultVariant":"false","targeting":{"in":["@example.com",{"var":"email"}]}}}}'; + + const core = new FlagdCore(); + core.setConfigurations(caseVariantValueFlag); + + const evaluation = core.resolveBooleanEvaluation( + 'new-welcome-banner', + false, + { email: 'test@example.com' }, + console, + ); + expect(evaluation.value).toBe(true); + expect(evaluation.variant).toBe('true'); + expect(evaluation.reason).toBe(StandardResolutionReasons.TARGETING_MATCH); + }); }); describe('flagd-core validations', () => {