Skip to content

Commit

Permalink
Merge pull request #17262 from wordpress-mobile/fix/null-access-token…
Browse files Browse the repository at this point in the history
…-share-login-resolver

Fix NullPointerException in SharedLoginResolver
RenanLukas authored Oct 4, 2022
2 parents cfe078a + ad5cd53 commit 15fd77f
Showing 2 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -30,10 +30,13 @@ class SharedLoginResolver @Inject constructor(
private val sharedLoginAnalyticsTracker: SharedLoginAnalyticsTracker
) {
fun tryJetpackLogin() {
val isAlreadyLoggedIn = accountStore.accessToken.isNotEmpty()
val isFirstTry = appPrefsWrapper.getIsFirstTrySharedLoginJetpack()
val isFeatureFlagEnabled = jetpackSharedLoginFlag.isEnabled()
if (isAlreadyLoggedIn || !isFirstTry || !isFeatureFlagEnabled) {
if (!isFeatureFlagEnabled) {
return
}
val isAlreadyLoggedIn = accountStore.hasAccessToken()
val isFirstTry = appPrefsWrapper.getIsFirstTrySharedLoginJetpack()
if (isAlreadyLoggedIn || !isFirstTry) {
return
}
sharedLoginAnalyticsTracker.trackLoginStart()
Original file line number Diff line number Diff line change
@@ -71,7 +71,7 @@ class SharedLoginResolverTest {
@Test
fun `Should NOT query ContentResolver if feature flag is DISABLED`() {
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(true)
whenever(accountStore.accessToken).thenReturn(notLoggedInToken)
whenever(accountStore.hasAccessToken()).thenReturn(false)
whenever(jetpackSharedLoginFlag.isEnabled()).thenReturn(false)
classToTest.tryJetpackLogin()
verify(contentResolverWrapper, never()).queryUri(contentResolver, uriValue)
@@ -80,7 +80,7 @@ class SharedLoginResolverTest {
@Test
fun `Should NOT query ContentResolver if IS already logged in`() {
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(true)
whenever(accountStore.accessToken).thenReturn(loggedInToken)
whenever(accountStore.hasAccessToken()).thenReturn(true)
whenever(jetpackSharedLoginFlag.isEnabled()).thenReturn(true)
classToTest.tryJetpackLogin()
verify(contentResolverWrapper, never()).queryUri(contentResolver, uriValue)
@@ -89,7 +89,7 @@ class SharedLoginResolverTest {
@Test
fun `Should NOT query ContentResolver if IS NOT the first try`() {
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(false)
whenever(accountStore.accessToken).thenReturn(notLoggedInToken)
whenever(accountStore.hasAccessToken()).thenReturn(false)
whenever(jetpackSharedLoginFlag.isEnabled()).thenReturn(true)
classToTest.tryJetpackLogin()
verify(contentResolverWrapper, never()).queryUri(contentResolver, uriValue)
@@ -128,7 +128,7 @@ class SharedLoginResolverTest {
@Test
fun `Should NOT track login start if IS already logged in`() {
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(true)
whenever(accountStore.accessToken).thenReturn(loggedInToken)
whenever(accountStore.hasAccessToken()).thenReturn(true)
whenever(jetpackSharedLoginFlag.isEnabled()).thenReturn(true)
classToTest.tryJetpackLogin()
verify(sharedLoginAnalyticsTracker, never()).trackLoginStart()
@@ -137,7 +137,7 @@ class SharedLoginResolverTest {
@Test
fun `Should NOT track login start if feature flag is DISABLED`() {
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(true)
whenever(accountStore.accessToken).thenReturn(notLoggedInToken)
whenever(accountStore.hasAccessToken()).thenReturn(false)
whenever(jetpackSharedLoginFlag.isEnabled()).thenReturn(false)
classToTest.tryJetpackLogin()
verify(sharedLoginAnalyticsTracker, never()).trackLoginStart()
@@ -146,7 +146,7 @@ class SharedLoginResolverTest {
@Test
fun `Should NOT track login start if IS NOT the first try`() {
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(false)
whenever(accountStore.accessToken).thenReturn(notLoggedInToken)
whenever(accountStore.hasAccessToken()).thenReturn(false)
whenever(jetpackSharedLoginFlag.isEnabled()).thenReturn(true)
classToTest.tryJetpackLogin()
verify(sharedLoginAnalyticsTracker, never()).trackLoginStart()
@@ -181,7 +181,7 @@ class SharedLoginResolverTest {

private fun featureEnabled() {
whenever(appPrefsWrapper.getIsFirstTrySharedLoginJetpack()).thenReturn(true)
whenever(accountStore.accessToken).thenReturn(notLoggedInToken)
whenever(accountStore.hasAccessToken()).thenReturn(false)
whenever(jetpackSharedLoginFlag.isEnabled()).thenReturn(true)
}
}

0 comments on commit 15fd77f

Please sign in to comment.