mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-1235 Auth | Testing | Added test to make sure mnemonic is deleted on logout (#19)
This commit is contained in:
parent
747e0312ad
commit
44d253b0ba
2 changed files with 76 additions and 0 deletions
|
@ -29,4 +29,5 @@ dependencies {
|
|||
testImplementation libs.mockitoKotlin
|
||||
testImplementation libs.robolectric
|
||||
testImplementation libs.archCoreTesting
|
||||
testImplementation libs.coroutineTesting
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package com.anytypeio.anytype.persistence
|
||||
|
||||
import android.content.Context
|
||||
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
|
||||
import androidx.room.Room
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.anytypeio.anytype.persistence.db.AnytypeDatabase
|
||||
import com.anytypeio.anytype.persistence.repo.DefaultAuthCache
|
||||
import com.anytypeio.anytype.test_utils.MockDataFactory
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.After
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.RuntimeEnvironment
|
||||
import org.robolectric.annotation.Config
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(manifest = Config.NONE)
|
||||
class DefaultAuthCacheTest {
|
||||
|
||||
@get:Rule
|
||||
val instantTaskExecutorRule = InstantTaskExecutorRule()
|
||||
|
||||
private val database = Room.inMemoryDatabaseBuilder(
|
||||
InstrumentationRegistry.getInstrumentation().context,
|
||||
AnytypeDatabase::class.java
|
||||
).allowMainThreadQueries().build()
|
||||
|
||||
private val encryptedPrefs = RuntimeEnvironment.getApplication().getSharedPreferences(
|
||||
"Encrypted prefs",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
|
||||
private val defaultPrefs = RuntimeEnvironment.getApplication().getSharedPreferences(
|
||||
"Default prefs",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
|
||||
@After
|
||||
fun after() {
|
||||
database.close()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should save mnemonic and clear mnemonic on logout`() = runTest {
|
||||
|
||||
val givenMnemonic = MockDataFactory.randomString()
|
||||
|
||||
val cache = DefaultAuthCache(
|
||||
db = database,
|
||||
encryptedPrefs = encryptedPrefs,
|
||||
defaultPrefs = defaultPrefs
|
||||
)
|
||||
|
||||
cache.saveMnemonic(mnemonic = givenMnemonic)
|
||||
|
||||
assertTrue { encryptedPrefs.contains(DefaultAuthCache.MNEMONIC_KEY) }
|
||||
|
||||
assertEquals(
|
||||
expected = givenMnemonic,
|
||||
actual = cache.getMnemonic()
|
||||
)
|
||||
|
||||
cache.logout()
|
||||
|
||||
assertFalse { encryptedPrefs.contains(DefaultAuthCache.MNEMONIC_KEY) }
|
||||
assertFalse { defaultPrefs.contains(DefaultAuthCache.MNEMONIC_KEY) }
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue