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.

MessageBuildersTest.kt 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package com.dmdirc.ktirc.messages
  2. import com.dmdirc.ktirc.IrcClient
  3. import com.dmdirc.ktirc.model.MessageTag
  4. import io.mockk.mockk
  5. import io.mockk.verify
  6. import org.junit.jupiter.api.Test
  7. internal class MessageBuildersTest {
  8. private val mockClient = mockk<IrcClient>()
  9. @Test
  10. fun `sendCapabilityRequest sends CAP REQ message with single argument`() {
  11. mockClient.sendCapabilityRequest(listOf("a"))
  12. verify { mockClient.send("CAP", "REQ", "a") }
  13. }
  14. @Test
  15. fun `sendCapabilityRequest sends CAP REQ message with multiple args`() {
  16. mockClient.sendCapabilityRequest(listOf("a b c"))
  17. verify { mockClient.send("CAP", "REQ", "a b c") }
  18. }
  19. @Test
  20. fun `sendJoin sends correct JOIN message`() {
  21. mockClient.sendJoin("#TheGibson")
  22. verify { mockClient.send("JOIN", "#TheGibson") }
  23. }
  24. @Test
  25. fun `sendPart sends correct PART message without reason`() {
  26. mockClient.sendPart("#TheGibson")
  27. verify { mockClient.send("PART", "#TheGibson") }
  28. }
  29. @Test
  30. fun `sendPart sends correct PART message with reason`() {
  31. mockClient.sendPart("#TheGibson", "Mess with the best...")
  32. verify { mockClient.send("PART", "#TheGibson", "Mess with the best...") }
  33. }
  34. @Test
  35. fun `sendModeRequest sends correct MODE message`() {
  36. mockClient.sendModeRequest("#TheGibson")
  37. verify { mockClient.send("MODE", "#TheGibson") }
  38. }
  39. @Test
  40. fun `sendNickChange sends correct NICK message`() {
  41. mockClient.sendNickChange("AcidBurn")
  42. verify { mockClient.send("NICK", "AcidBurn") }
  43. }
  44. @Test
  45. fun `sendAway sends blank AWAY message with no args`() {
  46. mockClient.sendAway()
  47. verify { mockClient.send(emptyMap(), "AWAY") }
  48. }
  49. @Test
  50. fun `sendAway sends AWAY message with reason`() {
  51. mockClient.sendAway("Hacking the planet")
  52. verify { mockClient.send("AWAY", "Hacking the planet") }
  53. }
  54. @Test
  55. fun `sendPassword sends correct PASS message`() {
  56. mockClient.sendPassword("hacktheplanet")
  57. verify { mockClient.send("PASS", "hacktheplanet") }
  58. }
  59. @Test
  60. fun `sendPong sends correct PONG message`() {
  61. mockClient.sendPong("abcdef".toByteArray())
  62. verify { mockClient.send("PONG", "abcdef") }
  63. }
  64. @Test
  65. fun `sendMessage sends correct PRIVMSG message`() {
  66. mockClient.sendMessage("acidBurn", "Hack the planet!")
  67. verify { mockClient.send(tagMap(), "PRIVMSG", "acidBurn", "Hack the planet!") }
  68. }
  69. @Test
  70. fun `sendMessage sends correct PRIVMSG message with reply to tag`() {
  71. mockClient.sendMessage("acidBurn", "Hack the planet!", "abc123")
  72. verify { mockClient.send(tagMap(MessageTag.Reply to "abc123"), "PRIVMSG", "acidBurn", "Hack the planet!") }
  73. }
  74. @Test
  75. fun `sendCtcp sends correct CTCP message with no arguments`() {
  76. mockClient.sendCtcp("acidBurn", "ping")
  77. verify { mockClient.send(tagMap(), "PRIVMSG", "acidBurn", "\u0001PING\u0001") }
  78. }
  79. @Test
  80. fun `sendCtcp sends correct CTCP message with arguments`() {
  81. mockClient.sendCtcp("acidBurn", "ping", "12345")
  82. verify { mockClient.send(tagMap(), "PRIVMSG", "acidBurn", "\u0001PING 12345\u0001") }
  83. }
  84. @Test
  85. fun `sendAction sends correct action`() {
  86. mockClient.sendAction("acidBurn", "hacks the planet")
  87. verify { mockClient.send(tagMap(), "PRIVMSG", "acidBurn", "\u0001ACTION hacks the planet\u0001") }
  88. }
  89. @Test
  90. fun `sendUser sends correct USER message`() {
  91. mockClient.sendUser("AcidBurn", "Kate")
  92. verify { mockClient.send("USER", "AcidBurn", "0", "*", "Kate") }
  93. }
  94. @Test
  95. fun `sendUser sends correct AUTHENTICATE message`() {
  96. mockClient.sendAuthenticationMessage("SCRAM-MD5")
  97. verify { mockClient.send("AUTHENTICATE", "SCRAM-MD5") }
  98. }
  99. @Test
  100. fun `sendUser sends correct blank AUTHENTICATE message`() {
  101. mockClient.sendAuthenticationMessage()
  102. verify { mockClient.send("AUTHENTICATE", "+") }
  103. }
  104. @Test
  105. fun `sendTagMessage sends tags`() {
  106. val tags = mapOf(MessageTag.MessageId to "id", MessageTag.AccountName to "foo")
  107. mockClient.sendTagMessage("#thegibson", tags)
  108. verify { mockClient.send(tags, "TAGMSG", "#thegibson") }
  109. }
  110. @Test
  111. fun `sendTagMessage sends tags with reply ID`() {
  112. val tags = mapOf(MessageTag.MessageId to "id", MessageTag.AccountName to "foo")
  113. mockClient.sendTagMessage("#thegibson", tags, "otherId")
  114. verify { mockClient.send(tags + (MessageTag.Reply to "otherId"), "TAGMSG", "#thegibson") }
  115. }
  116. }