@@ -429,6 +429,80 @@ describe('ReplayManager', function () {
429429 } ) ;
430430 } ) ;
431431
432+ describe ( '_canSendReplay' , function ( ) {
433+ it ( 'returns true when all conditions are met' , function ( ) {
434+ const result = ReplayManager . _canSendReplay (
435+ null ,
436+ { err : 0 } ,
437+ {
438+ 'Rollbar-Replay-Enabled' : 'true' ,
439+ 'Rollbar-Replay-RateLimit-Remaining' : '10' ,
440+ } ,
441+ ) ;
442+ expect ( result ) . to . be . true ;
443+ } ) ;
444+
445+ it ( 'returns false when err is truthy' , function ( ) {
446+ const result = ReplayManager . _canSendReplay (
447+ new Error ( 'API error' ) ,
448+ { err : 0 } ,
449+ { 'Rollbar-Replay-Enabled' : 'true' } ,
450+ ) ;
451+ expect ( result ) . to . be . false ;
452+ } ) ;
453+
454+ it ( 'returns false when resp.err is non-zero' , function ( ) {
455+ const result = ReplayManager . _canSendReplay ( null , { err : 1 } , {
456+ 'Rollbar-Replay-Enabled' : 'true' ,
457+ } ) ;
458+ expect ( result ) . to . be . false ;
459+ } ) ;
460+
461+ it ( 'returns false when resp is null' , function ( ) {
462+ const result = ReplayManager . _canSendReplay ( null , null , {
463+ 'Rollbar-Replay-Enabled' : 'true' ,
464+ } ) ;
465+ expect ( result ) . to . be . false ;
466+ } ) ;
467+
468+ it ( 'returns false when Rollbar-Replay-Enabled is not "true"' , function ( ) {
469+ const result = ReplayManager . _canSendReplay ( null , { err : 0 } , {
470+ 'Rollbar-Replay-Enabled' : 'false' ,
471+ 'Rollbar-Replay-RateLimit-Remaining' : '10' ,
472+ } ) ;
473+ expect ( result ) . to . be . false ;
474+ } ) ;
475+
476+ it ( 'returns false when Rollbar-Replay-RateLimit-Remaining is "0"' , function ( ) {
477+ const result = ReplayManager . _canSendReplay ( null , { err : 0 } , {
478+ 'Rollbar-Replay-Enabled' : 'true' ,
479+ 'Rollbar-Replay-RateLimit-Remaining' : '0' ,
480+ } ) ;
481+ expect ( result ) . to . be . false ;
482+ } ) ;
483+
484+ it ( 'returns false when headers are null' , function ( ) {
485+ const result = ReplayManager . _canSendReplay ( null , { err : 0 } , null ) ;
486+ expect ( result ) . to . be . false ;
487+ } ) ;
488+
489+ it ( 'handles case-insensitive headers' , function ( ) {
490+ const result = ReplayManager . _canSendReplay ( null , { err : 0 } , {
491+ 'rollbar-replay-enabled' : 'true' ,
492+ 'ROLLBAR-REPLAY-RATELIMIT-REMAINING' : '10' ,
493+ } ) ;
494+ expect ( result ) . to . be . true ;
495+ } ) ;
496+
497+ it ( 'handles whitespace in header values' , function ( ) {
498+ const result = ReplayManager . _canSendReplay ( null , { err : 0 } , {
499+ 'Rollbar-Replay-Enabled' : ' true ' ,
500+ 'Rollbar-Replay-RateLimit-Remaining' : ' 10 ' ,
501+ } ) ;
502+ expect ( result ) . to . be . true ;
503+ } ) ;
504+ } ) ;
505+
432506 describe ( 'sendOrDiscardReplay' , function ( ) {
433507 beforeEach ( function ( ) {
434508 replayManager . setSpans ( 'test-replay' , [ { id : 'span1' } ] ) ;
0 commit comments