mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-23 18:15:22 +00:00
refactor: change storage adding contacts to create one on ones with a non hidden thread priority and base for testing storage expiration merges from fake polling
This commit is contained in:
parent
f71c56022d
commit
e06f9ee79a
@ -7,16 +7,22 @@ import androidx.test.filters.SmallTest
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import network.loki.messenger.libsession_util.ConfigBase
|
||||
import network.loki.messenger.libsession_util.Contacts
|
||||
import network.loki.messenger.libsession_util.ConversationVolatileConfig
|
||||
import network.loki.messenger.libsession_util.util.Contact
|
||||
import network.loki.messenger.libsession_util.util.Conversation
|
||||
import network.loki.messenger.libsession_util.util.ExpiryMode
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.kotlin.argThat
|
||||
import org.mockito.kotlin.argWhere
|
||||
import org.mockito.kotlin.eq
|
||||
import org.mockito.kotlin.spy
|
||||
import org.mockito.kotlin.verify
|
||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||
import org.session.libsession.messaging.messages.ExpirationConfiguration
|
||||
import org.session.libsession.snode.SnodeAPI
|
||||
import org.session.libsession.utilities.Address
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsignal.utilities.KeyHelper
|
||||
import org.session.libsignal.utilities.hexEncodedPublicKey
|
||||
@ -50,13 +56,22 @@ class LibSessionTests {
|
||||
|
||||
private fun buildContactMessage(contactList: List<Contact>): ByteArray {
|
||||
val (key,_) = maybeGetUserInfo()!!
|
||||
val contacts = Contacts.Companion.newInstance(key)
|
||||
val contacts = Contacts.newInstance(key)
|
||||
contactList.forEach { contact ->
|
||||
contacts.set(contact)
|
||||
}
|
||||
return contacts.push().config
|
||||
}
|
||||
|
||||
private fun buildVolatileMessage(conversations: List<Conversation>): ByteArray {
|
||||
val (key, _) = maybeGetUserInfo()!!
|
||||
val volatile = ConversationVolatileConfig.newInstance(key)
|
||||
conversations.forEach { conversation ->
|
||||
volatile.set(conversation)
|
||||
}
|
||||
return volatile.push().config
|
||||
}
|
||||
|
||||
private fun fakePollNewConfig(configBase: ConfigBase, toMerge: ByteArray) {
|
||||
configBase.merge(nextFakeHash to toMerge)
|
||||
MessagingModuleConfiguration.shared.configFactory.persist(configBase, System.currentTimeMillis())
|
||||
@ -99,4 +114,38 @@ class LibSessionTests {
|
||||
verify(storageSpy).setRecipientApproved(argThat { address.serialize() == newContactId }, eq(true))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun test_expected_configs() {
|
||||
val app = InstrumentationRegistry.getInstrumentation().targetContext.applicationContext as ApplicationContext
|
||||
val storageSpy = spy(app.storage)
|
||||
app.storage = storageSpy
|
||||
|
||||
val randomRecipient = randomSessionId()
|
||||
val newContact = Contact(
|
||||
id = randomRecipient,
|
||||
approved = true,
|
||||
expiryMode = ExpiryMode.AfterSend(1000)
|
||||
)
|
||||
val newConvo = Conversation.OneToOne(
|
||||
randomRecipient,
|
||||
SnodeAPI.nowWithOffset,
|
||||
false
|
||||
)
|
||||
val volatiles = MessagingModuleConfiguration.shared.configFactory.convoVolatile!!
|
||||
val contacts = MessagingModuleConfiguration.shared.configFactory.contacts!!
|
||||
val newContactMerge = buildContactMessage(listOf(newContact))
|
||||
val newVolatileMerge = buildVolatileMessage(listOf(newConvo))
|
||||
val expConfig = ExpirationConfiguration()
|
||||
val recipientAddress = Address.fromSerialized(randomRecipient)
|
||||
fakePollNewConfig(contacts, newContactMerge)
|
||||
fakePollNewConfig(volatiles, newVolatileMerge)
|
||||
val threadId = storageSpy.getThreadId(recipientAddress)!!
|
||||
// whenever(storageSpy.getExpirationConfiguration(eq(threadId))).thenReturn(expConfig)
|
||||
// doNothing().whenever(storageSpy).setExpirationConfiguration(any())
|
||||
// verify(storageSpy).getExpirationConfiguration(eq(threadId))
|
||||
verify(storageSpy).setExpirationConfiguration(argWhere { config ->
|
||||
config.expiryMode is ExpiryMode.AfterSend
|
||||
})
|
||||
}
|
||||
|
||||
}
|
@ -1217,7 +1217,7 @@ open class Storage(
|
||||
deleteConversation(conversationThreadId)
|
||||
}
|
||||
} else {
|
||||
getThreadId(fromSerialized(contact.id))?.let { conversationThreadId ->
|
||||
getOrCreateThreadIdFor(fromSerialized(contact.id)).let { conversationThreadId ->
|
||||
setPinned(conversationThreadId, contact.priority == PRIORITY_PINNED)
|
||||
}
|
||||
}
|
||||
@ -1231,8 +1231,7 @@ open class Storage(
|
||||
contact.expiryMode,
|
||||
timestamp
|
||||
)
|
||||
DatabaseComponent.get(context).expirationConfigurationDatabase()
|
||||
.setExpirationConfiguration(expiration)
|
||||
setExpirationConfiguration(expiration)
|
||||
}
|
||||
}
|
||||
setRecipientHash(recipient, contact.hashCode().toString())
|
||||
|
@ -214,7 +214,6 @@ class Poller(private val configFactory: ConfigFactoryProtocol, debounceTimer: Ti
|
||||
val responseList = (rawResponses["results"] as List<RawResponse>)
|
||||
// in case we had null configs, the array won't be fully populated
|
||||
// index of the sparse array key iterator should be the request index, with the key being the namespace
|
||||
// TODO: add in specific ordering of config namespaces for processing
|
||||
listOfNotNull(
|
||||
configFactory.user?.configNamespace(),
|
||||
configFactory.contacts?.configNamespace(),
|
||||
|
Loading…
Reference in New Issue
Block a user