PIN : fix tests with new LockScreenConfig
This commit is contained in:
parent
4bcb17f09f
commit
20eed4f7d7
3 changed files with 10 additions and 8 deletions
|
|
@ -19,14 +19,14 @@ package io.element.android.appconfig
|
|||
object LockScreenConfig {
|
||||
|
||||
/**
|
||||
* Whether the LockScreen is mandatory or not.
|
||||
* Whether the PIN is mandatory or not.
|
||||
*/
|
||||
const val IS_MANDATORY: Boolean = false
|
||||
const val IS_PIN_MANDATORY: Boolean = false
|
||||
|
||||
/**
|
||||
* Some PINs are blacklisted.
|
||||
*/
|
||||
val PIN_BLACKLIST = listOf("0000", "1234")
|
||||
val PIN_BLACKLIST = setOf("0000", "1234")
|
||||
|
||||
/**
|
||||
* The size of the PIN.
|
||||
|
|
|
|||
|
|
@ -20,7 +20,10 @@ import io.element.android.appconfig.LockScreenConfig
|
|||
import io.element.android.features.lockscreen.impl.pin.model.PinEntry
|
||||
import javax.inject.Inject
|
||||
|
||||
class PinValidator @Inject constructor() {
|
||||
class PinValidator internal constructor(private val pinBlacklist: Set<String>) {
|
||||
|
||||
@Inject
|
||||
constructor() : this(LockScreenConfig.PIN_BLACKLIST)
|
||||
|
||||
sealed interface Result {
|
||||
data object Valid : Result
|
||||
|
|
@ -29,7 +32,7 @@ class PinValidator @Inject constructor() {
|
|||
|
||||
fun isPinValid(pinEntry: PinEntry): Result {
|
||||
val pinAsText = pinEntry.toText()
|
||||
val isBlacklisted = LockScreenConfig.PIN_BLACKLIST.any { it == pinAsText }
|
||||
val isBlacklisted = pinBlacklist.any { it == pinAsText }
|
||||
return if (isBlacklisted) {
|
||||
Result.Invalid(SetupPinFailure.PinBlacklisted)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ import app.cash.molecule.RecompositionMode
|
|||
import app.cash.molecule.moleculeFlow
|
||||
import app.cash.turbine.test
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.appconfig.LockScreenConfig
|
||||
import io.element.android.features.lockscreen.impl.pin.model.assertEmpty
|
||||
import io.element.android.features.lockscreen.impl.pin.model.assertText
|
||||
import io.element.android.features.lockscreen.impl.setup.validation.PinValidator
|
||||
|
|
@ -32,7 +31,7 @@ import org.junit.Test
|
|||
|
||||
class SetupPinPresenterTest {
|
||||
|
||||
private val blacklistedPin = LockScreenConfig.PIN_BLACKLIST
|
||||
private val blacklistedPin = "1234"
|
||||
private val halfCompletePin = "12"
|
||||
private val completePin = "1235"
|
||||
private val mismatchedPin = "1236"
|
||||
|
|
@ -101,6 +100,6 @@ class SetupPinPresenterTest {
|
|||
}
|
||||
|
||||
private fun createSetupPinPresenter(): SetupPinPresenter {
|
||||
return SetupPinPresenter(PinValidator(), aBuildMeta())
|
||||
return SetupPinPresenter(PinValidator(setOf(blacklistedPin)), aBuildMeta())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue