Skip to content

Enable native staging apps to use Staging API#13029

Merged
marcochavezf merged 10 commits into
mainfrom
vit-experiementWithStagingNative
Dec 5, 2022
Merged

Enable native staging apps to use Staging API#13029
marcochavezf merged 10 commits into
mainfrom
vit-experiementWithStagingNative

Conversation

@mountiny

@mountiny mountiny commented Nov 24, 2022

Copy link
Copy Markdown
Contributor

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 getPlatfrom call 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

  • Verify that no errors appear in the JS console

Internal tests

  1. Copy the contents from the .env.production to your .env file

  2. Make changes to this line so the test preferences are shown in

  3. Run the iOS and Android app

  4. Make sure the toggle for staging api is turned on

  5. Performs some actions in the app

  6. Go to logs and search for the most recent actions by this account

  7. Make sure the servers these request hit are staging servers

  8. Go back to the settings and switch to production API

  9. Repeat and confirm in the logs the request are hitting the production servers

  10. Run the app in desktop with staging env

  11. Confirm the correct servers are hit based on the toggle value

  12. Run the app in desktop with production env

  13. Confirm the production servers are used

Test that local development still works

  1. Run with dev env and make sure the API hits your local VM

Offline tests

No offline tests here.

QA Steps

  • Verify that no errors appear in the JS console
  1. Open the iOS and Android staging app

  2. Make sure the toggle for staging api is turned on

  3. Performs some actions in the app

  4. Go to logs and search for the most recent actions by this account

  5. Make sure the servers these request hit are staging servers

  6. Go back to the settings and switch to production API

  7. Repeat and confirm in the logs the request are hitting the production servers

  8. Run the staging web

  9. 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 Issues section above

  • I wrote clear testing steps that cover the changes made in this PR

    • I added steps for local testing in the Tests section
    • I added steps for the expected offline behavior in the Offline steps section
    • I added steps for Staging and/or Production testing in the QA steps section
    • I added steps to cover failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I included screenshots or videos for tests on all platforms

  • I ran the tests on all platforms & verified they passed on:

    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • 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)

    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick)
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If 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 using Avatar are 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:

    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:

    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. 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 Avatar is modified, I verified that Avatar is 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

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for expected offline behavior are in the Offline steps section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
    • I tested this PR with a High Traffic account against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability).
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. 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 Avatar is modified, I verified that Avatar is 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 reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

  1. Using dev env confirming that is not broken:
  • in web:

Screenshot 2022-12-05 at 13 42 23

  • in native also seems to point ot dev just fine:

image

  1. Staging env on desktop

image

  • staging but toggling to use production api works well too

image

  1. Staging env on native (that is how I can test locally the staging switch as the local build with production API is considered to be production app so no toggle shows up) - for this I had to force staging environment also here as the badge and the settings rely on request to play store to check the App version which obviously does not work locally.

image

the production api has been used if the toggle has changed back to prodcution

  1. Using Production API
  • desktop

image

- native using production API correctly sends the requests to production

image

Web image

with staging variables
image

Mobile Web - Chrome
Mobile Web - Safari
Desktop image
iOS image image
Android

@mountiny mountiny added the InternalQA This pull request required internal QA label Nov 24, 2022
@mountiny mountiny self-assigned this Nov 24, 2022
@mountiny mountiny requested a review from a team as a code owner November 24, 2022 22:40
@melvin-bot melvin-bot Bot requested review from marcochavezf and parasharrajat and removed request for a team November 24, 2022 22:41
@melvin-bot

melvin-bot Bot commented Nov 24, 2022

Copy link
Copy Markdown

@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]

@mountiny mountiny changed the title Enable native staging apps to use Staging API [WIP] Enable native staging apps to use Staging API Nov 24, 2022
@mountiny

mountiny commented Nov 24, 2022

Copy link
Copy Markdown
Contributor Author

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

@marcochavezf

marcochavezf commented Dec 1, 2022

Copy link
Copy Markdown
Contributor

In case of Android and iOS, the Config file is not accessible in staging build (we use production env during building)

@mountiny, I think this ^ is why IS_IN_STAGING is not setting the correct value, but we're already able to know if the env is staging on native apps (i.e. Android app from the internal beta program). For example, we display the TestToolMenu and the staging logo on staging native apps. So what if we use the same logic of the TestToolMenu or the staging log to use the Staging API in HttpUtils?

@mountiny

mountiny commented Dec 1, 2022

Copy link
Copy Markdown
Contributor Author

@mountiny, I think this ^ is why IS_IN_STAGING is not setting the correct value, but we're already able to know if the env is staging on native apps (i.e. Android app from the internal beta program). For example, we display the TestToolMenu and the staging logo on staging native apps. So what if we use the same logic of the TestToolMenu or the staging log to use the Staging API in HttpUtils?

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).

@marcochavezf

marcochavezf commented Dec 1, 2022

Copy link
Copy Markdown
Contributor

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.

Ah why checking environment === CONST.ENVIRONMENT.STAGING directly in HttpUtils will make a request to App Stores and would block other requests?

My thinking is that IS_IN_STAGING is initialized (for some reason) with the wrong value, because environment === CONST.ENVIRONMENT.STAGING is true (expected value) in other parts of the staging native apps.

@mountiny

mountiny commented Dec 1, 2022

Copy link
Copy Markdown
Contributor Author

because environment === CONST.ENVIRONMENT.STAGING is true (expected value) in other parts of the staging native apps

In other parts of the staging native apps we always use getEnvironment method which makes the API request

@marcochavezf

Copy link
Copy Markdown
Contributor

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?

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).

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 getEnvironment is completed before we make any other request?

@mountiny

mountiny commented Dec 2, 2022

Copy link
Copy Markdown
Contributor Author

is there a problem if we block the other requests until the getEnvironment is completed?

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.

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 getEnvironment is completed before we make any other request?

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)

@mountiny mountiny changed the title [WIP] Enable native staging apps to use Staging API Enable native staging apps to use Staging API Dec 5, 2022
@mountiny

mountiny commented Dec 5, 2022

Copy link
Copy Markdown
Contributor Author

@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()))}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only default to true if we are in web or desktop which can read the correct config

@marcochavezf

marcochavezf commented Dec 5, 2022

Copy link
Copy Markdown
Contributor

Reviewer Checklist

  • I have verified the author checklist is complete (all boxes are checked off).
  • I verified the correct issue is linked in the ### Fixed Issues section above
  • I verified testing steps are clear and they cover the changes made in this PR
    • I verified the steps for local testing are in the Tests section
    • I verified the steps for Staging and/or Production testing are in the QA steps section
    • I verified the steps cover any possible failure scenarios (i.e. verify an input displays the correct error message if the entered data is not correct)
    • I turned off my network connection and tested it while offline to ensure it matches the expected behavior (i.e. verify the default avatar icon is displayed if app is offline)
  • I checked that screenshots or videos are included for tests on all platforms
  • I included screenshots or videos for tests on all platforms
  • I verified tests pass on all platforms & I tested again on:
    • iOS / native
    • Android / native
    • iOS / Safari
    • Android / Chrome
    • MacOS / Chrome
    • MacOS / Desktop
  • If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack
  • I verified proper code patterns were followed (see Reviewing the code)
    • I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. toggleReport and not onIconClick).
    • I verified that comments were added to code that is not self explanatory
    • I verified that any new or modified comments were clear, correct English, and explained "why" the code was doing something instead of only explaining "what" the code was doing.
    • I verified any copy / text shown in the product was added in all src/languages/* files
    • I verified any copy / text that was added to the app is correct English and approved by marketing by adding the Waiting for Copy label for a copy review on the original GH to get the correct copy.
    • I verified proper file naming conventions were followed for any new files or renamed files. All non-platform specific files are named after what they export and are not named "index.js". All platform-specific files are named for the platform the code supports as outlined in the README.
    • I verified the JSDocs style guidelines (in STYLE.md) were followed
  • If a new code pattern is added I verified it was agreed to be used by multiple Expensify engineers
  • I verified that this PR follows the guidelines as stated in the Review Guidelines
  • I verified other components that can be impacted by these changes have been tested, and I retested again (i.e. if the PR modifies a shared library or component like Avatar, I verified the components using Avatar have been tested & I retested again)
  • 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
  • If a new component is created I verified that:
    • A similar component doesn't exist in the codebase
    • All props are defined accurately and each prop has a /** comment above it */
    • The file is named correctly
    • The component has a clear name that is non-ambiguous and the purpose of the component can be inferred from the name alone
    • The only data being stored in the state is data necessary for rendering and nothing else
    • For Class Components, any internal methods passed to components event handlers are bound to this properly so there are no scoping issues (i.e. for onClick={this.submit} the method this.submit should be bound to this in the constructor)
    • Any internal methods bound to this are necessary to be bound (i.e. avoid this.submit = this.submit.bind(this); if this.submit is never passed to a component event handler like onClick)
    • All JSX used for rendering exists in the render method
    • The component has the minimum amount of code necessary for its purpose, and it is broken down into smaller components in order to separate concerns and functions
  • If a new CSS style is added I verified that:
    • A similar style doesn't already exist
    • The style can't be created with an existing StyleUtils function (i.e. 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 Avatar is modified, I verified that Avatar is 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 reviewer checklist, including those that don't apply to this PR.

Screenshots/Videos

Web

Verifiying web is pointing to VM:

Screenshot 2022-12-05 at 17 19 12
Mobile Web - Chrome Screenshot 2022-12-05 at 17 22 50
Mobile Web - Safari Screenshot 2022-12-05 at 17 19 45
Desktop

Using staging:

Screenshot 2022-12-05 at 17 15 28 Screenshot 2022-12-05 at 14 42 06

Using production:

Screenshot 2022-12-05 at 17 05 20 Screenshot 2022-12-05 at 14 40 14
iOS Screenshot 2022-12-05 at 16 47 29
Android Screenshot 2022-12-05 at 14 40 45

@marcochavezf marcochavezf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mountiny! Tests went well

@marcochavezf marcochavezf merged commit 36a009b into main Dec 5, 2022
@marcochavezf marcochavezf deleted the vit-experiementWithStagingNative branch December 5, 2022 23:30
@OSBotify

OSBotify commented Dec 5, 2022

Copy link
Copy Markdown
Contributor

✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release.

@mountiny

mountiny commented Dec 6, 2022

Copy link
Copy Markdown
Contributor Author

Thank you @marcochavezf

@mountiny

mountiny commented Dec 9, 2022

Copy link
Copy Markdown
Contributor Author

QAed this on web and iOS mobile and it works well 🎉

@OSBotify

Copy link
Copy Markdown
Contributor

🚀 Deployed to production by @chiragsalian in version: 1.2.38-6 🚀

platform result
🤖 android 🤖 success ✅
🖥 desktop 🖥 success ✅
🍎 iOS 🍎 success ✅
🕸 web 🕸 success ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

InternalQA This pull request required internal QA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants