-
Notifications
You must be signed in to change notification settings - Fork 136
Issue/8178 fix user role fetch #8179
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
Conversation
| private fun restartMainActivity() { | ||
| if (ProcessLifecycleOwner.get().lifecycle.currentState.isAtLeast(STARTED)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I renamed the function to make it clear this would restart the activity, and I added the lifecycle's state check here instead of repeating it always, if it's called when the app is backgrounded, we don't want to pop the activity our of nowhere or the app to crash.
| doReturn(expectedUser.isUserEligible()).whenever(appPrefsWrapper).isUserEligible() | ||
| doReturn(expectedUser.email).whenever(appPrefsWrapper).getUserEmail() | ||
| whenever(userStore.fetchUserRole(any())).thenReturn(WooResult(expectedUser)) | ||
|
|
||
| fetcher.fetchUserEligibility() | ||
| fetcher.fetchUserInfo() | ||
|
|
||
| assertThat(appPrefsWrapper.isUserEligible()).isEqualTo(expectedUser.isUserEligible()) | ||
| assertThat(appPrefsWrapper.getUserEmail()).isEqualTo(expectedUser.email) | ||
| assertFalse(appPrefsWrapper.isUserEligible()) | ||
| verify(appPrefsWrapper).setUserEmail(expectedUser.email) | ||
| verify(appPrefsWrapper).setIsUserEligible(expectedUser.isUserEligible()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the other test below didn't test what they say they test, as all what it was done is setting the mocks and then checking that they return what we set. I updated them to confirm the behavior against what userStore would return.
| suspend fun fetchUserInfo(): WCUserModel? { | ||
| return userStore.fetchUserRole(selectedSite.get()).model?.also { | ||
| updateUserInfo(it) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of having two functions, I opted to have a single suspendable one, and it automatically saves the data to the prefs, this way, the clients won't have to call updateUserInfo themselves.
|
You can test the changes on this Pull Request by downloading an installable build, or scanning this QR code: |
|
Thanks for fixing this bug and making the code simpler and safer. Great job @hichamboushaba. Works perfect! |
Closes: #8178
Description
This PR fixes the above issue by making sure we re-open the MainActivity after the fetch if the user is ineligible.
Testing instructions
RELEASE-NOTES.txtif necessary.