You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EventUtilsTest.kt 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. package com.dmdirc.ktirc.events
  2. import com.dmdirc.ktirc.IrcClient
  3. import com.dmdirc.ktirc.TestConstants
  4. import com.dmdirc.ktirc.io.CaseMapping
  5. import com.dmdirc.ktirc.model.ModePrefixMapping
  6. import com.dmdirc.ktirc.model.ServerFeature
  7. import com.dmdirc.ktirc.model.ServerState
  8. import com.dmdirc.ktirc.model.User
  9. import com.nhaarman.mockitokotlin2.doReturn
  10. import com.nhaarman.mockitokotlin2.mock
  11. import com.nhaarman.mockitokotlin2.verify
  12. import org.junit.jupiter.api.Assertions.assertEquals
  13. import org.junit.jupiter.api.BeforeEach
  14. import org.junit.jupiter.api.Test
  15. internal class EventUtilsTest {
  16. private val serverState = ServerState("", "")
  17. private val ircClient = mock<IrcClient> {
  18. on { serverState } doReturn serverState
  19. on { caseMapping } doReturn CaseMapping.Ascii
  20. }
  21. @BeforeEach
  22. fun setUp() {
  23. serverState.features[ServerFeature.ModePrefixes] = ModePrefixMapping("ov", "@+")
  24. }
  25. @Test
  26. fun `ChannelNamesReceived#toModesAndUsers parses nicknames and mode prefixes`() {
  27. val event = ChannelNamesReceived(TestConstants.time, "#thegibson", listOf(
  28. "@+acidBurn", "@zeroCool", "thePlague"
  29. ))
  30. val result = event.toModesAndUsers(ircClient)
  31. assertEquals(3, result.size)
  32. assertEquals("ov", result[0].first)
  33. assertEquals("acidBurn", result[0].second.nickname)
  34. assertEquals("o", result[1].first)
  35. assertEquals("zeroCool", result[1].second.nickname)
  36. assertEquals("", result[2].first)
  37. assertEquals("thePlague", result[2].second.nickname)
  38. }
  39. @Test
  40. fun `ChannelNamesReceived#toModesAndUsers parses extended joins with prefixes`() {
  41. val event = ChannelNamesReceived(TestConstants.time, "#thegibson", listOf(
  42. "@+acidBurn!libby@root.localhost", "zeroCool!dade@root.localhost"
  43. ))
  44. val result = event.toModesAndUsers(ircClient)
  45. assertEquals(2, result.size)
  46. assertEquals("ov", result[0].first)
  47. assertEquals("acidBurn", result[0].second.nickname)
  48. assertEquals("libby", result[0].second.ident)
  49. assertEquals("root.localhost", result[0].second.hostname)
  50. assertEquals("", result[1].first)
  51. assertEquals("zeroCool", result[1].second.nickname)
  52. assertEquals("dade", result[1].second.ident)
  53. assertEquals("root.localhost", result[1].second.hostname)
  54. }
  55. @Test
  56. fun `reply sends response to user when message is private`() {
  57. serverState.localNickname = "zeroCool"
  58. val message = MessageReceived(TestConstants.time, User("acidBurn"), "Zerocool", "Hack the planet!")
  59. ircClient.reply(message, "OK")
  60. verify(ircClient).send("PRIVMSG acidBurn :OK")
  61. }
  62. @Test
  63. fun `reply sends unprefixed response to user when message is in a channel`() {
  64. val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!")
  65. ircClient.reply(message, "OK")
  66. verify(ircClient).send("PRIVMSG #TheGibson :OK")
  67. }
  68. @Test
  69. fun `reply sends prefixed response to user when message is in a channel`() {
  70. val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!")
  71. ircClient.reply(message, "OK", prefixWithNickname = true)
  72. verify(ircClient).send("PRIVMSG #TheGibson :acidBurn: OK")
  73. }
  74. @Test
  75. fun `reply sends response with message ID to user when message is private`() {
  76. serverState.localNickname = "zeroCool"
  77. val message = MessageReceived(TestConstants.time, User("acidBurn"), "Zerocool", "Hack the planet!", "abc123")
  78. ircClient.reply(message, "OK")
  79. verify(ircClient).send("@+draft/reply=abc123 PRIVMSG acidBurn :OK")
  80. }
  81. @Test
  82. fun `reply sends unprefixed response with message ID to user when message is in a channel`() {
  83. val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!", "abc123")
  84. ircClient.reply(message, "OK")
  85. verify(ircClient).send("@+draft/reply=abc123 PRIVMSG #TheGibson :OK")
  86. }
  87. @Test
  88. fun `reply sends prefixed response with message ID to user when message is in a channel`() {
  89. val message = MessageReceived(TestConstants.time, User("acidBurn"), "#TheGibson", "Hack the planet!", "abc123")
  90. ircClient.reply(message, "OK", prefixWithNickname = true)
  91. verify(ircClient).send("@+draft/reply=abc123 PRIVMSG #TheGibson :acidBurn: OK")
  92. }
  93. }