-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8713 from Expensify/marcaaron-reauthenticationTools
Add test tools to make it easier to test Network/reauthentication logic
- Loading branch information
Showing
7 changed files
with
150 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} | ||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters