Clean up lint warnings in tests (#650)

This commit is contained in:
David Perez 2024-01-17 16:03:33 -06:00 committed by Álison Fernandes
parent d66f707d14
commit ac0a079e42
3 changed files with 128 additions and 170 deletions

View file

@ -11,7 +11,6 @@ import com.x8bit.bitwarden.data.auth.datasource.disk.model.UserStateJson
import com.x8bit.bitwarden.data.auth.datasource.disk.util.FakeAuthDiskSource
import com.x8bit.bitwarden.data.auth.datasource.network.model.GetTokenResponseJson
import com.x8bit.bitwarden.data.auth.datasource.network.model.KdfTypeJson
import com.x8bit.bitwarden.data.auth.datasource.network.model.KdfTypeJson.PBKDF2_SHA256
import com.x8bit.bitwarden.data.auth.datasource.network.model.PreLoginResponseJson
import com.x8bit.bitwarden.data.auth.datasource.network.model.RefreshTokenResponseJson
import com.x8bit.bitwarden.data.auth.datasource.network.model.RegisterRequestJson
@ -91,7 +90,7 @@ class AuthRepositoryTest {
.apply {
environment = Environment.Us
}
private val settingsRepository: SettingsRepository = mockk() {
private val settingsRepository: SettingsRepository = mockk {
every { setDefaultsIfNecessary(any()) } just runs
}
private val authSdkSource = mockk<AuthSdkSource> {
@ -710,7 +709,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -759,7 +758,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -791,7 +790,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -823,7 +822,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -863,7 +862,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -902,7 +901,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -933,7 +932,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -964,7 +963,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -1000,7 +999,7 @@ class AuthRepositoryTest {
publicKey = PUBLIC_KEY,
encryptedPrivateKey = PRIVATE_KEY,
),
kdfType = PBKDF2_SHA256,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = DEFAULT_KDF_ITERATIONS.toUInt(),
),
)
@ -1104,7 +1103,6 @@ class AuthRepositoryTest {
@Suppress("MaxLineLength")
@Test
fun `switchAccount when the given userId does not correspond to a saved account should do nothing`() {
val originalUserId = USER_ID_1
val invalidId = "invalidId"
val originalUserState = SINGLE_USER_STATE_1.toUserState(
vaultState = VAULT_STATE,
@ -1133,7 +1131,6 @@ class AuthRepositoryTest {
@Suppress("MaxLineLength")
@Test
fun `switchAccount when the userId is valid should update the current UserState, clear the previously unlocked data, and reset the special circumstance`() {
val originalUserId = USER_ID_1
val updatedUserId = USER_ID_2
val originalUserState = MULTI_USER_STATE.toUserState(
vaultState = VAULT_STATE,
@ -1276,7 +1273,6 @@ class AuthRepositoryTest {
private const val PASSWORD_HASH = "passwordHash"
private const val ACCESS_TOKEN = "accessToken"
private const val ACCESS_TOKEN_2 = "accessToken2"
private const val ACCESS_TOKEN_3 = "accessToken3"
private const val REFRESH_TOKEN = "refreshToken"
private const val REFRESH_TOKEN_2 = "refreshToken2"
private const val CAPTCHA_KEY = "captcha"
@ -1284,11 +1280,8 @@ class AuthRepositoryTest {
private const val ENCRYPTED_USER_KEY = "encryptedUserKey"
private const val PUBLIC_KEY = "PublicKey"
private const val PRIVATE_KEY = "privateKey"
private const val USER_AUTO_UNLOCK_KEY = "userAutoUnlockKey"
private const val USER_ID_1 = "2a135b23-e1fb-42c9-bec3-573857bc8181"
private const val USER_ID_2 = "b9d32ec0-6497-4582-9798-b350f53bfa02"
private const val USER_ID_3 = "3816ef34-0747-4133-9b7a-ba35d3768a68"
private val ORGANIZATION_KEYS = mapOf("organizationId1" to "organizationKey1")
private val ORGANIZATIONS = listOf(createMockOrganization(number = 0))
private val PRE_LOGIN_SUCCESS = PreLoginResponseJson(
kdfParams = PreLoginResponseJson.KdfParams.Pbkdf2(iterations = 1u),
@ -1365,31 +1358,6 @@ class AuthRepositoryTest {
environmentUrlData = null,
),
)
private val ACCOUNT_3 = AccountJson(
profile = AccountJson.Profile(
userId = USER_ID_3,
email = "test3@bitwarden.com",
isEmailVerified = true,
name = "Bitwarden Tester 3",
hasPremium = false,
stamp = null,
organizationId = null,
avatarColorHex = null,
forcePasswordResetReason = null,
kdfType = KdfTypeJson.PBKDF2_SHA256,
kdfIterations = 400000,
kdfMemory = null,
kdfParallelism = null,
userDecryptionOptions = null,
),
tokens = AccountJson.Tokens(
accessToken = ACCESS_TOKEN_3,
refreshToken = "refreshToken",
),
settings = AccountJson.Settings(
environmentUrlData = null,
),
)
private val SINGLE_USER_STATE_1 = UserStateJson(
activeUserId = USER_ID_1,
accounts = mapOf(
@ -1409,14 +1377,6 @@ class AuthRepositoryTest {
USER_ID_2 to ACCOUNT_2,
),
)
private val MULTI_USER_STATE_2 = UserStateJson(
activeUserId = USER_ID_3,
accounts = mapOf(
USER_ID_1 to ACCOUNT_1,
USER_ID_2 to ACCOUNT_2,
USER_ID_3 to ACCOUNT_3,
),
)
private val USER_ORGANIZATIONS = listOf(
UserOrganizations(
userId = USER_ID_1,

View file

@ -268,7 +268,8 @@ class GeneratorRepositoryTest {
@Suppress("MaxLineLength")
@Test
fun `generatePlusAddressedEmail should return Success with generated email when SDK call is successful`() = runTest {
fun `generatePlusAddressedEmail should return Success with generated email when SDK call is successful`() =
runTest {
val userId = "testUserId"
val request = UsernameGeneratorRequest.Subaddress(
type = AppendType.Random,
@ -309,8 +310,8 @@ class GeneratorRepositoryTest {
@Suppress("MaxLineLength")
@Test
fun `generateCatchAllEmail should return Success with generated email when SDK call is successful`() = runTest {
val userId = "testUserId"
fun `generateCatchAllEmail should return Success with generated email when SDK call is successful`() =
runTest {
val request = UsernameGeneratorRequest.Catchall(
type = AppendType.Random,
domain = "domain",
@ -349,8 +350,8 @@ class GeneratorRepositoryTest {
@Suppress("MaxLineLength")
@Test
fun `generateRandomWord should return Success with generated email when SDK call is successful`() = runTest {
val userId = "testUserId"
fun `generateRandomWord should return Success with generated email when SDK call is successful`() =
runTest {
val request = UsernameGeneratorRequest.Word(
capitalize = false,
includeNumber = false,
@ -758,6 +759,7 @@ class GeneratorRepositoryTest {
generatorDiskSource.storeUsernameGenerationOptions(any(), any())
}
}
}
private val USER_STATE = UserStateJson(
activeUserId = "activeUserId",
@ -809,4 +811,3 @@ class GeneratorRepositoryTest {
),
),
)
}

View file

@ -73,7 +73,7 @@ class GeneratorViewModelTest : BaseViewModelTest() {
private val randomWordSavedStateHandle = createSavedStateHandleWithState(initialRandomWordState)
private val mutableUserStateFlow = MutableStateFlow<UserState?>(DEFAULT_USER_STATE)
private val authRepository = mockk<AuthRepository>() {
private val authRepository = mockk<AuthRepository> {
every { userStateFlow } returns mutableUserStateFlow
}
@ -1399,12 +1399,9 @@ class GeneratorViewModelTest : BaseViewModelTest() {
viewModel = createViewModel(usernameSavedStateHandle)
}
@Suppress("MaxLineLength")
@Test
fun `EmailTextChange should update email correctly`() =
runTest {
fun `EmailTextChange should update email correctly`() = runTest {
val newEmail = "test@example.com"
val newGeneratedEmail = "email+abcd1234@address.com"
viewModel.actionChannel.trySend(
GeneratorAction
.MainType