Skip to content

Commit 90c3538

Browse files
add tests
1 parent 2c86894 commit 90c3538

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package io.getstream.android.core.api.model.config
2+
3+
import io.getstream.android.core.api.model.event.StreamClientWsEvent
4+
import io.getstream.android.core.api.serialization.StreamEventSerialization
5+
import io.getstream.android.core.api.serialization.StreamJsonSerialization
6+
import kotlin.test.Test
7+
import kotlin.test.assertEquals
8+
import kotlin.test.assertNull
9+
import kotlin.test.assertSame
10+
11+
class StreamClientSerializationConfigTest {
12+
13+
@Test
14+
fun `json builder injects json implementation`() {
15+
val json = FakeJsonSerialization()
16+
val productEvents = FakeEventSerialization<Any>()
17+
val alsoExternal = setOf("custom:event")
18+
19+
val config = StreamClientSerializationConfig.json(json, productEvents, alsoExternal)
20+
21+
assertSame(json, config.json)
22+
assertNull(config.eventParser)
23+
assertSame(productEvents, config.productEventSerializers)
24+
assertEquals(alsoExternal, config.alsoExternal)
25+
}
26+
27+
@Test
28+
fun `event builder injects event parser`() {
29+
val eventParser = FakeEventSerialization<StreamClientWsEvent>()
30+
val productEvents = FakeEventSerialization<Any>()
31+
val alsoExternal = setOf("product:event")
32+
33+
val config = StreamClientSerializationConfig.event(eventParser, productEvents, alsoExternal)
34+
35+
assertSame(eventParser, config.eventParser)
36+
assertNull(config.json)
37+
assertSame(productEvents, config.productEventSerializers)
38+
assertEquals(alsoExternal, config.alsoExternal)
39+
}
40+
41+
private class FakeJsonSerialization : StreamJsonSerialization {
42+
override fun toJson(any: Any): Result<String> = Result.success("{}")
43+
44+
override fun <T : Any> fromJson(raw: String, clazz: Class<T>): Result<T> =
45+
Result.failure(UnsupportedOperationException())
46+
}
47+
48+
private class FakeEventSerialization<T> : StreamEventSerialization<T> {
49+
override fun serialize(data: T): Result<String> = Result.success("event")
50+
51+
override fun deserialize(raw: String): Result<T> =
52+
Result.failure(UnsupportedOperationException())
53+
}
54+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package io.getstream.android.core.api.model.config
2+
3+
import io.getstream.android.core.api.model.value.StreamApiKey
4+
import io.getstream.android.core.api.model.value.StreamHttpClientInfoHeader
5+
import kotlin.test.Test
6+
import kotlin.test.assertEquals
7+
import kotlin.test.assertFailsWith
8+
import kotlin.test.assertSame
9+
10+
class StreamSocketConfigTest {
11+
12+
private val apiKey = StreamApiKey.fromString("key")
13+
private val header = StreamHttpClientInfoHeader.create("product", "1.0", "android", 34, "pixel")
14+
15+
@Test
16+
fun `anonymous config uses anonymous auth type`() {
17+
val config = StreamSocketConfig.anonymous(
18+
url = "wss://chat.stream.io",
19+
apiKey = apiKey,
20+
clientInfoHeader = header,
21+
)
22+
23+
assertEquals("wss://chat.stream.io", config.url)
24+
assertEquals(apiKey, config.apiKey)
25+
assertEquals("anonymous", config.authType)
26+
assertEquals(header, config.clientInfoHeader)
27+
}
28+
29+
@Test
30+
fun `custom config uses provided auth type and validates input`() {
31+
val config =
32+
StreamSocketConfig.custom(
33+
url = "wss://chat.stream.io/custom",
34+
apiKey = apiKey,
35+
authType = "token",
36+
clientInfoHeader = header,
37+
)
38+
39+
assertEquals("token", config.authType)
40+
41+
assertFailsWith<IllegalArgumentException> {
42+
StreamSocketConfig.custom("", apiKey, "jwt", header)
43+
}
44+
assertFailsWith<IllegalArgumentException> {
45+
StreamSocketConfig.custom("wss://chat.stream.io", apiKey, "", header)
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)