Add output of DeletionResult to deleteAllMessages call

This commit is contained in:
Nico Alt
2020-10-08 14:42:40 +02:00
parent 6c6dbfd357
commit c017a813b0
3 changed files with 37 additions and 3 deletions

View File

@@ -33,6 +33,7 @@ import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertThrows
import org.junit.jupiter.api.Test
import org.spongycastle.util.encoders.Base64
import kotlin.random.Random
internal class MessagingControllerImplTest : ControllerTest() {
@@ -346,8 +347,10 @@ internal class MessagingControllerImplTest : ControllerTest() {
@Test
fun testDeleteAllMessages() {
val result = DeletionResult()
every { ctx.pathParam("contactId") } returns "1"
every { conversationManager.deleteAllMessages(ContactId(1)) } returns DeletionResult()
every { conversationManager.deleteAllMessages(ContactId(1)) } returns result
every { ctx.json(result.output()) } returns ctx
controller.deleteAllMessages(ctx)
}
@@ -368,6 +371,27 @@ internal class MessagingControllerImplTest : ControllerTest() {
}
}
@Test
fun testOutputDeletionResult() {
val result = DeletionResult()
if (Random.nextBoolean()) result.addInvitationNotAllSelected()
if (Random.nextBoolean()) result.addInvitationSessionInProgress()
if (Random.nextBoolean()) result.addIntroductionNotAllSelected()
if (Random.nextBoolean()) result.addIntroductionSessionInProgress()
if (Random.nextBoolean()) result.addNotFullyDownloaded()
val json = """
{
"allDeleted": ${result.allDeleted()},
"hasIntroductionSessionInProgress": ${result.hasIntroductionSessionInProgress()},
"hasInvitationSessionInProgress": ${result.hasInvitationSessionInProgress()},
"hasNotAllIntroductionSelected": ${result.hasNotAllIntroductionSelected()},
"hasNotAllInvitationSelected": ${result.hasNotAllInvitationSelected()},
"hasNotFullyDownloaded": ${result.hasNotFullyDownloaded()}
}
"""
assertJsonEquals(json, result.output())
}
private fun expectGetContact() {
every { ctx.pathParam("contactId") } returns contact.id.int.toString()
every { contactManager.getContact(contact.id) } returns contact