-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Yamil Medina <[email protected]>
- Loading branch information
1 parent
7cdd898
commit b17cc73
Showing
6 changed files
with
173 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
app/src/test/kotlin/com/wire/android/ui/home/AppSyncViewModelTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2024 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
*/ | ||
package com.wire.android.ui.home | ||
|
||
import com.wire.android.config.CoroutineTestExtension | ||
import com.wire.kalium.logic.feature.e2ei.SyncCertificateRevocationListUseCase | ||
import com.wire.kalium.logic.feature.e2ei.usecase.ObserveCertificateRevocationForSelfClientUseCase | ||
import com.wire.kalium.logic.feature.featureConfig.FeatureFlagsSyncWorker | ||
import io.mockk.MockKAnnotations | ||
import io.mockk.coEvery | ||
import io.mockk.coVerify | ||
import io.mockk.impl.annotations.MockK | ||
import kotlinx.coroutines.InternalCoroutinesApi | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.test.advanceUntilIdle | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
@ExtendWith(CoroutineTestExtension::class) | ||
class AppSyncViewModelTest { | ||
@Test | ||
fun `when startSyncingAppConfig is called then it should call the use case`() = runTest { | ||
val (arrangement, viewModel) = Arrangement().arrange { | ||
withObserveCertificateRevocationForSelfClient() | ||
withFeatureFlagsSyncWorker() | ||
withSyncCertificateRevocationListUseCase() | ||
} | ||
|
||
viewModel.startSyncingAppConfig() | ||
advanceUntilIdle() | ||
|
||
coVerify { arrangement.observeCertificateRevocationForSelfClient.invoke() } | ||
coVerify { arrangement.syncCertificateRevocationListUseCase.invoke() } | ||
coVerify { arrangement.featureFlagsSyncWorker.execute() } | ||
} | ||
|
||
@Test | ||
fun `when startSyncingAppConfig is called multiple times then it should call the use case with delay`() = runTest { | ||
val (arrangement, viewModel) = Arrangement().arrange { | ||
withObserveCertificateRevocationForSelfClient(1000) | ||
withFeatureFlagsSyncWorker(1000) | ||
withSyncCertificateRevocationListUseCase(1000) | ||
} | ||
|
||
viewModel.startSyncingAppConfig() | ||
viewModel.startSyncingAppConfig() | ||
viewModel.startSyncingAppConfig() | ||
advanceUntilIdle() | ||
|
||
coVerify(exactly = 1) { arrangement.observeCertificateRevocationForSelfClient.invoke() } | ||
coVerify(exactly = 1) { arrangement.syncCertificateRevocationListUseCase.invoke() } | ||
coVerify(exactly = 1) { arrangement.featureFlagsSyncWorker.execute() } | ||
} | ||
|
||
private class Arrangement { | ||
|
||
@MockK | ||
lateinit var syncCertificateRevocationListUseCase: SyncCertificateRevocationListUseCase | ||
|
||
@MockK | ||
lateinit var observeCertificateRevocationForSelfClient: ObserveCertificateRevocationForSelfClientUseCase | ||
|
||
@MockK | ||
lateinit var featureFlagsSyncWorker: FeatureFlagsSyncWorker | ||
|
||
init { | ||
MockKAnnotations.init(this) | ||
} | ||
|
||
private val viewModel = AppSyncViewModel( | ||
syncCertificateRevocationListUseCase, | ||
observeCertificateRevocationForSelfClient, | ||
featureFlagsSyncWorker | ||
) | ||
|
||
@OptIn(InternalCoroutinesApi::class) | ||
fun withObserveCertificateRevocationForSelfClient(delayMs: Long = 0) { | ||
coEvery { observeCertificateRevocationForSelfClient.invoke() } coAnswers { | ||
delay(delayMs) | ||
} | ||
} | ||
|
||
fun withSyncCertificateRevocationListUseCase(delayMs: Long = 0) { | ||
coEvery { syncCertificateRevocationListUseCase.invoke() } coAnswers { | ||
delay(delayMs) | ||
} | ||
} | ||
|
||
fun withFeatureFlagsSyncWorker(delayMs: Long = 0) { | ||
coEvery { featureFlagsSyncWorker.execute() } coAnswers { | ||
delay(delayMs) | ||
} | ||
} | ||
|
||
fun arrange(block: Arrangement.() -> Unit) = apply(block).let { | ||
this to viewModel | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule kalium
updated
36 files