Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,8 @@ class ActivityLogRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand All @@ -612,7 +613,8 @@ class ActivityLogRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
return response
Expand Down Expand Up @@ -698,7 +700,8 @@ class ActivityLogRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
return response
Expand All @@ -717,7 +720,8 @@ class ActivityLogRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ class BloggingPromptsRestClientTest {
eq(BloggingPromptsListResponseTypeToken.type),
eq(false),
any(),
eq(false)
eq(false),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,8 @@ class CommentsRestClientTest {
any(),
any(),
any(),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,8 @@ class CardsRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ class ExperimentRestClientTest {
eq(false),
any(),
eq(true),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ class FeatureFlagsRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class RemoteConfigRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class PlanOffersRestClientTest {
eq(false),
any(),
eq(true),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class ProductsRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,8 @@ class ScanRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down Expand Up @@ -508,7 +509,8 @@ class ScanRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.Mockito.mockStatic
import org.mockito.junit.MockitoJUnitRunner
import org.mockito.kotlin.KArgumentCaptor
import org.mockito.kotlin.any
Expand All @@ -34,12 +35,15 @@ import org.wordpress.android.fluxc.network.rest.wpcom.site.SiteWPComRestResponse
import org.wordpress.android.fluxc.network.rest.wpcom.site.StatusType.ERROR
import org.wordpress.android.fluxc.network.rest.wpcom.site.StatusType.SUCCESS
import org.wordpress.android.fluxc.store.SiteStore.PostFormatsErrorType
import org.wordpress.android.fluxc.store.SiteStore.SiteErrorType
import org.wordpress.android.fluxc.store.SiteStore.SiteFilter.WPCOM
import org.wordpress.android.fluxc.store.SiteStore.SiteVisibility
import org.wordpress.android.fluxc.store.SiteStore.SiteVisibility.COMING_SOON
import org.wordpress.android.fluxc.store.SiteStore.SiteVisibility.PUBLIC
import org.wordpress.android.fluxc.test
import org.wordpress.android.fluxc.tools.initCoroutineEngine
import org.wordpress.android.util.DateTimeUtils
import org.wordpress.android.util.UrlUtils
import kotlin.test.assertNotNull

@RunWith(MockitoJUnitRunner::class)
Expand All @@ -63,13 +67,14 @@ class SiteRestClientTest {
paramsCaptor = argumentCaptor()
bodyCaptor = argumentCaptor()
restClient = SiteRestClient(
null,
dispatcher,
requestQueue,
appSecrets,
wpComGsonRequestBuilder,
accessToken,
userAgent
appContext = null,
dispatcher = dispatcher,
requestQueue = requestQueue,
appSecrets = appSecrets,
wpComGsonRequestBuilder = wpComGsonRequestBuilder,
coroutineEngine = initCoroutineEngine(),
accessToken = accessToken,
userAgent = userAgent
)
whenever(site.siteId).thenReturn(siteId)
}
Expand Down Expand Up @@ -610,6 +615,22 @@ class SiteRestClientTest {
}
}

@Test
fun `given a suspended WPCom website, when fetching site info, then return correct error`() = test {
val urlUtilsMock = mockStatic(UrlUtils::class.java)
whenever(UrlUtils.addUrlSchemeIfNeeded(any(), any())).thenAnswer { it.arguments[0] as String }
val error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.INVALID_RESPONSE, "")).apply {
apiError = "connection_disabled"
}
initGetResponse(ConnectSiteInfoResponse::class.java, null, error)

val result = restClient.fetchConnectSiteInfoSync("test.com")

assertThat(result.error).isNotNull
assertThat(result.error!!.type).isEqualTo(SiteErrorType.WPCOM_SITE_SUSPENDED)
urlUtilsMock.close()
}

private suspend fun initSiteResponse(
data: SiteWPComRestResponse? = null,
error: WPComGsonNetworkError? = null
Expand Down Expand Up @@ -654,10 +675,13 @@ class SiteRestClientTest {

private suspend fun <T> initGetResponse(
clazz: Class<T>,
data: T,
data: T?,
error: WPComGsonNetworkError? = null
): Response<T> {
val response = if (error != null) Response.Error(error) else Success(data)
if (error == null && data == null) {
error("Either data or error must be provided")
}
val response = if (error != null) Response.Error(error) else Success<T>(data!!)
whenever(
wpComGsonRequestBuilder.syncGetRequest(
eq(restClient),
Expand All @@ -667,8 +691,8 @@ class SiteRestClientTest {
any(),
any(),
any(),
customGsonBuilder = anyOrNull()

customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
return response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,8 @@ class InsightsRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ class MostPopularRestClientTest {
eq(true),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ class PostingActivityRestClientTest {
eq(true),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ class SummaryRestClientTest {
eq(false),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ class SubscribersRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ class AuthorsRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ class ClicksRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ class CountryViewsRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ class FileDownloadsRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ class PostAndPageViewsRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,8 @@ class ReferrersRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ class SearchTermsRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ class VideoPlaysRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ class VisitAndViewsRestClientTest {
eq(cachingEnabled),
any(),
eq(false),
customGsonBuilder = anyOrNull()
customGsonBuilder = anyOrNull(),
authenticatedRequest = any()
)
).thenReturn(response)
whenever(site.siteId).thenReturn(siteId)
Expand Down
Loading
Loading