import LaunchDarkly , { LDClient } from "launchdarkly-node-server-sdk" ; import { mocked } from "ts-jest" ; jest . mock ( "launchdarkly-node-server-sdk" ) ; describe ( "Feature Flag" , ( ) => { let featureFlags ; const mockFeatureFlagValue = async ( flagValue ) => { mocked ( LaunchDarkly . init ) . mockReturnValue ( ( { variation : jest . fn ( ) . mockResolvedValue ( flagValue ) , waitForInitialization : jest . fn ( ) . mockResolvedValue ( { } ) } as unknown ) as LDClient ) ; featureFlags = await import ( "../../../src/config/feature-flags" ) ; } ; it ( "returns true when LaunchDarkly returns true" , async ( ) => { await mockFeatureFlagValue ( true ) ; expect ( await featureFlags . booleanFlag ( featureFlags . BooleanFlags . MAINTENANCE_MODE , true , "https://myjira.atlassian.net" ) ) . toBeTruthy ( ) ; } ) ; it ( "returns false when LaunchDarkly returns false" , async ( ) => { await mockFeatureFlagValue ( false ) ; expect ( await featureFlags . booleanFlag ( featureFlags . BooleanFlags . MAINTENANCE_MODE , true , "https://myjira.atlassian.net" ) ) . toBeFalsy ( ) ; } ) ; } ) ;