-
Notifications
You must be signed in to change notification settings - Fork 130
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 #13308 from woocommerce/issue/3974-remove-xmlrpc-a…
…ccount-mismatch [Login] Remove dependency on XMLRPC for the Account Mismatch flow
- Loading branch information
Showing
4 changed files
with
161 additions
and
132 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
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
108 changes: 108 additions & 0 deletions
108
.../kotlin/com/woocommerce/android/ui/login/accountmismatch/AccountMismatchRepositoryTest.kt
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,108 @@ | ||
package com.woocommerce.android.ui.login.accountmismatch | ||
|
||
import com.woocommerce.android.FakeDispatcher | ||
import com.woocommerce.android.ui.login.WPApiSiteRepository | ||
import com.woocommerce.android.viewmodel.BaseUnitTest | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.eq | ||
import org.mockito.kotlin.mock | ||
import org.mockito.kotlin.whenever | ||
import org.wordpress.android.fluxc.model.SiteModel | ||
import org.wordpress.android.fluxc.model.jetpack.JetpackUser | ||
import org.wordpress.android.fluxc.store.JetpackStore | ||
import org.wordpress.android.fluxc.store.SiteStore | ||
|
||
@OptIn(ExperimentalCoroutinesApi::class) | ||
class AccountMismatchRepositoryTest : BaseUnitTest() { | ||
private val jetpackStore = mock<JetpackStore>() | ||
private val siteStore = mock<SiteStore>() | ||
private val wpApiSiteRepository = mock<WPApiSiteRepository> { | ||
onBlocking { fetchSite(any(), any(), any()) }.thenReturn(Result.success(SiteModel())) | ||
} | ||
private val dispatcher = FakeDispatcher() | ||
|
||
private val sut = AccountMismatchRepository( | ||
jetpackStore = jetpackStore, | ||
siteStore = siteStore, | ||
wpApiSiteRepository = wpApiSiteRepository, | ||
dispatcher = dispatcher | ||
) | ||
|
||
@Test | ||
fun `given a non-connected Jetpack Account, when fetching status, then return correct status`() = testBlocking { | ||
whenever(jetpackStore.fetchJetpackUser(any(), eq(false))) | ||
.thenReturn(JetpackStore.JetpackUserResult(createJetpackUser(isConnected = false))) | ||
|
||
val result = sut.checkJetpackConnection( | ||
siteUrl = "https://example.com", | ||
username = "username", | ||
password = "password" | ||
) | ||
|
||
assertThat(result.getOrNull()).isEqualTo(AccountMismatchRepository.JetpackConnectionStatus.NotConnected) | ||
} | ||
|
||
@Test | ||
fun `given a null jetpack user, when fetching connection status, then assume non-connected`() = testBlocking { | ||
whenever(jetpackStore.fetchJetpackUser(any(), eq(false))) | ||
.thenReturn(JetpackStore.JetpackUserResult(null)) | ||
|
||
val result = sut.checkJetpackConnection( | ||
siteUrl = "https://example.com", | ||
username = "username", | ||
password = "password" | ||
) | ||
|
||
assertThat(result.getOrNull()).isEqualTo(AccountMismatchRepository.JetpackConnectionStatus.NotConnected) | ||
} | ||
|
||
@Test | ||
fun `given a connected Jetpack Account, when fetching status, then return correct status`() = testBlocking { | ||
whenever(jetpackStore.fetchJetpackUser(any(), eq(false))) | ||
.thenReturn(JetpackStore.JetpackUserResult(createJetpackUser(isConnected = true, wpcomEmail = "email"))) | ||
|
||
val result = sut.checkJetpackConnection( | ||
siteUrl = "https://example.com", | ||
username = "username", | ||
password = "password" | ||
) | ||
|
||
assertThat(result.getOrNull()) | ||
.isEqualTo(AccountMismatchRepository.JetpackConnectionStatus.ConnectedToDifferentAccount("email")) | ||
} | ||
|
||
@Test | ||
fun `given a correctly connected Jetpack account, when fetching email, then return it`() = testBlocking { | ||
whenever(jetpackStore.fetchJetpackUser(any(), eq(false))) | ||
.thenReturn(JetpackStore.JetpackUserResult(createJetpackUser(isConnected = true, wpcomEmail = "email"))) | ||
|
||
val result = sut.fetchJetpackConnectedEmail(SiteModel()) | ||
|
||
assertThat(result.getOrNull()).isEqualTo("email") | ||
} | ||
|
||
@Test | ||
fun `given an issue with Jetpack account, when fetching email, then return error`() = testBlocking { | ||
whenever(jetpackStore.fetchJetpackUser(any(), eq(false))) | ||
.thenReturn(JetpackStore.JetpackUserResult(createJetpackUser(isConnected = true, wpcomEmail = ""))) | ||
|
||
val result = sut.fetchJetpackConnectedEmail(SiteModel()) | ||
|
||
assertThat(result.isFailure).isTrue() | ||
} | ||
|
||
private fun createJetpackUser( | ||
isConnected: Boolean = false, | ||
wpcomEmail: String = "" | ||
) = JetpackUser( | ||
isConnected = isConnected, | ||
wpcomEmail = wpcomEmail, | ||
isMaster = false, | ||
username = "username", | ||
wpcomId = 1L, | ||
wpcomUsername = "wpcomUsername" | ||
) | ||
} |