mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
Remove pending contact state from the database.
This commit is contained in:
@@ -11,7 +11,7 @@ import org.junit.jupiter.api.Test
|
||||
class ContactControllerIntegrationTest: IntegrationTest() {
|
||||
|
||||
@Test
|
||||
fun `list of contacts need authentication token`() {
|
||||
fun `returning list of contacts needs authentication token`() {
|
||||
val response = getWithWrongToken("$url/contacts")
|
||||
assertEquals(401, response.statusCode)
|
||||
}
|
||||
@@ -72,11 +72,10 @@ class ContactControllerIntegrationTest: IntegrationTest() {
|
||||
assertEquals(200, response.statusCode)
|
||||
assertEquals(1, response.jsonArray.length())
|
||||
val jsonObject = response.jsonArray.getJSONObject(0)
|
||||
assertEquals(alias, jsonObject.getString("alias"))
|
||||
assertEquals("waiting_for_connection", jsonObject.getString("state"))
|
||||
assertEquals(alias, jsonObject.getJSONObject("pendingContact").getString("alias"))
|
||||
|
||||
// remove pending contact again
|
||||
val idString = jsonObject.getString("pendingContactId")
|
||||
val idString = jsonObject.getJSONObject("pendingContact").getString("pendingContactId")
|
||||
val deleteJson = """{"pendingContactId": "$idString"}"""
|
||||
response = delete("$url/contacts/add/pending", deleteJson)
|
||||
assertEquals(200, response.statusCode)
|
||||
@@ -94,7 +93,7 @@ class ContactControllerIntegrationTest: IntegrationTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `adding pending contacts needs authentication token`() {
|
||||
fun `adding a pending contact needs authentication token`() {
|
||||
val response = postWithWrongToken("$url/contacts/add/pending")
|
||||
assertEquals(401, response.statusCode)
|
||||
}
|
||||
@@ -106,7 +105,7 @@ class ContactControllerIntegrationTest: IntegrationTest() {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `deleting contact need authentication token`() {
|
||||
fun `deleting a contact needs authentication token`() {
|
||||
val response = deleteWithWrongToken("$url/contacts/1")
|
||||
assertEquals(401, response.statusCode)
|
||||
}
|
||||
|
||||
@@ -7,11 +7,14 @@ import io.mockk.Runs
|
||||
import io.mockk.every
|
||||
import io.mockk.just
|
||||
import io.mockk.runs
|
||||
import org.briarproject.bramble.api.Pair
|
||||
import org.briarproject.bramble.api.contact.Contact
|
||||
import org.briarproject.bramble.api.contact.ContactId
|
||||
import org.briarproject.bramble.api.contact.PendingContactId
|
||||
import org.briarproject.bramble.api.contact.PendingContactState.FAILED
|
||||
import org.briarproject.bramble.api.contact.PendingContactState.WAITING_FOR_CONNECTION
|
||||
import org.briarproject.bramble.api.contact.event.ContactAddedRemotelyEvent
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactAddedEvent
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactRemovedEvent
|
||||
import org.briarproject.bramble.api.contact.event.PendingContactStateChangedEvent
|
||||
import org.briarproject.bramble.api.db.NoSuchContactException
|
||||
@@ -124,8 +127,19 @@ internal class ContactControllerTest : ControllerTest() {
|
||||
|
||||
@Test
|
||||
fun testListPendingContacts() {
|
||||
every { contactManager.pendingContacts } returns listOf(pendingContact)
|
||||
every { ctx.json(listOf(pendingContact.output())) } returns ctx
|
||||
every { contactManager.pendingContacts } returns listOf(
|
||||
Pair(pendingContact, WAITING_FOR_CONNECTION)
|
||||
)
|
||||
every {
|
||||
ctx.json(
|
||||
listOf(
|
||||
JsonDict(
|
||||
"pendingContact" to pendingContact.output(),
|
||||
"state" to WAITING_FOR_CONNECTION.output()
|
||||
)
|
||||
)
|
||||
)
|
||||
} returns ctx
|
||||
controller.listPendingContacts(ctx)
|
||||
}
|
||||
|
||||
@@ -225,6 +239,20 @@ internal class ContactControllerTest : ControllerTest() {
|
||||
controller.eventOccurred(event)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPendingContactAddedEvent() {
|
||||
val event = PendingContactAddedEvent(pendingContact)
|
||||
|
||||
every {
|
||||
webSocketController.sendEvent(
|
||||
EVENT_PENDING_CONTACT_ADDED,
|
||||
event.output()
|
||||
)
|
||||
} just runs
|
||||
|
||||
controller.eventOccurred(event)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testPendingContactRemovedEvent() {
|
||||
val event = PendingContactRemovedEvent(pendingContact.id)
|
||||
@@ -284,13 +312,27 @@ internal class ContactControllerTest : ControllerTest() {
|
||||
{
|
||||
"pendingContactId": ${toJson(pendingContact.id.bytes)},
|
||||
"alias": "${pendingContact.alias}",
|
||||
"state": "${pendingContact.state.name.toLowerCase()}",
|
||||
"timestamp": ${pendingContact.timestamp}
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, pendingContact.output())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputPendingContactAddedEvent() {
|
||||
val event = PendingContactAddedEvent(pendingContact)
|
||||
val json = """
|
||||
{
|
||||
"pendingContact": {
|
||||
"pendingContactId": ${toJson(pendingContact.id.bytes)},
|
||||
"alias": "${pendingContact.alias}",
|
||||
"timestamp": ${pendingContact.timestamp}
|
||||
}
|
||||
}
|
||||
"""
|
||||
assertJsonEquals(json, event.output())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testOutputPendingContactStateChangedEvent() {
|
||||
val event = PendingContactStateChangedEvent(pendingContact.id, FAILED)
|
||||
|
||||
Reference in New Issue
Block a user