mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Use "text" to refer to message text.
This commit is contained in:
@@ -35,7 +35,7 @@ abstract class ControllerTest {
|
||||
protected val localAuthor: LocalAuthor = getLocalAuthor()
|
||||
protected val contact = Contact(ContactId(1), author, localAuthor.id, true, true)
|
||||
protected val message: Message = getMessage(group.id)
|
||||
protected val body: String = getRandomString(5)
|
||||
protected val text: String = getRandomString(5)
|
||||
protected val timestamp = 42L
|
||||
|
||||
protected fun assertJsonEquals(json: String, obj: Any) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.briarproject.bramble.api.sync.MessageId
|
||||
import org.briarproject.bramble.identity.output
|
||||
import org.briarproject.bramble.util.StringUtils.getRandomString
|
||||
import org.briarproject.briar.api.blog.*
|
||||
import org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_BODY_LENGTH
|
||||
import org.briarproject.briar.api.blog.BlogConstants.MAX_BLOG_POST_TEXT_LENGTH
|
||||
import org.briarproject.briar.api.blog.MessageType.POST
|
||||
import org.briarproject.briar.headless.ControllerTest
|
||||
import org.junit.jupiter.api.Assertions.assertThrows
|
||||
@@ -38,7 +38,7 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
fun testCreate() {
|
||||
val post = BlogPost(message, null, localAuthor)
|
||||
|
||||
every { ctx.body() } returns """{"text": "$body"}"""
|
||||
every { ctx.body() } returns """{"text": "$text"}"""
|
||||
every { identityManager.localAuthor } returns localAuthor
|
||||
every { blogManager.getPersonalBlog(localAuthor) } returns blog
|
||||
every { clock.currentTimeMillis() } returns message.timestamp
|
||||
@@ -48,12 +48,12 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
message.timestamp,
|
||||
parentId,
|
||||
localAuthor,
|
||||
body
|
||||
text
|
||||
)
|
||||
} returns post
|
||||
every { blogManager.addLocalPost(post) } just Runs
|
||||
every { blogManager.getPostHeader(post.message.groupId, post.message.id) } returns header
|
||||
every { ctx.json(header.output(body)) } returns ctx
|
||||
every { ctx.json(header.output(text)) } returns ctx
|
||||
|
||||
controller.createPost(ctx)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
|
||||
@Test
|
||||
fun testCreateTooLongText() {
|
||||
every { ctx.body() } returns """{"text": "${getRandomString(MAX_BLOG_POST_BODY_LENGTH + 1)}"}"""
|
||||
every { ctx.body() } returns """{"text": "${getRandomString(MAX_BLOG_POST_TEXT_LENGTH + 1)}"}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.createPost(ctx) }
|
||||
}
|
||||
@@ -83,8 +83,8 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
fun testList() {
|
||||
every { blogManager.blogs } returns listOf(blog)
|
||||
every { blogManager.getPostHeaders(group.id) } returns listOf(header)
|
||||
every { blogManager.getPostBody(message.id) } returns body
|
||||
every { ctx.json(listOf(header.output(body))) } returns ctx
|
||||
every { blogManager.getPostText(message.id) } returns text
|
||||
every { ctx.json(listOf(header.output(text))) } returns ctx
|
||||
|
||||
controller.listPosts(ctx)
|
||||
}
|
||||
@@ -102,7 +102,7 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
fun testOutputBlogPost() {
|
||||
val json = """
|
||||
{
|
||||
"text": "$body",
|
||||
"text": "$text",
|
||||
"author": ${toJson(author.output())},
|
||||
"authorStatus": "ourselves",
|
||||
"type": "post",
|
||||
@@ -114,7 +114,7 @@ internal class BlogControllerTest : ControllerTest() {
|
||||
"timestampReceived": $timestamp
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, header.output(body))
|
||||
assertJsonEquals(json, header.output(text))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ internal class WebSocketControllerTest : ControllerTest() {
|
||||
private val header =
|
||||
PrivateMessageHeader(message.id, group.id, timestamp, true, true, true, true)
|
||||
private val event = PrivateMessageReceivedEvent(header, contact.id)
|
||||
private val outputEvent = OutputEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
|
||||
private val outputEvent = OutputEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
|
||||
|
||||
@Test
|
||||
fun testSendEvent() {
|
||||
@@ -32,7 +32,7 @@ internal class WebSocketControllerTest : ControllerTest() {
|
||||
every { session1.send(capture(slot)) } just Runs
|
||||
|
||||
controller.sessions.add(session1)
|
||||
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
|
||||
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
|
||||
|
||||
assertJsonEquals(slot.captured, outputEvent)
|
||||
}
|
||||
@@ -55,7 +55,7 @@ internal class WebSocketControllerTest : ControllerTest() {
|
||||
|
||||
controller.sessions.add(session1)
|
||||
controller.sessions.add(session2)
|
||||
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(body))
|
||||
controller.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text))
|
||||
|
||||
verify { session2.send(slot.captured) }
|
||||
}
|
||||
@@ -66,7 +66,7 @@ internal class WebSocketControllerTest : ControllerTest() {
|
||||
{
|
||||
"type": "event",
|
||||
"name": "PrivateMessageReceivedEvent",
|
||||
"data": ${toJson(header.output(contact.id, body))}
|
||||
"data": ${toJson(header.output(contact.id, text))}
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, outputEvent)
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.briarproject.bramble.util.StringUtils.getRandomString
|
||||
import org.briarproject.briar.api.client.SessionId
|
||||
import org.briarproject.briar.api.introduction.IntroductionRequest
|
||||
import org.briarproject.briar.api.messaging.*
|
||||
import org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_BODY_LENGTH
|
||||
import org.briarproject.briar.api.messaging.MessagingConstants.MAX_PRIVATE_MESSAGE_TEXT_LENGTH
|
||||
import org.briarproject.briar.api.messaging.event.PrivateMessageReceivedEvent
|
||||
import org.briarproject.briar.headless.ControllerTest
|
||||
import org.briarproject.briar.headless.event.WebSocketController
|
||||
@@ -50,8 +50,8 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
fun list() {
|
||||
expectGetContact()
|
||||
every { conversationManager.getMessageHeaders(contact.id) } returns listOf(header)
|
||||
every { messagingManager.getMessageBody(message.id) } returns body
|
||||
every { ctx.json(listOf(header.output(contact.id, body))) } returns ctx
|
||||
every { messagingManager.getMessageText(message.id) } returns text
|
||||
every { ctx.json(listOf(header.output(contact.id, text))) } returns ctx
|
||||
|
||||
controller.list(ctx)
|
||||
}
|
||||
@@ -59,7 +59,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
@Test
|
||||
fun listIntroductionRequest() {
|
||||
val request = IntroductionRequest(
|
||||
message.id, group.id, timestamp, true, true, false, true, sessionId, author, body,
|
||||
message.id, group.id, timestamp, true, true, false, true, sessionId, author, text,
|
||||
false, false
|
||||
)
|
||||
|
||||
@@ -95,14 +95,14 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
val slot = CapturingSlot<JsonDict>()
|
||||
|
||||
expectGetContact()
|
||||
every { ctx.body() } returns """{"text": "$body"}"""
|
||||
every { ctx.body() } returns """{"text": "$text"}"""
|
||||
every { messagingManager.getContactGroup(contact) } returns group
|
||||
every { clock.currentTimeMillis() } returns timestamp
|
||||
every {
|
||||
privateMessageFactory.createPrivateMessage(
|
||||
group.id,
|
||||
timestamp,
|
||||
body
|
||||
text
|
||||
)
|
||||
} returns privateMessage
|
||||
every { messagingManager.addLocalMessage(privateMessage) } just runs
|
||||
@@ -110,7 +110,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
|
||||
controller.write(ctx)
|
||||
|
||||
assertEquals(privateMessage.output(contact.id, body), slot.captured)
|
||||
assertEquals(privateMessage.output(contact.id, text), slot.captured)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,7 +124,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun writeNonexistentBody() {
|
||||
fun writeNonexistentText() {
|
||||
expectGetContact()
|
||||
every { ctx.body() } returns """{"foo": "bar"}"""
|
||||
|
||||
@@ -132,7 +132,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun writeEmptyBody() {
|
||||
fun writeEmptyText() {
|
||||
expectGetContact()
|
||||
every { ctx.body() } returns """{"text": ""}"""
|
||||
|
||||
@@ -140,9 +140,9 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun writeTooLongBody() {
|
||||
fun writeTooLongText() {
|
||||
expectGetContact()
|
||||
every { ctx.body() } returns """{"text": "${getRandomString(MAX_PRIVATE_MESSAGE_BODY_LENGTH + 1)}"}"""
|
||||
every { ctx.body() } returns """{"text": "${getRandomString(MAX_PRIVATE_MESSAGE_TEXT_LENGTH + 1)}"}"""
|
||||
|
||||
assertThrows(BadRequestResponse::class.java) { controller.write(ctx) }
|
||||
}
|
||||
@@ -151,8 +151,8 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
fun privateMessageEvent() {
|
||||
val event = PrivateMessageReceivedEvent(header, contact.id)
|
||||
|
||||
every { messagingManager.getMessageBody(message.id) } returns body
|
||||
every { webSocketController.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(body)) } just runs
|
||||
every { messagingManager.getMessageText(message.id) } returns text
|
||||
every { webSocketController.sendEvent(EVENT_PRIVATE_MESSAGE, event.output(text)) } just runs
|
||||
|
||||
controller.eventOccurred(event)
|
||||
}
|
||||
@@ -161,7 +161,7 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
fun testOutputPrivateMessageHeader() {
|
||||
val json = """
|
||||
{
|
||||
"text": "$body",
|
||||
"text": "$text",
|
||||
"type": "PrivateMessage",
|
||||
"timestamp": $timestamp,
|
||||
"groupId": ${toJson(header.groupId.bytes)},
|
||||
@@ -173,14 +173,14 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
"id": ${toJson(header.id.bytes)}
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, header.output(contact.id, body))
|
||||
assertJsonEquals(json, header.output(contact.id, text))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputPrivateMessage() {
|
||||
val json = """
|
||||
{
|
||||
"text": "$body",
|
||||
"text": "$text",
|
||||
"type": "PrivateMessage",
|
||||
"timestamp": ${message.timestamp},
|
||||
"groupId": ${toJson(message.groupId.bytes)},
|
||||
@@ -192,11 +192,11 @@ internal class MessagingControllerImplTest : ControllerTest() {
|
||||
"id": ${toJson(message.id.bytes)}
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, privateMessage.output(contact.id, body))
|
||||
assertJsonEquals(json, privateMessage.output(contact.id, text))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testIntroductionRequestWithEmptyBody() {
|
||||
fun testIntroductionRequestWithNullText() {
|
||||
val request = IntroductionRequest(
|
||||
message.id, group.id, timestamp, true, true, false, true, sessionId, author, null,
|
||||
false, false
|
||||
|
||||
Reference in New Issue
Block a user