import { RolloutTracker } from './rollout' ; describe ( 'RolloutTracker' , ( ) => { describe ( 'isRolloutEnabled' , ( ) => { it ( 'throws on out of range percentages' , ( ) => { const tracker = new RolloutTracker ( 'instance-id' ) ; expect ( ( ) => tracker . isRolloutEnabled ( 'rollout-id' , - 1 ) ) . toThrowError ( ) ; expect ( ( ) => tracker . isRolloutEnabled ( 'rollout-id' , 101 ) ) . toThrowError ( ) ; } ) ; it ( 'throws on fractional percentage' , ( ) => { const tracker = new RolloutTracker ( 'instance-id' ) ; expect ( ( ) => tracker . isRolloutEnabled ( 'rollout-id' , 0.1 ) ) . toThrowError ( ) ; expect ( ( ) => tracker . isRolloutEnabled ( 'rollout-id' , 50.1 ) ) . toThrowError ( ) ; } ) ; it ( 'returns false on 0%' , ( ) => { const tracker = new RolloutTracker ( 'instance-id' ) ; expect ( tracker . isRolloutEnabled ( 'rollout-id' , 0 ) ) . toBeFalsy ( ) ; } ) ; it ( 'returns true on 100%' , ( ) => { const tracker = new RolloutTracker ( 'instance-id' ) ; expect ( tracker . isRolloutEnabled ( 'rollout-id' , 100 ) ) . toBeTruthy ( ) ; } ) ; it ( 'returns true depending on percentage' , ( ) => { const tracker = new RolloutTracker ( 'instance-id' ) ; expect ( tracker . isRolloutEnabled ( 'rollout-id' , 9 ) ) . toBeFalsy ( ) ; expect ( tracker . isRolloutEnabled ( 'rollout-id' , 10 ) ) . toBeTruthy ( ) ; } ) ; } ) ; describe ( 'forceRollout' , ( ) => { it ( 'forces rollout' , ( ) => { const tracker = new RolloutTracker ( 'instance-id' ) ; tracker . forceRollout ( 'rollout-id' , true ) ; expect ( tracker . isRolloutEnabled ( 'rollout-id' , 0 ) ) . toBeTruthy ( ) ; tracker . forceRollout ( 'rollout-id' , false ) ; expect ( tracker . isRolloutEnabled ( 'rollout-id' , 100 ) ) . toBeFalsy ( ) ; } ) ; } ) ; } ) ;