mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-19 06:09:55 +01:00
[headless] Fix unit tests by passing only timestamp into OutputContact
This commit is contained in:
@@ -63,7 +63,8 @@ constructor(
|
|||||||
|
|
||||||
override fun list(ctx: Context): Context {
|
override fun list(ctx: Context): Context {
|
||||||
val contacts = contactManager.contacts.map { contact ->
|
val contacts = contactManager.contacts.map { contact ->
|
||||||
contact.output(conversationManager)
|
val latestMsgTime = conversationManager.getGroupCount(contact.id).latestMsgTime
|
||||||
|
contact.output(latestMsgTime)
|
||||||
}
|
}
|
||||||
return ctx.json(contacts)
|
return ctx.json(contacts)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,19 +6,16 @@ import org.briarproject.bramble.identity.output
|
|||||||
import org.briarproject.briar.api.conversation.ConversationManager
|
import org.briarproject.briar.api.conversation.ConversationManager
|
||||||
import org.briarproject.briar.headless.json.JsonDict
|
import org.briarproject.briar.headless.json.JsonDict
|
||||||
|
|
||||||
internal fun Contact.output(conversationManager: ConversationManager) = JsonDict(
|
internal fun Contact.output(latestMsgTime: Long) = JsonDict(
|
||||||
"contactId" to id.int,
|
"contactId" to id.int,
|
||||||
"author" to author.output(),
|
"author" to author.output(),
|
||||||
"verified" to isVerified,
|
"verified" to isVerified,
|
||||||
"lastChatActivity" to this.getLastChatActivity(conversationManager)
|
"lastChatActivity" to latestMsgTime
|
||||||
).apply {
|
).apply {
|
||||||
alias?.let { put("alias", it) }
|
alias?.let { put("alias", it) }
|
||||||
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
|
handshakePublicKey?.let { put("handshakePublicKey", it.encoded) }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun Contact.getLastChatActivity(conversationManager: ConversationManager) =
|
|
||||||
conversationManager.getGroupCount(this.id).latestMsgTime
|
|
||||||
|
|
||||||
internal fun ContactAddedEvent.output() = JsonDict(
|
internal fun ContactAddedEvent.output() = JsonDict(
|
||||||
"contactId" to contactId.int,
|
"contactId" to contactId.int,
|
||||||
"verified" to isVerified
|
"verified" to isVerified
|
||||||
|
|||||||
@@ -34,8 +34,12 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
|
|
||||||
private val pendingContact = getPendingContact()
|
private val pendingContact = getPendingContact()
|
||||||
|
|
||||||
private val controller =
|
private val controller = ContactControllerImpl(
|
||||||
ContactControllerImpl(contactManager, conversationManager, objectMapper, webSocketController)
|
contactManager,
|
||||||
|
conversationManager,
|
||||||
|
objectMapper,
|
||||||
|
webSocketController
|
||||||
|
)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testEmptyContactList() {
|
fun testEmptyContactList() {
|
||||||
@@ -48,7 +52,7 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
fun testList() {
|
fun testList() {
|
||||||
every { contactManager.contacts } returns listOf(contact)
|
every { contactManager.contacts } returns listOf(contact)
|
||||||
every { conversationManager.getGroupCount(contact.id).latestMsgTime } returns timestamp
|
every { conversationManager.getGroupCount(contact.id).latestMsgTime } returns timestamp
|
||||||
every { ctx.json(listOf(contact.output(conversationManager))) } returns ctx
|
every { ctx.json(listOf(contact.output(timestamp))) } returns ctx
|
||||||
controller.list(ctx)
|
controller.list(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +269,6 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOutputContact() {
|
fun testOutputContact() {
|
||||||
every { conversationManager.getGroupCount(contact.id).latestMsgTime } returns timestamp
|
|
||||||
assertNotNull(contact.handshakePublicKey)
|
assertNotNull(contact.handshakePublicKey)
|
||||||
val json = """
|
val json = """
|
||||||
{
|
{
|
||||||
@@ -274,10 +277,10 @@ internal class ContactControllerTest : ControllerTest() {
|
|||||||
"alias" : "${contact.alias}",
|
"alias" : "${contact.alias}",
|
||||||
"handshakePublicKey": ${toJson(contact.handshakePublicKey!!.encoded)},
|
"handshakePublicKey": ${toJson(contact.handshakePublicKey!!.encoded)},
|
||||||
"verified": ${contact.isVerified},
|
"verified": ${contact.isVerified},
|
||||||
"lastChatActivity": ${timestamp}
|
"lastChatActivity": $timestamp
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
assertJsonEquals(json, contact.output(conversationManager))
|
assertJsonEquals(json, contact.output(timestamp))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user