-
Notifications
You must be signed in to change notification settings - Fork 18
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 #102 from /issues/90
Issue #90
- Loading branch information
Showing
13 changed files
with
113 additions
and
56 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
75 changes: 75 additions & 0 deletions
75
GrowthBook/src/androidTest/kotlin/com/sdk/growthbook/DefaultGBNetworkClientTest.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,75 @@ | ||
package com.sdk.growthbook | ||
|
||
import com.sdk.growthbook.network.DefaultGBNetworkClient | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.engine.mock.MockEngine | ||
import org.junit.Test | ||
import io.ktor.client.engine.mock.respond | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.http.headersOf | ||
import io.ktor.http.HttpHeaders | ||
import io.ktor.utils.io.ByteReadChannel | ||
import kotlinx.coroutines.runBlocking | ||
import kotlinx.serialization.SerializationException | ||
import org.junit.Assert.assertTrue | ||
|
||
private const val FEATURES_ENDPOINT = "/api/features/" | ||
|
||
class DefaultGBNetworkClientTest { | ||
private val classUnderTest: DefaultGBNetworkClient | ||
|
||
init { | ||
val mockEngine = MockEngine { | ||
respond( | ||
content = ByteReadChannel("some content"), | ||
status = HttpStatusCode.OK, | ||
headers = headersOf(HttpHeaders.ContentType, "application/json") | ||
) | ||
} | ||
|
||
classUnderTest = DefaultGBNetworkClient( | ||
HttpClient(mockEngine) | ||
) | ||
} | ||
|
||
@Test | ||
fun `test successful get request`() { | ||
var wasOnSuccessCalled = false | ||
|
||
val job = classUnderTest.consumeGETRequest( | ||
request = FEATURES_ENDPOINT, | ||
onSuccess = { _ -> | ||
wasOnSuccessCalled = true | ||
}, | ||
onError = {}, | ||
) | ||
|
||
runBlocking { | ||
job.join() | ||
} | ||
|
||
assertTrue(wasOnSuccessCalled) | ||
} | ||
|
||
@Test | ||
fun `test failed get request`() { | ||
var wasOnErrorCalled = false | ||
|
||
val job = classUnderTest.consumeGETRequest( | ||
request = FEATURES_ENDPOINT, | ||
onSuccess = { | ||
// typically in onSuccess callback JSON is parsed | ||
throw SerializationException() | ||
}, | ||
onError = { | ||
wasOnErrorCalled = true | ||
}, | ||
) | ||
|
||
runBlocking { | ||
job.join() | ||
} | ||
|
||
assertTrue(wasOnErrorCalled) | ||
} | ||
} |
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
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
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
Oops, something went wrong.