Skip to content

Commit

Permalink
test: update logic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel committed Jul 18, 2023
1 parent 89522ab commit 342f515
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ class ClientRepositoryTest {
clientId = "client_id_1",
type = ClientTypeDTO.Permanent,
registrationTime = "1969-05-12T10:52:02.671Z",
lastActive = "1969-05-12T10:52:02.671Z",
deviceType = DeviceTypeDTO.Desktop,
label = null,
model = "Mac ox",
Expand All @@ -261,6 +262,7 @@ class ClientRepositoryTest {
clientId = "client_id_2",
type = ClientTypeDTO.Permanent,
registrationTime = "2021-05-12T10:52:02.671Z",
lastActive = "2021-05-12T10:52:02.671Z",
deviceType = DeviceTypeDTO.Phone,
label = null,
model = "iphone 15",
Expand All @@ -279,6 +281,7 @@ class ClientRepositoryTest {
id = PlainId(value = "client_id_1"),
type = ClientType.Permanent,
registrationTime = Instant.parse("1969-05-12T10:52:02.671Z"),
lastActive = Instant.parse("1969-05-12T10:52:02.671Z"),
deviceType = DeviceType.Desktop,
label = null,
model = "Mac ox",
Expand All @@ -289,6 +292,7 @@ class ClientRepositoryTest {
id = PlainId(value = "client_id_2"),
type = ClientType.Permanent,
registrationTime = Instant.parse("2021-05-12T10:52:02.671Z"),
lastActive = Instant.parse("2021-05-12T10:52:02.671Z"),
deviceType = DeviceType.Phone,
label = null,
model = "iphone 15",
Expand Down Expand Up @@ -349,6 +353,7 @@ class ClientRepositoryTest {
id = "client-id",
clientType = ClientTypeEntity.Permanent,
registrationDate = null,
lastActive = null,
deviceType = DeviceTypeEntity.Desktop,
label = null,
model = null,
Expand All @@ -363,6 +368,7 @@ class ClientRepositoryTest {
id = ClientId("client-id"),
type = ClientType.Permanent,
registrationTime = null,
lastActive = null,
deviceType = DeviceType.Desktop,
label = null,
model = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ class ConversationRepositoryTest {
true,
null,
null,
null,
null
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.wire.kalium.logic.data.logout.LogoutRepository
import com.wire.kalium.logic.data.notification.PushTokenRepository
import com.wire.kalium.logic.feature.CachedClientIdClearer
import com.wire.kalium.logic.feature.session.UpgradeCurrentSessionUseCase
import com.wire.kalium.logic.framework.TestClient
import com.wire.kalium.logic.functional.Either
import io.mockative.Mock
import io.mockative.any
Expand All @@ -52,7 +53,7 @@ class GetOrRegisterClientUseCaseTest {
@Test
fun givenValidClientIsRetained_whenRegisteringAClient_thenDoNotRegisterNewAndReturnPersistedClient() = runTest {
val clientId = ClientId("clientId")
val client = Client(clientId, ClientType.Permanent, Instant.DISTANT_FUTURE, isVerified = false, isValid = true, null, "label", null)
val client = TestClient.CLIENT.copy(id = clientId)
val (arrangement, useCase) = Arrangement()
.withRetainedClientIdResult(Either.Right(clientId))
.withVerifyExistingClientResult(VerifyExistingClientResult.Success(client))
Expand Down Expand Up @@ -81,7 +82,7 @@ class GetOrRegisterClientUseCaseTest {
@Test
fun givenInvalidClientIsRetained_whenRegisteringAClient_thenClearDataAndRegisterNewClient() = runTest {
val clientId = ClientId("clientId")
val client = Client(clientId, ClientType.Permanent, Instant.DISTANT_FUTURE, isVerified = false, isValid = true, null, "label", null)
val client = TestClient.CLIENT.copy(id = clientId)
val (arrangement, useCase) = Arrangement()
.withRetainedClientIdResult(Either.Right(clientId))
.withVerifyExistingClientResult(VerifyExistingClientResult.Failure.ClientNotRegistered)
Expand Down Expand Up @@ -129,7 +130,7 @@ class GetOrRegisterClientUseCaseTest {
@Test
fun givenClientNotRetained_whenRegisteringAClient_thenRegisterNewClient() = runTest {
val clientId = ClientId("clientId")
val client = Client(clientId, ClientType.Permanent, Instant.DISTANT_FUTURE, isVerified = false, isValid = true, null, "label", null)
val client = TestClient.CLIENT.copy(id = clientId)
val (arrangement, useCase) = Arrangement()
.withRetainedClientIdResult(Either.Left(CoreFailure.MissingClientRegistration))
.withRegisterClientResult(RegisterClientResult.Success(client))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.wire.kalium.logic.data.client.ClientType
import com.wire.kalium.logic.data.client.DeviceType
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.framework.TestClient
import com.wire.kalium.logic.functional.Either
import io.mockative.Mock
import io.mockative.any
Expand All @@ -48,25 +49,11 @@ class ObserveClientsByUserIdUseCaseTest {
// Given
val userId = UserId("123", "wire.com")
val clients = listOf(
Client(
id = ClientId("1111"),
type = ClientType.Permanent,
registrationTime = Instant.DISTANT_FUTURE,
deviceType = DeviceType.Desktop,
label = null,
model = "Mac ox",
isVerified = false,
isValid = true
TestClient.CLIENT.copy(
id = ClientId("1111")
),
Client(
id = ClientId("2222"),
type = ClientType.Temporary,
registrationTime = Instant.DISTANT_FUTURE,
deviceType = DeviceType.Phone,
label = null,
model = "Mac ox",
isVerified = false,
isValid = true
TestClient.CLIENT.copy(
id = ClientId("2222")
)
)
val (arrangement, getOtherUsersClientsUseCase) = Arrangement()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.wire.kalium.logic.data.client.DeviceType
import com.wire.kalium.logic.data.id.PlainId
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.CurrentClientIdProvider
import com.wire.kalium.logic.framework.TestClient
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.logic.test_util.TestKaliumDispatcher
import com.wire.kalium.util.KaliumDispatcher
Expand Down Expand Up @@ -95,16 +96,7 @@ class ObserveClientDetailsUseCaseTest {
private companion object {
val USER_ID = UserId("user_id", "domain")
val CLIENT_ID = PlainId(value = "client_id_1")
val CLIENT = Client(
id = CLIENT_ID,
type = ClientType.Permanent,
registrationTime = Instant.DISTANT_FUTURE,
deviceType = DeviceType.Desktop,
label = null,
model = "Mac ox",
isVerified = false,
isValid = true
)
val CLIENT = TestClient.CLIENT
val CLIENT_RESULT = CLIENT.copy(id = PlainId(value = "client_id_1"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import com.wire.kalium.logic.data.client.ClientType
import com.wire.kalium.logic.data.client.DeviceType
import com.wire.kalium.logic.data.id.PlainId
import com.wire.kalium.logic.feature.CurrentClientIdProvider
import com.wire.kalium.logic.framework.TestClient
import com.wire.kalium.logic.functional.Either
import com.wire.kalium.network.exceptions.KaliumException
import io.ktor.utils.io.errors.IOException
Expand Down Expand Up @@ -102,16 +103,7 @@ class SelfClientsUseCaseTest {
}

private companion object {
val CLIENT = Client(
id = PlainId(value = "client_id_1"),
type = ClientType.Permanent,
registrationTime = Instant.parse("2022-01-01T10:52:02.671Z"),
deviceType = DeviceType.Desktop,
label = null,
model = "Mac ox",
isVerified = false,
isValid = true
)
val CLIENT = TestClient.CLIENT
val CLIENTS_LIST = listOf(
CLIENT.copy(id = PlainId(value = "client_id_1")),
CLIENT.copy(id = PlainId(value = "client_id_2"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ package com.wire.kalium.logic.feature.client
import com.wire.kalium.logic.NetworkFailure
import com.wire.kalium.logic.data.client.Client
import com.wire.kalium.logic.data.client.ClientRepository
import com.wire.kalium.logic.data.client.ClientType
import com.wire.kalium.logic.data.conversation.ClientId
import com.wire.kalium.logic.framework.TestClient
import com.wire.kalium.logic.functional.Either
import io.mockative.Mock
import io.mockative.any
Expand All @@ -33,7 +33,6 @@ import io.mockative.mock
import io.mockative.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertIs
Expand All @@ -44,7 +43,7 @@ class VerifyExistingClientUseCaseTest {
@Test
fun givenRegisteredClientId_whenInvoking_thenReturnSuccess() = runTest {
val clientId = ClientId("clientId")
val client = Client(clientId, ClientType.Permanent, Instant.DISTANT_PAST, isVerified = false, isValid = false, null, null, "label")
val client = TestClient.CLIENT.copy(id = clientId)
val (_, useCase) = Arrangement()
.withSelfClientsResult(Either.Right(listOf(client)))
.arrange()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ object TestClient {
CLIENT_ID,
ClientType.Permanent,
Instant.DISTANT_PAST,
Instant.DISTANT_PAST,
deviceType = null,
model = null,
label = "label",
Expand Down

0 comments on commit 342f515

Please sign in to comment.