From 53830656364a43d8d52db54831bb498df726321b Mon Sep 17 00:00:00 2001 From: 0x330a <92654767+0x330a@users.noreply.github.com> Date: Fri, 16 Dec 2022 10:56:59 +1100 Subject: [PATCH] test: add in contact merge tests --- .../libsession_util/InstrumentedTests.kt | 37 +++++++++++++++++++ .../messenger/libsession_util/util/Contact.kt | 12 +++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt b/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt index 3e17f9f835..f29a0802c6 100644 --- a/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt +++ b/libsession-util/src/androidTest/java/network/loki/messenger/libsession_util/InstrumentedTests.kt @@ -2,9 +2,12 @@ package network.loki.messenger.libsession_util import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry +import network.loki.messenger.libsession_util.util.Contact import network.loki.messenger.libsession_util.util.KeyPair import network.loki.messenger.libsession_util.util.Sodium import network.loki.messenger.libsession_util.util.UserPic +import org.hamcrest.CoreMatchers.not +import org.hamcrest.MatcherAssert.assertThat import org.junit.Assert.* import org.junit.Test import org.junit.runner.RunWith @@ -112,6 +115,40 @@ class InstrumentedTests { assertEquals(anotherId, contactList[1].id) assertEquals("Joey", contactList[0].nickname) assertNull(contactList[1].nickname) + + contacts.erase(definitelyRealId) + + val thirdId ="052222222222222222222222222222222222222222222222222222222222222222" + val third = Contact( + id = thirdId, + nickname = "Nickname 3", + approved = true, + blocked = true, + profilePicture = UserPic("http://example.com/huge.bmp", "qwerty".encodeToByteArray()) + ) + contacts2.set(third) + assertTrue(contacts.needsPush()) + assertTrue(contacts2.needsPush()) + val toPush = contacts.push() + val toPush2 = contacts2.push() + assertEquals(toPush.seqNo, toPush2.seqNo) + assertThat(toPush2.config, not(equals(toPush.config))) + + contacts.confirmPushed(toPush.seqNo) + contacts2.confirmPushed(toPush2.seqNo) + + contacts.merge(toPush2.config) + contacts2.merge(toPush.config) + + assertTrue(contacts.needsPush()) + assertTrue(contacts2.needsPush()) + + val mergePush = contacts.push() + val mergePush2 = contacts2.push() + + assertEquals(mergePush.seqNo, mergePush2.seqNo) + assertArrayEquals(mergePush.config, mergePush2.config) + } @Test diff --git a/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt b/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt index 71e67555c1..aa00310e75 100644 --- a/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt +++ b/libsession-util/src/main/java/network/loki/messenger/libsession_util/util/Contact.kt @@ -2,10 +2,10 @@ package network.loki.messenger.libsession_util.util data class Contact( val id: String, - var name: String?, - var nickname: String?, - var approved: Boolean, - var approvedMe: Boolean, - var blocked: Boolean, - var profilePicture: UserPic? + var name: String? = null, + var nickname: String? = null, + var approved: Boolean = false, + var approvedMe: Boolean = false, + var blocked: Boolean = false, + var profilePicture: UserPic? = null ) \ No newline at end of file