diff --git a/android/native.gradle b/android/native.gradle index ce24c1c1e..2a88511d9 100644 --- a/android/native.gradle +++ b/android/native.gradle @@ -1,5 +1,5 @@ project.ext.instabug = [ - version: '14.0.0.6273368-SNAPSHOT' + version: '14.1.0.6273967-SNAPSHOT' ] dependencies { diff --git a/examples/default/android/build.gradle b/examples/default/android/build.gradle index a9222aeeb..5729e78c9 100644 --- a/examples/default/android/build.gradle +++ b/examples/default/android/build.gradle @@ -24,7 +24,7 @@ buildscript { classpath("com.android.tools.build:gradle:8.1.0") classpath("com.facebook.react:react-native-gradle-plugin") classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") - classpath("com.instabug.library:instabug-plugin:14.0.0.6273368-SNAPSHOT") + classpath("com.instabug.library:instabug-plugin:14.1.0.6273967-SNAPSHOT") } } diff --git a/examples/default/ios/Podfile b/examples/default/ios/Podfile index d9bb06968..2849b67b7 100644 --- a/examples/default/ios/Podfile +++ b/examples/default/ios/Podfile @@ -19,7 +19,7 @@ target 'InstabugExample' do rn_maps_path = '../node_modules/react-native-maps' pod 'react-native-google-maps', :path => rn_maps_path - pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec' + pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.1.0/Instabug.podspec' use_react_native!( :path => config[:reactNativePath], # An absolute path to your application root. diff --git a/examples/default/ios/Podfile.lock b/examples/default/ios/Podfile.lock index eaf6fc979..6f1c22dd5 100644 --- a/examples/default/ios/Podfile.lock +++ b/examples/default/ios/Podfile.lock @@ -31,7 +31,7 @@ PODS: - hermes-engine (0.75.4): - hermes-engine/Pre-built (= 0.75.4) - hermes-engine/Pre-built (0.75.4) - - Instabug (13.4.3) + - Instabug (14.1.0) - instabug-reactnative-ndk (0.1.0): - DoubleConversion - glog @@ -1603,7 +1603,7 @@ PODS: - ReactCommon/turbomodule/core - Yoga - RNInstabug (13.4.0): - - Instabug (= 13.4.3) + - Instabug (= 14.1.0) - React-Core - RNReanimated (3.16.1): - DoubleConversion @@ -1747,7 +1747,7 @@ DEPENDENCIES: - fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`) - glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`) - hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`) - - Instabug (from `https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec`) + - Instabug (from `https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.1.0/Instabug.podspec`) - instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`) - OCMock - RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`) @@ -1844,7 +1844,7 @@ EXTERNAL SOURCES: :podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec" :tag: hermes-2024-08-15-RNv0.75.1-4b3bf912cc0f705b51b71ce1a5b8bd79b93a451b Instabug: - :podspec: https://ios-releases.instabug.com/custom/release-support_cp_network_filtering_obfuscation-add_reset_network_state/13.4.3/Instabug.podspec + :podspec: https://ios-releases.instabug.com/custom/feature-support_cp_network_filtering_obfuscation-base/14.1.0/Instabug.podspec instabug-reactnative-ndk: :path: "../node_modules/instabug-reactnative-ndk" RCT-Folly: @@ -1995,7 +1995,7 @@ SPEC CHECKSUMS: Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0 - Instabug: 12ea6990039094c48a7c7e8103ba8679c0833f5e + Instabug: afe23192d5487aa2afd4f3baa76913cc2c421cda instabug-reactnative-ndk: d765ac289d56e8896398d02760d9abf2562fc641 OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74 RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740 @@ -2061,14 +2061,14 @@ SPEC CHECKSUMS: ReactCommon: 6a952e50c2a4b694731d7682aaa6c79bc156e4ad RNCClipboard: 2821ac938ef46f736a8de0c8814845dde2dcbdfb RNGestureHandler: 511250b190a284388f9dd0d2e56c1df76f14cfb8 - RNInstabug: 514b187e5b884939fd337eefb3244ea75e7e34f8 + RNInstabug: 6e109844b6a8cb6d905e3dacd644973839862715 RNReanimated: f42a5044d121d68e91680caacb0293f4274228eb RNScreens: c7ceced6a8384cb9be5e7a5e88e9e714401fd958 RNSVG: 8b1a777d54096b8c2a0fd38fc9d5a454332bbb4d RNVectorIcons: 6382277afab3c54658e9d555ee0faa7a37827136 SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d - Yoga: aa3df615739504eebb91925fc9c58b4922ea9a08 + Yoga: 055f92ad73f8c8600a93f0e25ac0b2344c3b07e6 -PODFILE CHECKSUM: 784fde5e5fa833eeefea8a5deaa699d18167d101 +PODFILE CHECKSUM: 48043b3d903923ac80ca4e335406e87f2daba40f -COCOAPODS: 1.15.2 +COCOAPODS: 1.14.0 diff --git a/examples/default/src/App.tsx b/examples/default/src/App.tsx index 2a7c572f6..0e3bca8c8 100644 --- a/examples/default/src/App.tsx +++ b/examples/default/src/App.tsx @@ -7,6 +7,7 @@ import Instabug, { CrashReporting, InvocationEvent, LogLevel, + NetworkInterceptionMode, NetworkLogger, ReproStepsMode, } from 'instabug-reactnative'; @@ -29,7 +30,7 @@ export const App: React.FC = () => { token: '0fcc87b8bf731164828cc411eccc802a', invocationEvents: [InvocationEvent.floatingButton], debugLogsLevel: LogLevel.verbose, - // networkInterceptionMode: NetworkInterceptionMode.native, + networkInterceptionMode: NetworkInterceptionMode.native, }); CrashReporting.setNDKCrashesEnabled(true); diff --git a/ios/native.rb b/ios/native.rb index 90bb0bf58..4fc710cbe 100644 --- a/ios/native.rb +++ b/ios/native.rb @@ -1,4 +1,4 @@ -$instabug = { :version => '13.4.3' } +$instabug = { :version => '14.1.0' } def use_instabug! (spec = nil) version = $instabug[:version] diff --git a/src/modules/Instabug.ts b/src/modules/Instabug.ts index d41462a01..344fe2e99 100644 --- a/src/modules/Instabug.ts +++ b/src/modules/Instabug.ts @@ -1,4 +1,3 @@ -//todo: remove all logs tagged with 'Andrew' in the file import { AppState, type AppStateStatus, @@ -74,25 +73,6 @@ function reportCurrentViewForAndroid(screenName: string | null) { } } -function _logFlags() { - if (Platform.OS === 'android') { - console.log( - `Andrew: APM Flags -> { - isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled}, - hasAPMNetworkPlugin: ${hasAPMNetworkPlugin}, - shouldEnableNativeInterception: ${shouldEnableNativeInterception} - }`, - ); - } else { - console.log( - `Andrew: APM Flags -> { - isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled}, - shouldEnableNativeInterception: ${shouldEnableNativeInterception} - }`, - ); - } -} - /** * Initializes the SDK. * This is the main SDK method that does all the magic. This is the only @@ -148,14 +128,11 @@ const handleAppStateChange = async (nextAppState: AppStateStatus, config: Instab const isUpdated = await fetchApmNetworkFlags(); if (isUpdated) { - console.log('Andrew: App has come to the foreground!'); - console.log('Andrew: APM network flags updated.'); refreshAPMNetworkConfigs(config); } } _currentAppState = nextAppState; - console.log(`Andrew: Current AppState: ${_currentAppState}`); }; /** @@ -176,10 +153,6 @@ const fetchApmNetworkFlags = async () => { isUpdated = true; } } - - console.log( - `Andrew: fetchApmNetworkFlags {isNativeInterceptionFeatureEnabled: ${isNativeInterceptionFeatureEnabled}, hasAPMNetworkPlugin: ${hasAPMNetworkPlugin}}`, - ); return isUpdated; }; @@ -241,13 +214,6 @@ function handleAndroidNativeInterception() { * Control either to enable or disable the native interception for iOS after the init method is called. */ function handleIOSNativeInterception(config: InstabugConfig) { - console.log( - `Andrew: handleIOSNativeInterception(${ - shouldEnableNativeInterception && - config.networkInterceptionMode === NetworkInterceptionMode.native - })`, - ); - if ( shouldEnableNativeInterception && config.networkInterceptionMode === NetworkInterceptionMode.native @@ -295,12 +261,6 @@ const handleInterceptionModeForIOS = (config: InstabugConfig) => { * Initializes Instabug with the given configuration. */ const initializeNativeInstabug = (config: InstabugConfig) => { - console.log( - `Andrew: initializeNativeInstabug -> NativeNetworkInterceptionMode ${ - shouldEnableNativeInterception && - config.networkInterceptionMode === NetworkInterceptionMode.native - }`, - ); NativeInstabug.init( config.token, config.invocationEvents, @@ -319,7 +279,6 @@ function refreshAPMNetworkConfigs(config: InstabugConfig, forceRefreshIOS: boole if (Platform.OS === 'ios' && forceRefreshIOS) { handleIOSNativeInterception(config); } - _logFlags(); setApmNetworkFlagsIfChanged({ isNativeInterceptionFeatureEnabled, hasAPMNetworkPlugin, @@ -339,10 +298,6 @@ function refreshAPMNetworkConfigs(config: InstabugConfig, forceRefreshIOS: boole function addOnFeatureUpdatedListener(config: InstabugConfig) { emitter.addListener(NativeEvents.IBG_ON_FEATURES_UPDATED_CALLBACK, (flags) => { const { cpNativeInterceptionEnabled, hasAPMPlugin } = flags; - console.log(`Andrew: addOnFeatureUpdatedListener -> - isNativeInterceptionFeatureEnabled: ${cpNativeInterceptionEnabled}, - hasAPMNetworkPlugin: ${hasAPMPlugin}. - `); isNativeInterceptionFeatureEnabled = cpNativeInterceptionEnabled; hasAPMNetworkPlugin = hasAPMPlugin; shouldEnableNativeInterception = diff --git a/src/modules/NetworkLogger.ts b/src/modules/NetworkLogger.ts index 25275fd2d..db5061da8 100644 --- a/src/modules/NetworkLogger.ts +++ b/src/modules/NetworkLogger.ts @@ -41,9 +41,6 @@ export const setEnabled = (isEnabled: boolean) => { try { if (_networkDataObfuscationHandler) { network = await _networkDataObfuscationHandler(network); - console.log( - `Andrew: xhr.setOnDoneCallback -> _networkDataObfuscationHandler ${network.url}`, - ); } if (network.requestBodySize > InstabugConstants.MAX_NETWORK_BODY_SIZE_IN_BYTES) { @@ -88,7 +85,6 @@ export const setEnabled = (isEnabled: boolean) => { * @param isEnabled */ export const setNativeInterceptionEnabled = (isEnabled: boolean) => { - console.log(`Andrew: NetworkLogger -> setNativeInterceptionEnabled ${isEnabled}`); _isNativeInterceptionEnabled = isEnabled; }; @@ -108,12 +104,8 @@ export const setNetworkDataObfuscationHandler = ( _networkDataObfuscationHandler = handler; if (_isNativeInterceptionEnabled && Platform.OS === 'ios') { if (hasFilterExpression) { - console.log( - 'Andrew: setNetworkDataObfuscationHandler -> registerFilteringAndObfuscationListenerV2', - ); registerFilteringAndObfuscationListener(_requestFilterExpression); } else { - console.log('Andrew: setNetworkDataObfuscationHandler -> registerObfuscationListener'); registerObfuscationListener(); } } @@ -129,12 +121,8 @@ export const setRequestFilterExpression = (expression: string) => { if (_isNativeInterceptionEnabled && Platform.OS === 'ios') { if (_networkDataObfuscationHandler) { - console.log( - 'Andrew: setRequestFilterExpression -> registerFilteringAndObfuscationListenerV2', - ); registerFilteringAndObfuscationListener(_requestFilterExpression); } else { - console.log('Andrew: setRequestFilterExpression -> registerFilteringListener'); registerFilteringListener(_requestFilterExpression); } } @@ -186,11 +174,8 @@ export const registerNetworkLogsListener = ( handler?: (networkSnapshot: NetworkData) => void, ) => { if (Platform.OS === 'ios') { - console.log('Andrew: registerNetworkLogsListener called'); - // remove old listeners if (NetworkLoggerEmitter.listenerCount(NativeNetworkLoggerEvent.NETWORK_LOGGER_HANDLER) > 0) { - console.log('Andrew: removeAllListeners called'); NetworkLoggerEmitter.removeAllListeners(NativeNetworkLoggerEvent.NETWORK_LOGGER_HANDLER); } @@ -201,7 +186,6 @@ export const registerNetworkLogsListener = ( // attach a new listener to the existing one. _networkListener = NetworkListenerType.both; } - console.log(`Andrew: new NetworkLogsListener (${_networkListener}) attached`); } NetworkLoggerEmitter.addListener( diff --git a/src/utils/AppStatesHandler.ts b/src/utils/AppStatesHandler.ts index ff458d417..ac71f50b9 100644 --- a/src/utils/AppStatesHandler.ts +++ b/src/utils/AppStatesHandler.ts @@ -6,7 +6,6 @@ let subscription: any = null; export const addAppStateListener = (handleAppStateChange: (state: AppStateStatus) => void) => { if (!subscription) { subscription = AppState.addEventListener('change', handleAppStateChange); - console.log('Andrew: AppState listener added'); } }; @@ -16,6 +15,5 @@ export const removeAppStateListener = () => { if (subscription) { subscription.remove(); subscription = null; - console.log('Andrew: AppState listener removed'); } }; diff --git a/src/utils/InstabugUtils.ts b/src/utils/InstabugUtils.ts index 2b8e5a7f5..6a70baf20 100644 --- a/src/utils/InstabugUtils.ts +++ b/src/utils/InstabugUtils.ts @@ -171,15 +171,11 @@ export function isContentTypeNotAllowed(contentType: string) { return allowed.every((type) => !contentType.includes(type)); } -//todo: remove all logs tagged with 'Andrew' in the file export const reportNetworkLog = (network: NetworkData) => { if (Platform.OS === 'android') { const requestHeaders = JSON.stringify(network.requestHeaders); const responseHeaders = JSON.stringify(network.responseHeaders); - console.log('Andrew: ' + `NetworkLogger -> ${JSON.stringify(apmFlags)}`); - console.log('Andrew: ' + 'NetworkLogger -> NativeInstabug.networkLogAndroid'); - NativeInstabug.networkLogAndroid( network.url, network.requestBody, @@ -196,8 +192,6 @@ export const reportNetworkLog = (network: NetworkData) => { !apmFlags.hasAPMNetworkPlugin || !apmFlags.shouldEnableNativeInterception ) { - console.log('Andrew: ' + 'NetworkLogger -> NativeAPM.networkLogAndroid'); - console.log('Andrew: ' + `NetworkLogger -> ${network.url}`); NativeAPM.networkLogAndroid( network.startTime, network.duration, @@ -218,12 +212,6 @@ export const reportNetworkLog = (network: NetworkData) => { ); } } else { - console.log( - 'Andrew: ' + - `NetworkLogger -> {isNativeInterceptionEnabled: ${apmFlags.isNativeInterceptionFeatureEnabled}}`, - ); - console.log('Andrew: ' + 'NetworkLogger -> NativeInstabug.networkLogIOS'); - NativeInstabug.networkLogIOS( network.url, network.method, @@ -245,6 +233,10 @@ export const reportNetworkLog = (network: NetworkData) => { } }; +/** + * @internal + * This method is for internal use only. + */ export function registerObfuscationListener() { NetworkLogger.registerNetworkLogsListener( NetworkListenerType.obfuscation, @@ -258,6 +250,10 @@ export function registerObfuscationListener() { ); } +/** + * @internal + * This method is for internal use only. + */ export function registerFilteringListener(filterExpression: string) { NetworkLogger.registerNetworkLogsListener( NetworkListenerType.filtering, @@ -279,6 +275,10 @@ export function registerFilteringListener(filterExpression: string) { ); } +/** + * @internal + * This method is for internal use only. + */ export function registerFilteringAndObfuscationListener(filterExpression: string) { NetworkLogger.registerNetworkLogsListener(NetworkListenerType.both, async (networkSnapshot) => { // eslint-disable-next-line no-new-func @@ -304,14 +304,14 @@ export function registerFilteringAndObfuscationListener(filterExpression: string }); } +/** + * @internal + * This method is for internal use only. + */ export function checkNetworkRequestHandlers() { const obfuscationHandler = NetworkLogger.getNetworkDataObfuscationHandler(); const hasFilterExpression = NetworkLogger.hasRequestFilterExpression(); - console.log( - `Andrew: handlers - {filtering = ${hasFilterExpression}, obfuscation = ${obfuscationHandler != null}}`, - ); if (hasFilterExpression && obfuscationHandler) { // Register listener that handles both (Filtering & Obfuscation) registerFilteringAndObfuscationListener(NetworkLogger.getRequestFilterExpression()); @@ -336,7 +336,11 @@ export function resetNativeObfuscationListener() { NetworkLoggerEmitter.removeAllListeners(NativeNetworkLoggerEvent.NETWORK_LOGGER_HANDLER); } -function updateNetworkLogSnapshot(networkSnapshot: NetworkData) { +/** + * @internal + * This method is for internal use only. + */ +export function updateNetworkLogSnapshot(networkSnapshot: NetworkData) { NativeNetworkLogger.updateNetworkLogSnapshot( networkSnapshot.url, networkSnapshot.id, diff --git a/test/utils/AppStatesHandler.spec.ts b/test/utils/AppStatesHandler.spec.ts new file mode 100644 index 000000000..c784da86a --- /dev/null +++ b/test/utils/AppStatesHandler.spec.ts @@ -0,0 +1,60 @@ +import { AppState } from 'react-native'; +import { addAppStateListener, removeAppStateListener } from '../../src/utils/AppStatesHandler'; + +jest.mock('react-native', () => ({ + AppState: { + addEventListener: jest.fn(), + }, +})); + +describe('AppState Listener', () => { + const mockHandleAppStateChange = jest.fn(); + const mockRemove = jest.fn(); + + beforeEach(() => { + jest.clearAllMocks(); + (AppState.addEventListener as jest.Mock).mockReturnValue({ remove: mockRemove }); + }); + + afterEach(() => { + removeAppStateListener(); // Ensure no leftover subscriptions between tests + }); + + it('should add an AppState listener if none exists', () => { + addAppStateListener(mockHandleAppStateChange); + + expect(AppState.addEventListener).toHaveBeenCalledTimes(1); + expect(AppState.addEventListener).toHaveBeenCalledWith('change', mockHandleAppStateChange); + }); + + it('should not add another listener if one already exists', () => { + addAppStateListener(mockHandleAppStateChange); + addAppStateListener(mockHandleAppStateChange); + + expect(AppState.addEventListener).toHaveBeenCalledTimes(1); // Only called once + }); + + it('should remove the AppState listener if one exists', () => { + addAppStateListener(mockHandleAppStateChange); + removeAppStateListener(); + + expect(mockRemove).toHaveBeenCalledTimes(1); // The remove function is called + }); + + it('should do nothing if removeAppStateListener is called without an existing subscription', () => { + removeAppStateListener(); + + expect(mockRemove).not.toHaveBeenCalled(); // No remove is called + }); + + it('should handle multiple add/remove calls properly', () => { + addAppStateListener(mockHandleAppStateChange); + removeAppStateListener(); + + addAppStateListener(mockHandleAppStateChange); + removeAppStateListener(); + + expect(AppState.addEventListener).toHaveBeenCalledTimes(2); // Listener is added twice + expect(mockRemove).toHaveBeenCalledTimes(2); // Listener is removed twice + }); +}); diff --git a/test/utils/InstabugUtils.spec.ts b/test/utils/InstabugUtils.spec.ts index 8a0d26f78..859eac0e3 100644 --- a/test/utils/InstabugUtils.spec.ts +++ b/test/utils/InstabugUtils.spec.ts @@ -4,17 +4,30 @@ import { Platform } from 'react-native'; import parseErrorStackLib from 'react-native/Libraries/Core/Devtools/parseErrorStack'; import * as Instabug from '../../src/modules/Instabug'; +import * as NetworkLogger from '../../src/modules/NetworkLogger'; import { NativeCrashReporting } from '../../src/native/NativeCrashReporting'; import { InvocationEvent, NetworkData, NonFatalErrorLevel } from '../../src'; import InstabugUtils, { getStackTrace, + registerFilteringAndObfuscationListener, + registerFilteringListener, + registerObfuscationListener, reportNetworkLog, + resetNativeObfuscationListener, sendCrashReport, + updateNetworkLogSnapshot, } from '../../src/utils/InstabugUtils'; -import { NativeNetworkLogger } from '../../src/native/NativeNetworkLogger'; + +import { + NativeNetworkLogger, + NetworkListenerType, + NetworkLoggerEmitter, +} from '../../src/native/NativeNetworkLogger'; import { NativeInstabug } from '../../src/native/NativeInstabug'; import { NativeAPM } from '../../src/native/NativeAPM'; +jest.mock('../../src/modules/NetworkLogger'); + describe('Test global error handler', () => { beforeEach(() => { Instabug.init({ token: '', invocationEvents: [InvocationEvent.none] }); @@ -333,3 +346,91 @@ describe('reportNetworkLog', () => { ); }); }); + +describe('test registerNetworkLogsListener usage', () => { + beforeEach(() => { + jest.clearAllMocks(); // Clear all mocks before each test + }); + + const network: NetworkLogger.NetworkData = { + id: '', + url: 'https://api.instabug.com', + requestBody: '', + requestHeaders: { 'content-type': 'application/json' }, + method: 'GET', + responseBody: '', + responseCode: 200, + responseHeaders: { 'content-type': 'application/json' }, + contentType: 'application/json', + duration: 0, + requestBodySize: 0, + responseBodySize: 0, + errorDomain: '', + errorCode: 0, + startTime: 0, + serverErrorMessage: '', + requestContentType: 'application/json', + }; + + it('registerObfuscationListener should call NetworkLogger.registerNetworkLogsListener() with NetworkListenerType = NetworkListenerType.obfuscation', () => { + registerObfuscationListener(); + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledTimes(1); + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledWith( + NetworkListenerType.obfuscation, + expect.any(Function), + ); + }); + + it('registerFilteringListener should call NetworkLogger.registerNetworkLogsListener() with NetworkListenerType = NetworkListenerType.filtering', () => { + const testText = 'true'; + registerFilteringListener(testText); + + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledTimes(1); + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledWith( + NetworkListenerType.filtering, + expect.any(Function), + ); + }); + + it('registerFilteringAndObfuscationListener should call NetworkLogger.registerNetworkLogsListener() with NetworkListenerType = NetworkListenerType.both', () => { + const testText = 'true'; + registerFilteringAndObfuscationListener(testText); + + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledTimes(1); + expect(NetworkLogger.registerNetworkLogsListener).toBeCalledWith( + NetworkListenerType.both, + expect.any(Function), + ); + }); + + it('should call NetworkLoggerEmitter.removeAllListeners when call resetNativeObfuscationListener', () => { + jest.spyOn(NetworkLoggerEmitter, 'removeAllListeners').mockImplementation(); + resetNativeObfuscationListener(); + expect(NetworkLoggerEmitter.removeAllListeners).toBeCalledTimes(1); + }); + + it('should call NativeNetworkLogger.resetNetworkLogsListener when call resetNativeObfuscationListener on android platform', () => { + Platform.OS = 'android'; + jest.spyOn(NativeNetworkLogger, 'resetNetworkLogsListener').mockImplementation(); + jest.spyOn(NetworkLoggerEmitter, 'removeAllListeners').mockImplementation(); + resetNativeObfuscationListener(); + expect(NativeNetworkLogger.resetNetworkLogsListener).toBeCalledTimes(1); + expect(NetworkLoggerEmitter.removeAllListeners).toBeCalledTimes(1); + }); + + it('should call NativeNetworkLogger.updateNetworkLogSnapshot when call updateNetworkLogSnapshot with correct parameters', () => { + jest.spyOn(NativeNetworkLogger, 'updateNetworkLogSnapshot').mockImplementation(); + + updateNetworkLogSnapshot(network); + expect(NativeNetworkLogger.updateNetworkLogSnapshot).toBeCalledTimes(1); + expect(NativeNetworkLogger.updateNetworkLogSnapshot).toHaveBeenCalledWith( + network.url, + network.id, + network.requestBody, + network.responseBody, + network.responseCode ?? 200, + network.requestHeaders, + network.responseHeaders, + ); + }); +});