@@ -21,6 +21,7 @@ import io.getstream.chat.android.client.parser2.ParserFactory
21
21
import io.getstream.chat.android.client.token.FakeTokenManager
22
22
import io.getstream.chat.android.client.utils.HeadersUtil
23
23
import io.getstream.chat.android.models.User
24
+ import io.getstream.chat.android.randomBoolean
24
25
import io.getstream.chat.android.randomString
25
26
import io.getstream.chat.android.randomUser
26
27
import okhttp3.OkHttpClient
@@ -45,17 +46,18 @@ internal class SocketFactoryTest {
45
46
whenever(this .newWebSocket(any(), any())) doReturn mock()
46
47
}
47
48
48
- private val socketFactory = SocketFactory (
49
- chatParser,
50
- FakeTokenManager (token, loadSyncToken),
51
- headersUtil,
52
- httpClient,
53
- )
54
-
55
49
/* * [arguments] */
56
50
@ParameterizedTest
57
51
@MethodSource(" arguments" )
58
- internal fun testCreateSocket (connectionConf : SocketFactory .ConnectionConf , expectedUrl : String ) {
52
+ internal fun testCreateSocket (
53
+ expireToken : Boolean ,
54
+ connectionConf : SocketFactory .ConnectionConf ,
55
+ expectedUrl : String ,
56
+ ) {
57
+ val socketFactory = Fixture (httpClient)
58
+ .withExpire(expireToken)
59
+ .get()
60
+
59
61
socketFactory.createSocket(connectionConf)
60
62
61
63
verify(httpClient, only()).newWebSocket(
@@ -66,6 +68,21 @@ internal class SocketFactoryTest {
66
68
)
67
69
}
68
70
71
+ private class Fixture (val httpClient : OkHttpClient ) {
72
+ private val tokenManager = FakeTokenManager (token, loadSyncToken)
73
+
74
+ fun withExpire (expire : Boolean ): Fixture = apply {
75
+ tokenManager.takeIf { expire }?.expireToken()
76
+ }
77
+
78
+ fun get () = SocketFactory (
79
+ chatParser,
80
+ tokenManager,
81
+ headersUtil,
82
+ httpClient,
83
+ )
84
+ }
85
+
69
86
companion object {
70
87
private val chatParser: ChatParser = ParserFactory .createMoshiChatParser()
71
88
private val endpoint = " https://${randomString().lowercase(Locale .getDefault())} /"
@@ -81,24 +98,42 @@ internal class SocketFactoryTest {
81
98
fun arguments () = listOf (
82
99
randomUser(image = randomString(), name = randomString(), language = randomString()).let {
83
100
Arguments .of(
101
+ false ,
84
102
SocketFactory .ConnectionConf .UserConnectionConf (endpoint, apiKey, it),
85
103
" ${endpoint} connect?json=${buildFullUserJson(it, it.id)} &api_key=$apiKey &X-Stream-Client=${headersUtil.buildSdkTrackingHeaders()} &authorization=$token &stream-auth-type=jwt" ,
86
104
)
87
105
},
88
106
randomUser().let {
89
107
Arguments .of(
108
+ false ,
109
+ SocketFactory .ConnectionConf .UserConnectionConf (endpoint, apiKey, it).asReconnectionConf(),
110
+ " ${endpoint} connect?json=${buildMinimumUserJson(it.id)} &api_key=$apiKey &X-Stream-Client=${headersUtil.buildSdkTrackingHeaders()} &authorization=$token &stream-auth-type=jwt" ,
111
+ )
112
+ },
113
+ randomUser(image = randomString(), name = randomString(), language = randomString()).let {
114
+ Arguments .of(
115
+ true ,
116
+ SocketFactory .ConnectionConf .UserConnectionConf (endpoint, apiKey, it),
117
+ " ${endpoint} connect?json=${buildFullUserJson(it, it.id)} &api_key=$apiKey &X-Stream-Client=${headersUtil.buildSdkTrackingHeaders()} &authorization=$loadSyncToken &stream-auth-type=jwt" ,
118
+ )
119
+ },
120
+ randomUser().let {
121
+ Arguments .of(
122
+ true ,
90
123
SocketFactory .ConnectionConf .UserConnectionConf (endpoint, apiKey, it).asReconnectionConf(),
91
124
" ${endpoint} connect?json=${buildMinimumUserJson(it.id)} &api_key=$apiKey &X-Stream-Client=${headersUtil.buildSdkTrackingHeaders()} &authorization=$loadSyncToken &stream-auth-type=jwt" ,
92
125
)
93
126
},
94
127
User (" anon" ).let {
95
128
Arguments .of(
129
+ randomBoolean(),
96
130
SocketFactory .ConnectionConf .AnonymousConnectionConf (endpoint, apiKey, it).asReconnectionConf(),
97
131
" ${endpoint} connect?json=${buildMinimumUserJson(it.id)} &api_key=$apiKey &X-Stream-Client=${headersUtil.buildSdkTrackingHeaders()} &stream-auth-type=anonymous" ,
98
132
)
99
133
},
100
134
User (" !anon" ).let {
101
135
Arguments .of(
136
+ randomBoolean(),
102
137
SocketFactory .ConnectionConf .AnonymousConnectionConf (endpoint, apiKey, it).asReconnectionConf(),
103
138
" ${endpoint} connect?json=${buildMinimumUserJson(" anon" )} &api_key=$apiKey &X-Stream-Client=${headersUtil.buildSdkTrackingHeaders()} &stream-auth-type=anonymous" ,
104
139
)
0 commit comments