From 9c060fbe9702bb3ae38adbdba9719b5c7a15119d Mon Sep 17 00:00:00 2001 From: tienifr Date: Tue, 18 Jun 2024 15:12:53 +0700 Subject: [PATCH] Revert: Backend unreachability message --- .storybook/preview.tsx | 2 +- src/CONST.ts | 6 +- src/Expensify.tsx | 6 +- src/components/OfflineIndicator.tsx | 23 +--- src/hooks/useNetwork.ts | 9 +- src/languages/en.ts | 1 - src/languages/es.ts | 1 - src/libs/NetworkConnection.ts | 112 +++++++----------- src/libs/actions/Network.ts | 11 +- .../index.android.ts | 15 --- src/libs/checkInternetReachability/index.ts | 5 - src/libs/checkInternetReachability/types.ts | 3 - src/types/onyx/Network.ts | 3 - tests/unit/APITest.ts | 38 +++--- tests/unit/NetworkTest.ts | 10 +- 15 files changed, 80 insertions(+), 165 deletions(-) delete mode 100644 src/libs/checkInternetReachability/index.android.ts delete mode 100644 src/libs/checkInternetReachability/index.ts delete mode 100644 src/libs/checkInternetReachability/types.ts diff --git a/.storybook/preview.tsx b/.storybook/preview.tsx index 7527857eeda7..ec8e17dda4cf 100644 --- a/.storybook/preview.tsx +++ b/.storybook/preview.tsx @@ -16,7 +16,7 @@ import './fonts.css'; Onyx.init({ keys: ONYXKEYS, initialKeyStates: { - [ONYXKEYS.NETWORK]: {isOffline: false, isBackendReachable: true}, + [ONYXKEYS.NETWORK]: {isOffline: false}, }, }); diff --git a/src/CONST.ts b/src/CONST.ts index 9311816c38a2..920a223b5722 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -560,10 +560,8 @@ const CONST = { EMPTY_ARRAY, EMPTY_OBJECT, USE_EXPENSIFY_URL, - STATUS_EXPENSIFY_URL: 'https://status.expensify.com', GOOGLE_MEET_URL_ANDROID: 'https://meet.google.com', GOOGLE_DOC_IMAGE_LINK_MATCH: 'googleusercontent.com', - GOOGLE_CLOUD_URL: 'https://clients3.google.com/generate_204', IMAGE_BASE64_MATCH: 'base64', DEEPLINK_BASE_URL: 'new-expensify://', PDF_VIEWER_URL: '/pdf/web/viewer.html', @@ -1059,7 +1057,7 @@ const CONST = { MAX_RETRY_WAIT_TIME_MS: 10 * 1000, PROCESS_REQUEST_DELAY_MS: 1000, MAX_PENDING_TIME_MS: 10 * 1000, - BACKEND_CHECK_INTERVAL_MS: 60 * 1000, + RECHECK_INTERVAL_MS: 60 * 1000, MAX_REQUEST_RETRIES: 10, NETWORK_STATUS: { ONLINE: 'online', @@ -1071,7 +1069,7 @@ const CONST = { DEFAULT_TIME_ZONE: {automatic: true, selected: 'America/Los_Angeles'}, DEFAULT_ACCOUNT_DATA: {errors: null, success: '', isLoading: false}, DEFAULT_CLOSE_ACCOUNT_DATA: {errors: null, success: '', isLoading: false}, - DEFAULT_NETWORK_DATA: {isOffline: false, isBackendReachable: true}, + DEFAULT_NETWORK_DATA: {isOffline: false}, FORMS: { LOGIN_FORM: 'LoginForm', VALIDATE_CODE_FORM: 'ValidateCodeForm', diff --git a/src/Expensify.tsx b/src/Expensify.tsx index ddc4b5f88a69..458f1e3c5d24 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -146,10 +146,10 @@ function Expensify({ // Initialize this client as being an active client ActiveClientManager.init(); - // Used for the offline indicator appearing when someone is offline or backend is unreachable - const unsubscribeNetworkStatus = NetworkConnection.subscribeToNetworkStatus(); + // Used for the offline indicator appearing when someone is offline + const unsubscribeNetInfo = NetworkConnection.subscribeToNetInfo(); - return () => unsubscribeNetworkStatus(); + return unsubscribeNetInfo; }, []); useEffect(() => { diff --git a/src/components/OfflineIndicator.tsx b/src/components/OfflineIndicator.tsx index 1cadace6d3b4..337e5dd850f7 100644 --- a/src/components/OfflineIndicator.tsx +++ b/src/components/OfflineIndicator.tsx @@ -7,11 +7,9 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout'; import useTheme from '@hooks/useTheme'; import useThemeStyles from '@hooks/useThemeStyles'; import variables from '@styles/variables'; -import CONST from '@src/CONST'; import Icon from './Icon'; import * as Expensicons from './Icon/Expensicons'; import Text from './Text'; -import TextLink from './TextLink'; type OfflineIndicatorProps = { /** Optional styles for container element that will override the default styling for the offline indicator */ @@ -25,7 +23,7 @@ function OfflineIndicator({style, containerStyles}: OfflineIndicatorProps) { const theme = useTheme(); const styles = useThemeStyles(); const {translate} = useLocalize(); - const {isOffline, isBackendReachable} = useNetwork(); + const {isOffline} = useNetwork(); const {shouldUseNarrowLayout} = useResponsiveLayout(); const computedStyles = useMemo((): StyleProp => { @@ -36,7 +34,7 @@ function OfflineIndicator({style, containerStyles}: OfflineIndicatorProps) { return shouldUseNarrowLayout ? styles.offlineIndicatorMobile : styles.offlineIndicator; }, [containerStyles, shouldUseNarrowLayout, styles.offlineIndicatorMobile, styles.offlineIndicator]); - if (!isOffline && isBackendReachable) { + if (!isOffline) { return null; } @@ -48,22 +46,7 @@ function OfflineIndicator({style, containerStyles}: OfflineIndicatorProps) { width={variables.iconSizeSmall} height={variables.iconSizeSmall} /> - - {isOffline ? ( - translate('common.youAppearToBeOffline') - ) : ( - <> - {translate('common.weMightHaveProblem')} - - {new URL(CONST.STATUS_EXPENSIFY_URL).host} - - . - - )} - + {translate('common.youAppearToBeOffline')} ); } diff --git a/src/hooks/useNetwork.ts b/src/hooks/useNetwork.ts index 65565d035e36..950d0592b59c 100644 --- a/src/hooks/useNetwork.ts +++ b/src/hooks/useNetwork.ts @@ -6,14 +6,13 @@ type UseNetworkProps = { onReconnect?: () => void; }; -type UseNetwork = {isOffline: boolean; isBackendReachable: boolean}; +type UseNetwork = {isOffline: boolean}; export default function useNetwork({onReconnect = () => {}}: UseNetworkProps = {}): UseNetwork { const callback = useRef(onReconnect); callback.current = onReconnect; - const {isOffline, networkStatus, isBackendReachable} = useContext(NetworkContext) ?? {...CONST.DEFAULT_NETWORK_DATA, networkStatus: CONST.NETWORK.NETWORK_STATUS.UNKNOWN}; - const isNetworkStatusUnknown = networkStatus === CONST.NETWORK.NETWORK_STATUS.UNKNOWN; + const {isOffline, networkStatus} = useContext(NetworkContext) ?? {...CONST.DEFAULT_NETWORK_DATA, networkStatus: CONST.NETWORK.NETWORK_STATUS.UNKNOWN}; const prevOfflineStatusRef = useRef(isOffline); useEffect(() => { // If we were offline before and now we are not offline then we just reconnected @@ -30,6 +29,6 @@ export default function useNetwork({onReconnect = () => {}}: UseNetworkProps = { prevOfflineStatusRef.current = isOffline; }, [isOffline]); - // If the network status is unknown, we fallback to default state, i.e. we're online and backend is reachable. - return isNetworkStatusUnknown ? CONST.DEFAULT_NETWORK_DATA : {isOffline, isBackendReachable}; + // If the network status is undefined, we don't treat it as offline. Otherwise, we utilize the isOffline prop. + return {isOffline: networkStatus === CONST.NETWORK.NETWORK_STATUS.UNKNOWN ? false : isOffline}; } diff --git a/src/languages/en.ts b/src/languages/en.ts index bf3803c7606d..f5520afa2cc2 100755 --- a/src/languages/en.ts +++ b/src/languages/en.ts @@ -273,7 +273,6 @@ export default { your: 'your', conciergeHelp: 'Please reach out to Concierge for help.', youAppearToBeOffline: 'You appear to be offline.', - weMightHaveProblem: 'We might have a problem. Check out ', thisFeatureRequiresInternet: 'This feature requires an active internet connection to be used.', attachementWillBeAvailableOnceBackOnline: 'Attachment will become available once back online.', areYouSure: 'Are you sure?', diff --git a/src/languages/es.ts b/src/languages/es.ts index 4c900e23acc5..2facecb0815b 100644 --- a/src/languages/es.ts +++ b/src/languages/es.ts @@ -264,7 +264,6 @@ export default { your: 'tu', conciergeHelp: 'Por favor, contacta con Concierge para obtener ayuda.', youAppearToBeOffline: 'Parece que estás desconectado.', - weMightHaveProblem: 'Peude que te tengamos un problema. Echa un vistazo a ', thisFeatureRequiresInternet: 'Esta función requiere una conexión a Internet activa para ser utilizada.', attachementWillBeAvailableOnceBackOnline: 'El archivo adjunto estará disponible cuando vuelvas a estar en línea.', areYouSure: '¿Estás seguro?', diff --git a/src/libs/NetworkConnection.ts b/src/libs/NetworkConnection.ts index 8c76e52aa42d..0b4ca5291689 100644 --- a/src/libs/NetworkConnection.ts +++ b/src/libs/NetworkConnection.ts @@ -8,7 +8,6 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import * as NetworkActions from './actions/Network'; import AppStateMonitor from './AppStateMonitor'; -import checkInternetReachability from './checkInternetReachability'; import Log from './Log'; let isOffline = false; @@ -43,23 +42,12 @@ function setOfflineStatus(isCurrentlyOffline: boolean, reason = ''): void { // When reconnecting, ie, going from offline to online, all the reconnection callbacks // are triggered (this is usually Actions that need to re-download data from the server) if (isOffline && !isCurrentlyOffline) { - NetworkActions.setIsBackendReachable(true, 'moved from offline to online'); triggerReconnectionCallbacks('offline status changed'); } isOffline = isCurrentlyOffline; } -function setNetWorkStatus(isInternetReachable: boolean | null): void { - let networkStatus; - if (!isBoolean(isInternetReachable)) { - networkStatus = CONST.NETWORK.NETWORK_STATUS.UNKNOWN; - } else { - networkStatus = isInternetReachable ? CONST.NETWORK.NETWORK_STATUS.ONLINE : CONST.NETWORK.NETWORK_STATUS.OFFLINE; - } - NetworkActions.setNetWorkStatus(networkStatus); -} - // Update the offline status in response to changes in shouldForceOffline let shouldForceOffline = false; Onyx.connect({ @@ -103,26 +91,23 @@ Onyx.connect({ }); /** - * Set interval to periodically (re)check backend status. - * Because backend unreachability might imply lost internet connection, we need to check internet reachability. - * @returns clearInterval cleanup + * Set up the event listener for NetInfo to tell whether the user has + * internet connectivity or not. This is more reliable than the Pusher + * `disconnected` event which takes about 10-15 seconds to emit. + * @returns unsubscribe method */ -function subscribeToBackendAndInternetReachability(): () => void { - const intervalID = setInterval(() => { - // Offline status also implies backend unreachability - if (isOffline) { - // Periodically recheck the network connection - // More info: https://github.com/Expensify/App/issues/42988 - recheckNetworkConnection(); - Log.info(`[NetworkStatus] Rechecking the network connection with "isOffline" set to "true" to double-check internet reachability.`); - return; - } - // Using the API url ensures reachability is tested over internet - fetch(`${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/Ping?accountID=${accountID || 'unknown'}`, { - method: 'GET', - cache: 'no-cache', - }) - .then((response) => { +function subscribeToNetInfo(): () => void { + // Note: We are disabling the configuration for NetInfo when using the local web API since requests can get stuck in a 'Pending' state and are not reliable indicators for "offline". + // If you need to test the "recheck" feature then switch to the production API proxy server. + if (!CONFIG.IS_USING_LOCAL_WEB) { + // Calling NetInfo.configure (re)checks current state. We use it to force a recheck whenever we (re)subscribe + NetInfo.configure({ + // By default, NetInfo uses `/` for `reachabilityUrl` + // When App is served locally (or from Electron) this address is always reachable - even offline + // Using the API url ensures reachability is tested over internet + reachabilityUrl: `${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api/Ping?accountID=${accountID || 'unknown'}`, + reachabilityMethod: 'GET', + reachabilityTest: (response) => { if (!response.ok) { return Promise.resolve(false); } @@ -130,44 +115,15 @@ function subscribeToBackendAndInternetReachability(): () => void { .json() .then((json) => Promise.resolve(json.jsonCode === 200)) .catch(() => Promise.resolve(false)); - }) - .then((isBackendReachable: boolean) => { - if (isBackendReachable) { - NetworkActions.setIsBackendReachable(true, 'successfully completed API request'); - return; - } - NetworkActions.setIsBackendReachable(false, 'request succeeded, but internet reachability test failed'); - checkInternetReachability().then((isInternetReachable: boolean) => { - setOfflineStatus(!isInternetReachable, 'checkInternetReachability was called after api/ping returned a non-200 jsonCode'); - setNetWorkStatus(isInternetReachable); - }); - }) - .catch(() => { - NetworkActions.setIsBackendReachable(false, 'request failed and internet reachability test failed'); - checkInternetReachability().then((isInternetReachable: boolean) => { - setOfflineStatus(!isInternetReachable, 'checkInternetReachability was called after api/ping request failed'); - setNetWorkStatus(isInternetReachable); - }); - }); - }, CONST.NETWORK.BACKEND_CHECK_INTERVAL_MS); - - return () => { - clearInterval(intervalID); - }; -} + }, -/** - * Monitor internet connectivity and perform periodic backend reachability checks - * @returns unsubscribe method - */ -function subscribeToNetworkStatus(): () => void { - // Note: We are disabling the reachability check when using the local web API since requests can get stuck in a 'Pending' state and are not reliable indicators for reachability. - // If you need to test the "recheck" feature then switch to the production API proxy server. - const unsubscribeFromBackendReachability = !CONFIG.IS_USING_LOCAL_WEB ? subscribeToBackendAndInternetReachability() : undefined; + // If a check is taking longer than this time we're considered offline + reachabilityRequestTimeout: CONST.NETWORK.MAX_PENDING_TIME_MS, + }); + } - // Set up the event listener for NetInfo to tell whether the user has - // internet connectivity or not. This is more reliable than the Pusher - // `disconnected` event which takes about 10-15 seconds to emit. + // Subscribe to the state change event via NetInfo so we can update + // whether a user has internet connectivity or not. const unsubscribeNetInfo = NetInfo.addEventListener((state) => { Log.info('[NetworkConnection] NetInfo state change', false, {...state}); if (shouldForceOffline) { @@ -176,11 +132,27 @@ function subscribeToNetworkStatus(): () => void { } setOfflineStatus(state.isInternetReachable === false, 'NetInfo received a state change event'); Log.info(`[NetworkStatus] NetInfo.addEventListener event coming, setting "offlineStatus" to ${!!state.isInternetReachable} with network state: ${JSON.stringify(state)}`); - setNetWorkStatus(state.isInternetReachable); + let networkStatus; + if (!isBoolean(state.isInternetReachable)) { + networkStatus = CONST.NETWORK.NETWORK_STATUS.UNKNOWN; + } else { + networkStatus = state.isInternetReachable ? CONST.NETWORK.NETWORK_STATUS.ONLINE : CONST.NETWORK.NETWORK_STATUS.OFFLINE; + } + NetworkActions.setNetWorkStatus(networkStatus); }); + // Periodically recheck the network connection + // More info: https://github.com/Expensify/App/issues/42988 + const recheckIntervalID = setInterval(() => { + if (!isOffline) { + return; + } + recheckNetworkConnection(); + Log.info(`[NetworkStatus] Rechecking the network connection with "isOffline" set to "true" to double-check internet reachability.`); + }, CONST.NETWORK.RECHECK_INTERVAL_MS); + return () => { - unsubscribeFromBackendReachability?.(); + clearInterval(recheckIntervalID); unsubscribeNetInfo(); }; } @@ -231,6 +203,6 @@ export default { onReconnect, triggerReconnectionCallbacks, recheckNetworkConnection, - subscribeToNetworkStatus, + subscribeToNetInfo, }; export type {NetworkStatus}; diff --git a/src/libs/actions/Network.ts b/src/libs/actions/Network.ts index 883e336d6c90..d8a87aff551d 100644 --- a/src/libs/actions/Network.ts +++ b/src/libs/actions/Network.ts @@ -3,15 +3,6 @@ import Log from '@libs/Log'; import type {NetworkStatus} from '@libs/NetworkConnection'; import ONYXKEYS from '@src/ONYXKEYS'; -function setIsBackendReachable(isBackendReachable: boolean, reason: string) { - if (isBackendReachable) { - Log.info(`[Network] Backend is reachable because: ${reason}`); - } else { - Log.info(`[Network] Backend is not reachable because: ${reason}`); - } - Onyx.merge(ONYXKEYS.NETWORK, {isBackendReachable}); -} - function setIsOffline(isOffline: boolean, reason = '') { if (reason) { let textToLog = '[Network] Client is'; @@ -41,4 +32,4 @@ function setShouldFailAllRequests(shouldFailAllRequests: boolean) { Onyx.merge(ONYXKEYS.NETWORK, {shouldFailAllRequests}); } -export {setIsBackendReachable, setIsOffline, setShouldForceOffline, setShouldFailAllRequests, setTimeSkew, setNetWorkStatus}; +export {setIsOffline, setShouldForceOffline, setShouldFailAllRequests, setTimeSkew, setNetWorkStatus}; diff --git a/src/libs/checkInternetReachability/index.android.ts b/src/libs/checkInternetReachability/index.android.ts deleted file mode 100644 index da46623c3e05..000000000000 --- a/src/libs/checkInternetReachability/index.android.ts +++ /dev/null @@ -1,15 +0,0 @@ -import CONST from '@src/CONST'; -import type InternetReachabilityCheck from './types'; - -/** - * Although Android supports internet reachability check, it only does on initiating the connection. - * We need to implement a test for a highly-available endpoint in case of lost internet after initiation. - */ -export default function checkInternetReachability(): InternetReachabilityCheck { - return fetch(CONST.GOOGLE_CLOUD_URL, { - method: 'GET', - cache: 'no-cache', - }) - .then((response) => Promise.resolve(response.status === 204)) - .catch(() => Promise.resolve(false)); -} diff --git a/src/libs/checkInternetReachability/index.ts b/src/libs/checkInternetReachability/index.ts deleted file mode 100644 index d7d0808c6efc..000000000000 --- a/src/libs/checkInternetReachability/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type InternetReachabilityCheck from './types'; - -export default function checkInternetReachability(): InternetReachabilityCheck { - return Promise.resolve(true); -} diff --git a/src/libs/checkInternetReachability/types.ts b/src/libs/checkInternetReachability/types.ts deleted file mode 100644 index 3e1cb96cb26c..000000000000 --- a/src/libs/checkInternetReachability/types.ts +++ /dev/null @@ -1,3 +0,0 @@ -type InternetReachabilityCheck = Promise; - -export default InternetReachabilityCheck; diff --git a/src/types/onyx/Network.ts b/src/types/onyx/Network.ts index 4ef24a314647..680c6c468c00 100644 --- a/src/types/onyx/Network.ts +++ b/src/types/onyx/Network.ts @@ -5,9 +5,6 @@ type Network = { /** Is the network currently offline or not */ isOffline: boolean; - /** Is the backend reachable when online */ - isBackendReachable: boolean; - /** Should the network be forced offline */ shouldForceOffline?: boolean; diff --git a/tests/unit/APITest.ts b/tests/unit/APITest.ts index 07633b19802b..9688b0890c34 100644 --- a/tests/unit/APITest.ts +++ b/tests/unit/APITest.ts @@ -68,7 +68,7 @@ describe('APITests', () => { const xhr = jest.spyOn(HttpUtils, 'xhr').mockRejectedValue(new Error('Unexpected xhr call')); // Given we're offline - return Onyx.set(ONYXKEYS.NETWORK, {isOffline: true, isBackendReachable: false}) + return Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}) .then(() => { // When API Writes and Reads are called API.write('mock command' as WriteCommand, {param1: 'value1'} as ApiRequestCommandParameters[WriteCommand]); @@ -101,7 +101,7 @@ describe('APITests', () => { // Given we have some requests made while we're offline return ( Onyx.multiSet({ - [ONYXKEYS.NETWORK]: {isOffline: true, isBackendReachable: false}, + [ONYXKEYS.NETWORK]: {isOffline: true}, [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin: 'test', autoGeneratedPassword: 'passwd'}, [ONYXKEYS.SESSION]: {authToken: 'testToken'}, }) @@ -117,7 +117,7 @@ describe('APITests', () => { }) // When we resume connectivity - .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true})) + .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) .then(waitForBatchedUpdates) .then(() => { expect(NetworkStore.isOffline()).toBe(false); @@ -153,7 +153,7 @@ describe('APITests', () => { // Given we have some requests made while we're offline return ( - Onyx.set(ONYXKEYS.NETWORK, {isOffline: true, isBackendReachable: false}) + Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}) .then(() => { // When API Write commands are made API.write('mock command' as WriteCommand, {param1: 'value1'} as ApiRequestCommandParameters[WriteCommand]); @@ -162,7 +162,7 @@ describe('APITests', () => { }) // When we resume connectivity - .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true})) + .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) .then(waitForBatchedUpdates) .then(() => { // Then requests should remain persisted until the xhr call is resolved @@ -215,7 +215,7 @@ describe('APITests', () => { // Given we have a request made while we're offline return ( - Onyx.set(ONYXKEYS.NETWORK, {isOffline: true, isBackendReachable: false}) + Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}) .then(() => { // When API Write commands are made API.write('mock command' as WriteCommand, {param1: 'value1'} as ApiRequestCommandParameters[WriteCommand]); @@ -223,7 +223,7 @@ describe('APITests', () => { }) // When we resume connectivity - .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true})) + .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) .then(waitForBatchedUpdates) .then(() => { // Then there has only been one request so far @@ -302,14 +302,14 @@ describe('APITests', () => { Onyx.merge(ONYXKEYS.CREDENTIALS, {autoGeneratedLogin: 'test', autoGeneratedPassword: 'passwd'}); return ( waitForBatchedUpdates() - .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: true, isBackendReachable: false})) + .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: true})) .then(() => { API.write('Mock' as WriteCommand, {param1: 'value1'} as ApiRequestCommandParameters[WriteCommand]); return waitForBatchedUpdates(); }) // When we resume connectivity - .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true})) + .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) .then(waitForBatchedUpdates) .then(() => { const nonLogCalls = xhr.mock.calls.filter(([commandName]) => commandName !== 'Log'); @@ -332,7 +332,7 @@ describe('APITests', () => { const xhr = jest.spyOn(HttpUtils, 'xhr').mockResolvedValue({jsonCode: CONST.JSON_CODE.SUCCESS}); return Onyx.multiSet({ [ONYXKEYS.SESSION]: {authToken: 'anyToken'}, - [ONYXKEYS.NETWORK]: {isOffline: true, isBackendReachable: false}, + [ONYXKEYS.NETWORK]: {isOffline: true}, [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin: 'test_user', autoGeneratedPassword: 'psswd'}, }) .then(() => { @@ -347,7 +347,7 @@ describe('APITests', () => { return waitForBatchedUpdates(); }) - .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true})) + .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) .then(waitForBatchedUpdates) .then(() => { // Then expect all 7 calls to have been made and for the Writes to be made in the order that we made them @@ -368,7 +368,7 @@ describe('APITests', () => { const xhr = jest.spyOn(HttpUtils, 'xhr').mockResolvedValueOnce({jsonCode: CONST.JSON_CODE.NOT_AUTHENTICATED}).mockResolvedValue({jsonCode: CONST.JSON_CODE.SUCCESS}); return Onyx.multiSet({ - [ONYXKEYS.NETWORK]: {isOffline: true, isBackendReachable: false}, + [ONYXKEYS.NETWORK]: {isOffline: true}, [ONYXKEYS.SESSION]: {authToken: 'test'}, [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin: 'test', autoGeneratedPassword: 'passwd'}, }) @@ -382,7 +382,7 @@ describe('APITests', () => { API.write('MockCommand' as WriteCommand, {content: 'value6'} as ApiRequestCommandParameters[WriteCommand]); return waitForBatchedUpdates(); }) - .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true})) + .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) .then(waitForBatchedUpdates) .then(() => { // Then expect only 8 calls to have been made total and for them to be made in the order that we made them despite requiring reauthentication @@ -412,7 +412,7 @@ describe('APITests', () => { return Onyx.multiSet({ [ONYXKEYS.SESSION]: {authToken: 'oldToken'}, - [ONYXKEYS.NETWORK]: {isOffline: false, isBackendReachable: true}, + [ONYXKEYS.NETWORK]: {isOffline: false}, [ONYXKEYS.CREDENTIALS]: {autoGeneratedLogin: 'test_user', autoGeneratedPassword: 'psswd'}, }) .then(() => { @@ -426,7 +426,7 @@ describe('APITests', () => { forceNetworkRequest: false, }); - Onyx.set(ONYXKEYS.NETWORK, {isOffline: true, isBackendReachable: false}); + Onyx.set(ONYXKEYS.NETWORK, {isOffline: true}); expect(NetworkStore.isOffline()).toBe(false); expect(NetworkStore.isAuthenticating()).toBe(false); return waitForBatchedUpdates(); @@ -444,7 +444,7 @@ describe('APITests', () => { waitForBatchedUpdates(); // Come back from offline to trigger the sequential queue flush - Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true}); + Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}); }) .then(() => { // When we wait for the sequential queue to finish @@ -491,7 +491,7 @@ describe('APITests', () => { // Given a simulated a condition where the credentials have not yet been read from storage and we are offline return Onyx.multiSet({ - [ONYXKEYS.NETWORK]: {isOffline: true, isBackendReachable: false}, + [ONYXKEYS.NETWORK]: {isOffline: true}, [ONYXKEYS.CREDENTIALS]: {}, [ONYXKEYS.SESSION]: null, }) @@ -507,7 +507,7 @@ describe('APITests', () => { expect(PersistedRequests.getAll().length).toBe(1); // When we go online and wait for promises to resolve - return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true}); + return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}); }) .then(waitForBatchedUpdates) .then(() => { @@ -531,7 +531,7 @@ describe('APITests', () => { test('Write request will move directly to the SequentialQueue when we are online and block non-Write requests', () => { const xhr = jest.spyOn(HttpUtils, 'xhr'); - return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true}) + return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}) .then(() => { // GIVEN that we are online expect(NetworkStore.isOffline()).toBe(false); diff --git a/tests/unit/NetworkTest.ts b/tests/unit/NetworkTest.ts index 850e7d5c236a..42b3024efaa3 100644 --- a/tests/unit/NetworkTest.ts +++ b/tests/unit/NetworkTest.ts @@ -109,7 +109,7 @@ describe('NetworkTests', () => { // This should first trigger re-authentication and then a Failed to fetch PersonalDetails.openPublicProfilePage(TEST_USER_ACCOUNT_ID); return waitForBatchedUpdates() - .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true})) + .then(() => Onyx.set(ONYXKEYS.NETWORK, {isOffline: false})) .then(() => { expect(isOffline).toBe(false); @@ -260,7 +260,7 @@ describe('NetworkTests', () => { const logHmmmSpy = jest.spyOn(Log, 'hmmm'); // Given we have a request made while online - return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true}) + return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}) .then(() => { Network.post('MockBadNetworkResponse', {param1: 'value1'}); return waitForBatchedUpdates(); @@ -276,7 +276,7 @@ describe('NetworkTests', () => { const logAlertSpy = jest.spyOn(Log, 'alert'); // Given we have a request made while online - return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true}) + return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}) .then(() => { Network.post('MockBadNetworkResponse', {param1: 'value1'}); return waitForBatchedUpdates(); @@ -292,7 +292,7 @@ describe('NetworkTests', () => { const onResolved = jest.fn(); // Given we have a request made while online - return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true}) + return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}) .then(() => { expect(NetworkStore.isOffline()).toBe(false); @@ -313,7 +313,7 @@ describe('NetworkTests', () => { // GIVEN a mock that will return a "cancelled" request error global.fetch = jest.fn().mockRejectedValue(new DOMException('Aborted', CONST.ERROR.REQUEST_CANCELLED)); - return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false, isBackendReachable: true}) + return Onyx.set(ONYXKEYS.NETWORK, {isOffline: false}) .then(() => { // WHEN we make a few requests and then cancel them Network.post('MockCommandOne');