Enable native staging apps to use Staging API#13029
Conversation
|
@parasharrajat @marcochavezf One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
This is WIP because there will be still an issue now with Production native app pointing to staging. After thinking about this for a while I think we dont have other option than to default the staging api toggle to false and hence start the staging apps with production API until the user changes this settings to staging API (in native at least). I think it is not ideal but I think this is fine as it does not stop us from testing staging API |
@mountiny, I think this ^ is why |
Hwy hey sorry I got lost in other issues before coming back to this one. So we had been thinking about all those options, the problem with the approach you mention is that it needs to make a request to App stores to find out about the beta. Since the place where it makes sense to make this request is when the app is being loaded, we would block other request/slow them down if we would do this and initially we would use different api than expected. Therefore the best solution which will work predictably and consistently is to default to production instead of staging and then just switch based on the toggle once onyx state if loaded (in case on native apps). |
Ah why checking My thinking is that |
In other parts of the staging native apps we always use getEnvironment method which makes the API request |
Oh I see, but is there a problem if we block the other requests until the getEnvironment is completed?
Sorry if I'm missing something, but how will we know that we have to turn on the staging switch automatically on staging apps? Isn't more reliable to wait until |
Normally we dont call this as app start, which we would have to do here and also even in production since we dont have a way to know to not make this request if in production. If the request is made somewhere else in the App it is not such huge problem.
the getEnvironment is used to decide if we should show the toggle, then if we are in staging, we show the toggle but its actual value is help only in Onyx and that is what will decide where we will point. We cannot however safely default to staging, we will need to default to production and then let the user who is on staging switch to staging. That will be saved until the onyx data is reset by signing out (I dont think we save this in database) |
|
@marcochavezf @parasharrajat Not sure how Rajat you can test this in native apps locally but this is ready for review/ testing. I have included all my testing scenarios in the PR body, it took a while to test everything. There is no ideal solution to this so I feel like this is the least evil route. |
| <TestToolRow title="Use Staging Server"> | ||
| <Switch | ||
| isOn={lodashGet(props, 'user.shouldUseStagingServer', true)} | ||
| isOn={lodashGet(props, 'user.shouldUseStagingServer', _.contains([CONST.PLATFORM.WEB, CONST.PLATFORM.DESKTOP], getPlatform()))} |
There was a problem hiding this comment.
Only default to true if we are in web or desktop which can read the correct config
Reviewer Checklist
Screenshots/Videos |
marcochavezf
left a comment
There was a problem hiding this comment.
Thanks @mountiny! Tests went well
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
Thank you @marcochavezf |
|
QAed this on web and iOS mobile and it works well 🎉 |
|
🚀 Deployed to production by @chiragsalian in version: 1.2.38-6 🚀
|









Details
This PR will enable us to use staging API in native apps as well. This is a follow up to this PR #12880 which had to be reverted as after one refactor update the dev environment was not read correctly locally.
The shouldUseStaging variable will be false by default in native apps. In production App, user does not have access to the toggle hence they cannot switch production app to use Staging API. In staging, this means that before the Onyx data is available we will defer to production API, which is safe bet and how staging app works now. Once the settings is available we will decide based on the toggle state.
For desktop and web, we will keep the same behaviour which we achieve by using the
getPlatfromcall to check for Web and desktop.In case of Android and iOS, the Config file is not accessible in staging build (we use production env during building), therefore we need to rely only on the staging toggle in this case and that is why we add this platform specific check.
Fixed Issues
$ #11561
$ #11068
Tests
Internal tests
Copy the contents from the
.env.productionto your.envfileMake changes to this line so the test preferences are shown in
Run the iOS and Android app
Make sure the toggle for staging api is turned on
Performs some actions in the app
Go to logs and search for the most recent actions by this account
Make sure the servers these request hit are staging servers
Go back to the settings and switch to production API
Repeat and confirm in the logs the request are hitting the production servers
Run the app in desktop with staging env
Confirm the correct servers are hit based on the toggle value
Run the app in desktop with production env
Confirm the production servers are used
Test that local development still works
Offline tests
No offline tests here.
QA Steps
Open the iOS and Android staging app
Make sure the toggle for staging api is turned on
Performs some actions in the app
Go to logs and search for the most recent actions by this account
Make sure the servers these request hit are staging servers
Go back to the settings and switch to production API
Repeat and confirm in the logs the request are hitting the production servers
Run the staging web
By checking the logs, confirm the correct servers are being hit based on what stage the toggle is at
PR Author Checklist
I linked the correct issue in the
### Fixed Issuessection aboveI wrote clear testing steps that cover the changes made in this PR
TestssectionOffline stepssectionQA stepssectionI included screenshots or videos for tests on all platforms
I ran the tests on all platforms & verified they passed on:
I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed)
I followed proper code patterns (see Reviewing the code)
toggleReportand notonIconClick)src/languages/*filesWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedIf a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
I followed the guidelines as stated in the Review Guidelines
I tested other components that can be impacted by my changes (i.e. if the PR modifies a shared library or component like
Avatar, I verified the components usingAvatarare working as expected)I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
I verified any variables that can be defined as constants (ie. in CONST.js or at the top of the file that uses the constant) are defined as such
I verified that if a function's arguments changed that all usages have also been updated correctly
If a new component is created I verified that:
/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)If a new CSS style is added I verified that:
StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)If the PR modifies a generic component, I tested and verified that those changes do not break usages of that component in the rest of the App (i.e. if a shared library or component like
Avataris modified, I verified thatAvataris working as expected in all cases)If the PR modifies a component related to any of the existing Storybook stories, I tested and verified all stories for that component are still working as expected.
I have checked off every checkbox in the PR author checklist, including those that don't apply to this PR.
PR Reviewer Checklist
The reviewer will copy/paste it into a new comment and complete it after the author checklist is completed
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick).src/languages/*filesWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarhave been tested & I retested again)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)Screenshots/Videos
the production api has been used if the toggle has changed back to prodcution

- native using production API correctly sends the requests to productionWeb
with staging variables

Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android