Skip to content

Commit

Permalink
Adds error test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Antonis Lilis committed Oct 12, 2023
1 parent 0739f39 commit 5bed1ee
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,46 @@ class SiteRestClientTest {
}
}

@Test
fun `given a network error, when all domains are requested, then return api error`() = test {
val error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.NETWORK_ERROR))
initAllDomainsResponse(error = error)

val response = restClient.fetchAllDomains(noWpCom = true)
assert(response is Response.Error)
with((response as Response.Error).error) {
assertThat(type).isEqualTo(GenericErrorType.NETWORK_ERROR)
assertThat(message).isNull()
}
}

@Test
fun `given timeout, when all domains are requested, then return timeout error`() = test {
val error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.TIMEOUT))
initAllDomainsResponse(error = error)

val response = restClient.fetchAllDomains(noWpCom = true)
assert(response is Response.Error)
with((response as Response.Error).error) {
assertThat(type).isEqualTo(GenericErrorType.TIMEOUT)
assertThat(message).isNull()
}
}

@Test
fun `given not authenticated, when all domains are requested, then retun auth required error`() = test {
val tokenErrorMessage = "An active access token must be used to query information about the current user."
val error = WPComGsonNetworkError(BaseNetworkError(GenericErrorType.NOT_AUTHENTICATED, tokenErrorMessage))
initAllDomainsResponse(error = error)

val response = restClient.fetchAllDomains(noWpCom = true)
assert(response is Response.Error)
with((response as Response.Error).error) {
assertThat(type).isEqualTo(GenericErrorType.NOT_AUTHENTICATED)
assertThat(message).isEqualTo(tokenErrorMessage)
}
}

private suspend fun initSiteResponse(
data: SiteWPComRestResponse? = null,
error: WPComGsonNetworkError? = null
Expand Down

0 comments on commit 5bed1ee

Please sign in to comment.