-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into dependabot/github_actions/codecov/codecov…
…-action-3
- Loading branch information
Showing
8 changed files
with
285 additions
and
40 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
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
142 changes: 142 additions & 0 deletions
142
logic/src/commonTest/kotlin/com/wire/kalium/logic/client/E2EIClientProviderTest.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,142 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2023 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.kalium.logic.client | ||
|
||
import com.wire.kalium.logic.data.client.E2EIClientProvider | ||
import com.wire.kalium.logic.data.client.EI2EIClientProviderImpl | ||
import com.wire.kalium.logic.framework.TestClient | ||
import com.wire.kalium.logic.framework.TestUser | ||
import com.wire.kalium.logic.util.arrangement.provider.E2EIClientProviderArrangement | ||
import com.wire.kalium.logic.util.arrangement.provider.E2EIClientProviderArrangementImpl | ||
import com.wire.kalium.logic.util.shouldFail | ||
import com.wire.kalium.logic.util.shouldSucceed | ||
import io.mockative.any | ||
import io.mockative.once | ||
import io.mockative.verify | ||
import kotlinx.coroutines.test.runTest | ||
import kotlin.test.Test | ||
|
||
class E2EIClientProviderTest { | ||
@Test | ||
fun givenMLSClientWithoutE2EI_whenGettingE2EIClient_callsNewRotateEnrollment() = runTest{ | ||
val (arrangement, e2eiClientProvider) = Arrangement() | ||
.arrange { | ||
withGetMLSClientSuccessful() | ||
withE2EINewActivationEnrollmentSuccessful() | ||
withSelfUser(TestUser.SELF) | ||
withE2EIEnabled(false) | ||
} | ||
|
||
e2eiClientProvider.getE2EIClient(TestClient.CLIENT_ID).shouldSucceed() | ||
|
||
verify(arrangement.userRepository) | ||
.suspendFunction(arrangement.userRepository::getSelfUser) | ||
.wasInvoked(exactly = once) | ||
|
||
verify(arrangement.mlsClient) | ||
.suspendFunction(arrangement.mlsClient::e2eiNewActivationEnrollment) | ||
.with(any(), any(), any()) | ||
.wasInvoked(exactly = once) | ||
|
||
verify(arrangement.mlsClient) | ||
.suspendFunction(arrangement.mlsClient::e2eiNewRotateEnrollment) | ||
.with(any(),any(),any()) | ||
.wasNotInvoked() | ||
} | ||
|
||
@Test | ||
fun givenMLSClientWithE2EI_whenGettingE2EIClient_callsNewActivationEnrollment() = runTest{ | ||
val (arrangement, e2eiClientProvider) = Arrangement() | ||
.arrange { | ||
withGetMLSClientSuccessful() | ||
withE2EINewRotationEnrollmentSuccessful() | ||
withSelfUser(TestUser.SELF) | ||
withE2EIEnabled(true) | ||
} | ||
|
||
e2eiClientProvider.getE2EIClient(TestClient.CLIENT_ID).shouldSucceed() | ||
|
||
verify(arrangement.userRepository) | ||
.suspendFunction(arrangement.userRepository::getSelfUser) | ||
.wasInvoked(exactly = once) | ||
|
||
verify(arrangement.mlsClientProvider) | ||
.suspendFunction(arrangement.mlsClientProvider::getMLSClient) | ||
.with(any()) | ||
.wasInvoked(exactly = once) | ||
|
||
verify(arrangement.mlsClient) | ||
.suspendFunction(arrangement.mlsClient::e2eiNewRotateEnrollment) | ||
.with(any(),any(),any()) | ||
.wasInvoked(exactly = once) | ||
|
||
verify(arrangement.mlsClient) | ||
.suspendFunction(arrangement.mlsClient::e2eiNewActivationEnrollment) | ||
.with(any(), any(), any()) | ||
.wasNotInvoked() | ||
} | ||
|
||
@Test | ||
fun givenSelfUserNotFound_whenGettingE2EIClient_ReturnsError() = runTest{ | ||
val (arrangement, e2eiClientProvider) = Arrangement() | ||
.arrange { | ||
withGetMLSClientSuccessful() | ||
withE2EINewRotationEnrollmentSuccessful() | ||
withSelfUser(null) | ||
withE2EIEnabled(true) | ||
} | ||
|
||
e2eiClientProvider.getE2EIClient(TestClient.CLIENT_ID).shouldFail() | ||
|
||
verify(arrangement.userRepository) | ||
.suspendFunction(arrangement.userRepository::getSelfUser) | ||
.wasInvoked(exactly = once) | ||
|
||
verify(arrangement.mlsClientProvider) | ||
.suspendFunction(arrangement.mlsClientProvider::getMLSClient) | ||
.with(any()) | ||
.wasNotInvoked() | ||
|
||
verify(arrangement.mlsClient) | ||
.suspendFunction(arrangement.mlsClient::e2eiNewRotateEnrollment) | ||
.with(any(),any(),any()) | ||
.wasNotInvoked() | ||
|
||
verify(arrangement.mlsClient) | ||
.suspendFunction(arrangement.mlsClient::e2eiNewActivationEnrollment) | ||
.with(any(), any(), any()) | ||
.wasNotInvoked() | ||
} | ||
|
||
private class Arrangement : | ||
E2EIClientProviderArrangement by E2EIClientProviderArrangementImpl() { | ||
private lateinit var e2eiClientProvider: E2EIClientProvider | ||
|
||
fun arrange(block: Arrangement.() -> Unit): Pair<Arrangement, E2EIClientProvider> { | ||
apply(block) | ||
e2eiClientProvider = EI2EIClientProviderImpl( | ||
TestUser.USER_ID, | ||
currentClientIdProvider, | ||
mlsClientProvider, | ||
userRepository | ||
) | ||
|
||
return this to e2eiClientProvider | ||
} | ||
} | ||
} |
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
Oops, something went wrong.