|
@@ -9,6 +9,7 @@ import com.dmdirc.ktirc.util.currentTimeProvider
|
9
|
9
|
import com.dmdirc.ktirc.util.generateLabel
|
10
|
10
|
import com.nhaarman.mockitokotlin2.*
|
11
|
11
|
import io.ktor.util.KtorExperimentalAPI
|
|
12
|
+import io.mockk.*
|
12
|
13
|
import kotlinx.coroutines.*
|
13
|
14
|
import kotlinx.coroutines.channels.Channel
|
14
|
15
|
import kotlinx.coroutines.channels.filter
|
|
@@ -55,10 +56,12 @@ internal class IrcClientImplTest {
|
55
|
56
|
username = USER_NAME
|
56
|
57
|
}
|
57
|
58
|
|
58
|
|
- private val normalConfig = IrcClientConfig(ServerConfig().apply {
|
|
59
|
+ private val serverConfig = ServerConfig().apply {
|
59
|
60
|
host = HOST
|
60
|
61
|
port = PORT
|
61
|
|
- }, profileConfig, BehaviourConfig(), null)
|
|
62
|
+ }
|
|
63
|
+
|
|
64
|
+ private val normalConfig = IrcClientConfig(serverConfig, profileConfig, BehaviourConfig(), null)
|
62
|
65
|
|
63
|
66
|
@BeforeEach
|
64
|
67
|
fun setUp() {
|
|
@@ -190,6 +193,7 @@ internal class IrcClientImplTest {
|
190
|
193
|
}
|
191
|
194
|
|
192
|
195
|
@Test
|
|
196
|
+ @SuppressWarnings("deprecation")
|
193
|
197
|
fun `sends text to socket`() = runBlocking {
|
194
|
198
|
val client = IrcClientImpl(normalConfig)
|
195
|
199
|
client.socketFactory = mockSocketFactory
|
|
@@ -211,6 +215,56 @@ internal class IrcClientImplTest {
|
211
|
215
|
assertLineReceived("testing 123 456")
|
212
|
216
|
}
|
213
|
217
|
|
|
218
|
+ @Test
|
|
219
|
+ fun `echoes message event when behaviour is set and cap is unsupported`() = runBlocking {
|
|
220
|
+ val config = IrcClientConfig(serverConfig, profileConfig, BehaviourConfig().apply { alwaysEchoMessages = true }, null)
|
|
221
|
+ val client = IrcClientImpl(config)
|
|
222
|
+ client.socketFactory = mockSocketFactory
|
|
223
|
+
|
|
224
|
+ val slot = slot<MessageReceived>()
|
|
225
|
+ val mockkEventHandler = mockk<(IrcEvent) -> Unit>(relaxed = true)
|
|
226
|
+ every { mockkEventHandler(capture(slot)) } just Runs
|
|
227
|
+
|
|
228
|
+ client.onEvent(mockkEventHandler)
|
|
229
|
+ client.connect()
|
|
230
|
+
|
|
231
|
+ client.send("PRIVMSG", "#thegibson", "Mess with the best, die like the rest")
|
|
232
|
+
|
|
233
|
+ assertTrue(slot.isCaptured)
|
|
234
|
+ val event = slot.captured
|
|
235
|
+ assertEquals("#thegibson", event.target)
|
|
236
|
+ assertEquals("Mess with the best, die like the rest", event.message)
|
|
237
|
+ assertEquals(NICK, event.user.nickname)
|
|
238
|
+ assertEquals(TestConstants.time, event.metadata.time)
|
|
239
|
+ }
|
|
240
|
+
|
|
241
|
+ @Test
|
|
242
|
+ fun `does not echo message event when behaviour is set and cap is supported`() = runBlocking {
|
|
243
|
+ val config = IrcClientConfig(serverConfig, profileConfig, BehaviourConfig().apply { alwaysEchoMessages = true }, null)
|
|
244
|
+ val client = IrcClientImpl(config)
|
|
245
|
+ client.socketFactory = mockSocketFactory
|
|
246
|
+ client.serverState.capabilities.enabledCapabilities[Capability.EchoMessages] = ""
|
|
247
|
+ client.connect()
|
|
248
|
+
|
|
249
|
+ client.onEvent(mockEventHandler)
|
|
250
|
+ client.send("PRIVMSG", "#thegibson", "Mess with the best, die like the rest")
|
|
251
|
+
|
|
252
|
+ verify(mockEventHandler, never()).invoke(isA<MessageReceived>())
|
|
253
|
+ }
|
|
254
|
+
|
|
255
|
+ @Test
|
|
256
|
+ fun `does not echo message event when behaviour is unset`() = runBlocking {
|
|
257
|
+ val config = IrcClientConfig(serverConfig, profileConfig, BehaviourConfig().apply { alwaysEchoMessages = false }, null)
|
|
258
|
+ val client = IrcClientImpl(config)
|
|
259
|
+ client.socketFactory = mockSocketFactory
|
|
260
|
+ client.connect()
|
|
261
|
+
|
|
262
|
+ client.onEvent(mockEventHandler)
|
|
263
|
+ client.send("PRIVMSG", "#thegibson", "Mess with the best, die like the rest")
|
|
264
|
+
|
|
265
|
+ verify(mockEventHandler, never()).invoke(isA<MessageReceived>())
|
|
266
|
+ }
|
|
267
|
+
|
214
|
268
|
@Test
|
215
|
269
|
fun `sends structured text to socket with tags`() = runBlocking {
|
216
|
270
|
val client = IrcClientImpl(normalConfig)
|