Fix receivers of ConversationMessageReceivedEvent

These were only listening to private message events, ignoring all others
This commit is contained in:
Torsten Grote
2018-11-07 11:31:50 -03:00
parent cccaeeda6c
commit f964d1ef07
12 changed files with 117 additions and 34 deletions

View File

@@ -3,13 +3,20 @@ package org.briarproject.briar.headless.event
import io.javalin.json.JavalinJson.toJson
import io.javalin.websocket.WsSession
import io.mockk.*
import org.briarproject.bramble.api.identity.AuthorInfo
import org.briarproject.bramble.api.identity.AuthorInfo.Status.VERIFIED
import org.briarproject.bramble.test.ImmediateExecutor
import org.briarproject.bramble.test.TestUtils.getRandomId
import org.briarproject.briar.api.client.SessionId
import org.briarproject.briar.api.introduction.IntroductionRequest
import org.briarproject.briar.api.introduction.event.IntroductionRequestReceivedEvent
import org.briarproject.briar.api.messaging.PrivateMessageHeader
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
import org.briarproject.briar.headless.ControllerTest
import org.briarproject.briar.headless.messaging.EVENT_PRIVATE_MESSAGE
import org.briarproject.briar.headless.messaging.EVENT_CONVERSATION_MESSAGE
import org.briarproject.briar.headless.messaging.output
import org.eclipse.jetty.websocket.api.WebSocketException
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import java.io.IOException
@@ -23,7 +30,7 @@ internal class WebSocketControllerTest : ControllerTest() {
private val header =
PrivateMessageHeader(message.id, group.id, timestamp, true, true, true, true, emptyList())
private val event = PrivateMessageReceivedEvent(header, contact.id)
private val outputEvent = OutputEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
private val outputEvent = OutputEvent(EVENT_CONVERSATION_MESSAGE, event.output(text))
@Test
fun testSendEvent() {
@@ -32,7 +39,7 @@ internal class WebSocketControllerTest : ControllerTest() {
every { session1.send(capture(slot)) } just Runs
controller.sessions.add(session1)
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
controller.sendEvent(EVENT_CONVERSATION_MESSAGE, event.output(text))
assertJsonEquals(slot.captured, outputEvent)
}
@@ -55,13 +62,45 @@ internal class WebSocketControllerTest : ControllerTest() {
controller.sessions.add(session1)
controller.sessions.add(session2)
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
controller.sendEvent(EVENT_CONVERSATION_MESSAGE, event.output(text))
verify { session2.send(slot.captured) }
}
@Test
fun testOutputPrivateMessageReceivedEvent() {
fun testIntroductionRequestEvent() {
val sessionId = SessionId(getRandomId())
val authorInfo = AuthorInfo(VERIFIED)
val introductionRequest = IntroductionRequest(
message.id,
group.id,
timestamp,
true,
true,
true,
true,
sessionId,
author,
text,
false,
authorInfo
)
val introductionRequestEvent =
IntroductionRequestReceivedEvent(introductionRequest, contact.id)
val introductionOutputEvent =
OutputEvent(EVENT_CONVERSATION_MESSAGE, introductionRequestEvent.output())
val slot = CapturingSlot<String>()
every { session1.send(capture(slot)) } just Runs
controller.sessions.add(session1)
controller.sendEvent(EVENT_CONVERSATION_MESSAGE, introductionRequestEvent.output())
assertJsonEquals(slot.captured, introductionOutputEvent)
assertEquals("IntroductionRequest", introductionRequestEvent.output()["type"])
}
@Test
fun testOutputConversationMessageReceivedEvent() {
val json = """
{
"type": "event",

View File

@@ -161,7 +161,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
val event = PrivateMessageReceivedEvent(header, contact.id)
every { messagingManager.getMessageText(message.id) } returns text
every { webSocketController.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text)) } just runs
every { webSocketController.sendEvent(EVENT_CONVERSATION_MESSAGE, event.output(text)) } just runs
controller.eventOccurred(event)
}