Repository navigation
Add test tools to make it easier to test Network/reauthentication logic #8713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import {withOnyx} from 'react-native-onyx'; | ||
| import styles from '../styles/styles'; | ||
| import Switch from './Switch'; | ||
| import Text from './Text'; | ||
| import * as User from '../libs/actions/User'; | ||
| import * as Network from '../libs/actions/Network'; | ||
| import * as Session from '../libs/actions/Session'; | ||
| import ONYXKEYS from '../ONYXKEYS'; | ||
| import Button from './Button'; | ||
| import * as NetworkStore from '../libs/Network/NetworkStore'; | ||
| import TestToolRow from './TestToolRow'; | ||
|
|
||
| const propTypes = { | ||
| /** User object in Onyx */ | ||
| user: PropTypes.shape({ | ||
| /** Whether we should use the staging version of the secure API server */ | ||
| shouldUseSecureStaging: PropTypes.bool, | ||
| }), | ||
|
|
||
| /** Network object in Onyx */ | ||
| network: PropTypes.shape({ | ||
| /** Whether we should fail all network requests */ | ||
| shouldFailAllRequests: PropTypes.bool, | ||
| }), | ||
| }; | ||
|
|
||
| const defaultProps = { | ||
| user: { | ||
| shouldUseSecureStaging: false, | ||
| }, | ||
| network: { | ||
| shouldFailAllRequests: false, | ||
| }, | ||
| }; | ||
|
|
||
| const TestToolMenu = props => ( | ||
| <> | ||
| <Text style={[styles.formLabel]} numberOfLines={1}> | ||
| Test Preferences | ||
| </Text> | ||
|
|
||
| {/* Option to switch from using the staging secure endpoint or the production secure endpoint. | ||
| This enables QA and internal testers to take advantage of sandbox environments for 3rd party services like Plaid and Onfido. */} | ||
| <TestToolRow title="Use Secure Staging Server"> | ||
| <Switch | ||
| isOn={props.user.shouldUseSecureStaging || false} | ||
| onToggle={() => User.setShouldUseSecureStaging(!props.user.shouldUseSecureStaging)} | ||
| /> | ||
| </TestToolRow> | ||
|
|
||
| {/* When toggled all network requests will fail. */} | ||
| <TestToolRow title="Simulate failing network requests"> | ||
| <Switch | ||
| isOn={props.network.shouldFailAllRequests || false} | ||
|
marcaaron marked this conversation as resolved.
Resolved
|
||
| onToggle={() => Network.setShouldFailAllRequests(!props.network.shouldFailAllRequests)} | ||
| /> | ||
| </TestToolRow> | ||
|
|
||
| {/* Instantly invalidates a user's local authToken. Useful for testing flows related to reauthentication. */} | ||
| <TestToolRow title="Authentication status"> | ||
| <Button | ||
| small | ||
| text="Invalidate" | ||
| onPress={() => NetworkStore.setAuthToken('pizza')} | ||
| /> | ||
| </TestToolRow> | ||
|
|
||
| {/* Invalidate stored user auto-generated credentials. Useful for manually testing sign out logic. */} | ||
| <TestToolRow title="Device credentials"> | ||
| <Button | ||
| small | ||
| text="Destroy" | ||
| onPress={() => Session.invalidateCredentials()} | ||
| /> | ||
| </TestToolRow> | ||
| </> | ||
| ); | ||
|
|
||
| TestToolMenu.propTypes = propTypes; | ||
| TestToolMenu.defaultProps = defaultProps; | ||
| export default withOnyx({ | ||
| user: { | ||
| key: ONYXKEYS.USER, | ||
| }, | ||
| network: { | ||
| key: ONYXKEYS.NETWORK, | ||
| }, | ||
| })(TestToolMenu); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import React from 'react'; | ||
| import PropTypes from 'prop-types'; | ||
| import {View} from 'react-native'; | ||
| import styles from '../styles/styles'; | ||
| import Text from './Text'; | ||
|
|
||
| const propTypes = { | ||
| /** Title of control */ | ||
| title: PropTypes.string.isRequired, | ||
|
|
||
| /** Control component jsx */ | ||
| children: PropTypes.node.isRequired, | ||
| }; | ||
|
|
||
| const TestToolRow = props => ( | ||
| <View style={[styles.flexRow, styles.mb6, styles.justifyContentBetween, styles.alignItemsCenter]}> | ||
| <View style={styles.flex4}> | ||
| <Text> | ||
| {props.title} | ||
| </Text> | ||
| </View> | ||
| <View style={[styles.flex1, styles.alignItemsEnd]}> | ||
| {props.children} | ||
| </View> | ||
| </View> | ||
| ); | ||
|
|
||
| TestToolRow.propTypes = propTypes; | ||
| export default TestToolRow; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,6 +37,7 @@ function LogCommand(parameters) { | |
| function serverLoggingCallback(logger, params) { | ||
| const requestParams = params; | ||
| requestParams.shouldProcessImmediately = false; | ||
| requestParams.shouldRetry = false; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One weird side effect of trigger the option where all the requests should fail is that some iteration of a Log command is getting retried forever. I suspect it's something like:
But not 100% sure and need to debug some more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think we need more debugging to find out that |
||
| requestParams.expensifyCashAppVersion = `expensifyCash[${getPlatform()}]${version}`; | ||
| if (requestParams.parameters) { | ||
| requestParams.parameters = JSON.stringify(params.parameters); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.