@@ -854,6 +854,47 @@ describe('SessionRecording', () => {
854
854
expect ( emitValues . filter ( ( v ) => v === 'sampled' ) . length ) . toBeGreaterThan ( 30 )
855
855
expect ( emitValues . filter ( ( v ) => v === 'disabled' ) . length ) . toBeGreaterThan ( 30 )
856
856
} )
857
+
858
+ it ( 'turning sample rate to null, means sessions are no longer sampled out' , ( ) => {
859
+ sessionRecording . startIfEnabledOrStop ( )
860
+ // set sample rate to 0, i.e. no sessions will run
861
+ sessionRecording . onRemoteConfig (
862
+ makeDecideResponse ( { sessionRecording : { endpoint : '/s/' , sampleRate : '0.00' } } )
863
+ )
864
+ // then check that a session is sampled (i.e. storage is false not true or null)
865
+ expect ( posthog . get_property ( SESSION_RECORDING_IS_SAMPLED ) ) . toBe ( false )
866
+ expect ( sessionRecording [ 'status' ] ) . toBe ( 'disabled' )
867
+
868
+ // then turn sample rate to null
869
+ sessionRecording . onRemoteConfig (
870
+ makeDecideResponse ( { sessionRecording : { endpoint : '/s/' , sampleRate : null } } )
871
+ )
872
+
873
+ // then check that a session is no longer sampled out (i.e. storage is cleared not false)
874
+ expect ( posthog . get_property ( SESSION_RECORDING_IS_SAMPLED ) ) . toBe ( undefined )
875
+ expect ( sessionRecording [ 'status' ] ) . toBe ( 'active' )
876
+ } )
877
+
878
+ it ( 'turning sample rate from null to 0, resets values as expected' , ( ) => {
879
+ sessionRecording . startIfEnabledOrStop ( )
880
+
881
+ // first turn sample rate to null
882
+ sessionRecording . onRemoteConfig (
883
+ makeDecideResponse ( { sessionRecording : { endpoint : '/s/' , sampleRate : null } } )
884
+ )
885
+
886
+ // then check that a session is no longer sampled out (i.e. storage is cleared not false)
887
+ expect ( posthog . get_property ( SESSION_RECORDING_IS_SAMPLED ) ) . toBe ( undefined )
888
+ expect ( sessionRecording [ 'status' ] ) . toBe ( 'active' )
889
+
890
+ // set sample rate to 0, i.e. no sessions will run
891
+ sessionRecording . onRemoteConfig (
892
+ makeDecideResponse ( { sessionRecording : { endpoint : '/s/' , sampleRate : '0.00' } } )
893
+ )
894
+ // then check that a session is sampled (i.e. storage is false not true or null)
895
+ expect ( posthog . get_property ( SESSION_RECORDING_IS_SAMPLED ) ) . toBe ( false )
896
+ expect ( sessionRecording [ 'status' ] ) . toBe ( 'disabled' )
897
+ } )
857
898
} )
858
899
859
900
describe ( 'canvas' , ( ) => {
0 commit comments