@@ -16,6 +16,10 @@ import InstabugUtils, {
1616 resetNativeObfuscationListener ,
1717 sendCrashReport ,
1818 updateNetworkLogSnapshot ,
19+ setApmNetworkFlagsIfChanged ,
20+ generateTracePartialId ,
21+ generateW3CHeader ,
22+ isContentTypeNotAllowed ,
1923} from '../../src/utils/InstabugUtils' ;
2024
2125import {
@@ -458,3 +462,40 @@ describe('test registerNetworkLogsListener usage', () => {
458462 ) ;
459463 } ) ;
460464} ) ;
465+
466+ describe ( 'InstabugUtils - Additional Coverage' , ( ) => {
467+ it ( 'setApmNetworkFlagsIfChanged should return true if flags change' , ( ) => {
468+ const flags = {
469+ isNativeInterceptionFeatureEnabled : true ,
470+ hasAPMNetworkPlugin : true ,
471+ shouldEnableNativeInterception : true ,
472+ } ;
473+ expect ( setApmNetworkFlagsIfChanged ( flags ) ) . toBe ( true ) ;
474+ expect ( setApmNetworkFlagsIfChanged ( flags ) ) . toBe ( false ) ;
475+ } ) ;
476+
477+ it ( 'generateTracePartialId should return a non-zero hex string and number' , ( ) => {
478+ const { numberPartilId, hexStringPartialId } = generateTracePartialId ( ) ;
479+ expect ( hexStringPartialId ) . toMatch ( / ^ [ 0 - 9 a - f ] { 8 } $ / ) ;
480+ expect ( hexStringPartialId ) . not . toBe ( '00000000' ) ;
481+ expect ( typeof numberPartilId ) . toBe ( 'number' ) ;
482+ expect ( numberPartilId ) . not . toBe ( 0 ) ;
483+ } ) ;
484+
485+ it ( 'generateW3CHeader should return a valid w3c header object' , ( ) => {
486+ const now = Date . now ( ) ;
487+ const result = generateW3CHeader ( now ) ;
488+ expect ( result ) . toHaveProperty ( 'timestampInSeconds' ) ;
489+ expect ( result ) . toHaveProperty ( 'partialId' ) ;
490+ expect ( result ) . toHaveProperty ( 'w3cHeader' ) ;
491+ expect ( typeof result . w3cHeader ) . toBe ( 'string' ) ;
492+ expect ( result . w3cHeader . split ( '-' ) . length ) . toBe ( 4 ) ;
493+ } ) ;
494+
495+ it ( 'isContentTypeNotAllowed should return false for allowed types and true for not allowed' , ( ) => {
496+ expect ( isContentTypeNotAllowed ( 'application/json' ) ) . toBe ( false ) ;
497+ expect ( isContentTypeNotAllowed ( 'text/plain' ) ) . toBe ( false ) ;
498+ expect ( isContentTypeNotAllowed ( 'image/png' ) ) . toBe ( true ) ;
499+ expect ( isContentTypeNotAllowed ( 'application/pdf' ) ) . toBe ( true ) ;
500+ } ) ;
501+ } ) ;
0 commit comments