-
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.
refactor: api mocks [WPB-9999] (#3053)
* refactor: api mocks * removed unnecessary conversation creation in test * fix: hide conversation name in logs * added documentation to logger * test fixes
- Loading branch information
Showing
34 changed files
with
794 additions
and
549 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
55 changes: 55 additions & 0 deletions
55
logic/src/commonMain/kotlin/com/wire/kalium/logic/util/TimeLogger.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,55 @@ | ||
/* | ||
* 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.kalium.logic.util | ||
|
||
import kotlinx.datetime.Clock | ||
import kotlinx.datetime.Instant | ||
|
||
/** | ||
* The `TimeLogger` class is designed to measure the duration of a process for benchmarking purposes. | ||
* It takes a `processName` as a parameter to identify the process being timed. | ||
* | ||
* Usage: | ||
* - Call `start()` to begin tracking the time for a process. | ||
* - Call `finish()` to log the time taken since `start()` was invoked. | ||
* | ||
* @property processName The name of the process being measured. | ||
* | ||
* Methods: | ||
* - `start()`: Logs the process start and records the current time. | ||
* - `finish()`: Logs the process end, calculates the elapsed time, and prints the duration in milliseconds. | ||
* | ||
* This class is useful for performance analysis and optimization by providing a simple way to track | ||
* execution times for different parts of code. | ||
*/ | ||
class TimeLogger(private val processName: String) { | ||
|
||
private lateinit var startTime: Instant | ||
fun start() { | ||
println("$processName starting") | ||
startTime = Clock.System.now() | ||
|
||
} | ||
|
||
fun finish() { | ||
val endTime = Clock.System.now() | ||
val duration = endTime - startTime | ||
println("$processName finished after: ${duration.inWholeMilliseconds} milliseconds") | ||
} | ||
|
||
} |
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
42 changes: 42 additions & 0 deletions
42
mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.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,42 @@ | ||
/* | ||
* 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.kalium.mocks.mocks.client | ||
|
||
import com.wire.kalium.network.api.authenticated.client.Capabilities | ||
import com.wire.kalium.network.api.authenticated.client.ClientCapabilityDTO | ||
import com.wire.kalium.network.api.authenticated.client.ClientDTO | ||
import com.wire.kalium.network.api.authenticated.client.ClientTypeDTO | ||
import com.wire.kalium.network.api.authenticated.client.DeviceTypeDTO | ||
|
||
object ClientMocks { | ||
|
||
const val selfClientId = "defkrr8e7grgsoufhg8" | ||
|
||
val selfClient = ClientDTO( | ||
clientId = selfClientId, | ||
type = ClientTypeDTO.Permanent, | ||
deviceType = DeviceTypeDTO.Phone, | ||
registrationTime = "2021-05-12T10:52:02.671Z", | ||
lastActive = "2021-05-12T10:52:02.671Z", | ||
label = "label", | ||
cookie = "sldkfmdeklmwldwlek23kl44mntiuepfojfndkjd", | ||
capabilities = Capabilities(listOf(ClientCapabilityDTO.LegalHoldImplicitConsent)), | ||
model = "model", | ||
mlsPublicKeys = null | ||
) | ||
} |
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
111 changes: 111 additions & 0 deletions
111
mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/connection/ConnectionMocks.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,111 @@ | ||
/* | ||
* 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.kalium.mocks.mocks.connection | ||
|
||
import com.wire.kalium.network.api.authenticated.connection.ConnectionDTO | ||
import com.wire.kalium.network.api.authenticated.connection.ConnectionResponse | ||
import com.wire.kalium.network.api.authenticated.connection.ConnectionStateDTO | ||
import com.wire.kalium.network.api.authenticated.connection.UpdateConnectionRequest | ||
import com.wire.kalium.network.api.model.ConversationId | ||
import com.wire.kalium.network.api.model.PaginationRequest | ||
import com.wire.kalium.network.api.model.QualifiedID | ||
import kotlinx.datetime.Instant | ||
|
||
object ConnectionMocks { | ||
val connectionList = listOf( | ||
ConnectionDTO( | ||
conversationId = "addb6fbf-2bc3-4b59-b428-6fa4c594fb05", | ||
from = "36ef84a9-837a-4f75-af81-5a2e70e06836", | ||
lastUpdate = Instant.parse("2022-04-04T16:11:28.388Z"), | ||
qualifiedConversationId = ConversationId( | ||
domain = "staging.zinfra.io", | ||
value = "addb6fbf-2bc3-4b59-b428-6fa4c594fb05" | ||
), | ||
qualifiedToId = QualifiedID( | ||
domain = "staging.zinfra.io", | ||
value = "76ebeb16-a849-4be4-84a7-157654b492cf" | ||
), | ||
status = ConnectionStateDTO.ACCEPTED, | ||
toId = "76ebeb16-a849-4be4-84a7-157654b492cf" | ||
), | ||
ConnectionDTO( | ||
conversationId = "af6d3c9a-7934-4790-9ebf-f655e13acc76", | ||
from = "36ef84a9-837a-4f75-af81-5a2e70e06836", | ||
lastUpdate = Instant.parse("2022-03-23T16:53:32.515Z"), | ||
qualifiedConversationId = ConversationId( | ||
domain = "staging.zinfra.io", | ||
value = "af6d3c9a-7934-4790-9ebf-f655e13acc76" | ||
), | ||
qualifiedToId = QualifiedID( | ||
domain = "staging.zinfra.io", | ||
value = "787db7f1-f5ba-481b-af3e-9c27705a6440" | ||
), | ||
status = ConnectionStateDTO.ACCEPTED, | ||
toId = "787db7f1-f5ba-481b-af3e-9c27705a6440" | ||
), | ||
ConnectionDTO( | ||
conversationId = "f15a944a-b62b-4d9a-aff4-014d78a02294", | ||
from = "36ef84a9-837a-4f75-af81-5a2e70e06836", | ||
lastUpdate = Instant.parse("2022-03-25T17:20:13.637Z"), | ||
qualifiedConversationId = ConversationId( | ||
domain = "staging.zinfra.io", | ||
value = "f15a944a-b62b-4d9a-aff4-014d78a02294" | ||
), | ||
qualifiedToId = QualifiedID( | ||
domain = "staging.zinfra.io", | ||
value = "ba6b0fa1-32b1-4e25-8072-a71f07bfba5e" | ||
), | ||
status = ConnectionStateDTO.ACCEPTED, | ||
toId = "ba6b0fa1-32b1-4e25-8072-a71f07bfba5e" | ||
) | ||
) | ||
|
||
val connectionsResponse = ConnectionResponse( | ||
connections = connectionList, | ||
hasMore = false, | ||
pagingState = "AQ==" | ||
) | ||
|
||
val connection = ConnectionDTO( | ||
conversationId = "addb6fbf-2bc3-4b59-b428-6fa4c594fb05", | ||
from = "36ef84a9-837a-4f75-af81-5a2e70e06836", | ||
lastUpdate = Instant.parse("2022-04-04T16:11:28.388Z"), | ||
qualifiedConversationId = ConversationId( | ||
domain = "staging.zinfra.io", | ||
value = "addb6fbf-2bc3-4b59-b428-6fa4c594fb05" | ||
), | ||
qualifiedToId = QualifiedID( | ||
domain = "staging.zinfra.io", | ||
value = "76ebeb16-a849-4be4-84a7-157654b492cf" | ||
), | ||
status = ConnectionStateDTO.ACCEPTED, | ||
toId = "76ebeb16-a849-4be4-84a7-157654b492cf" | ||
) | ||
|
||
val emptyPaginationRequest = PaginationRequest( | ||
size = 500, | ||
pagingState = null | ||
) | ||
|
||
val paginationRequest = PaginationRequest( | ||
size = 500, | ||
pagingState = "PAGING_STATE_1234" | ||
) | ||
|
||
val acceptedConnectionRequest = UpdateConnectionRequest(ConnectionStateDTO.ACCEPTED) | ||
} |
77 changes: 77 additions & 0 deletions
77
mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/conversation/ConversationMocks.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,77 @@ | ||
/* | ||
* 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.kalium.mocks.mocks.conversation | ||
|
||
import com.wire.kalium.mocks.mocks.domain.DomainMocks | ||
import com.wire.kalium.network.api.authenticated.conversation.ConvProtocol | ||
import com.wire.kalium.network.api.authenticated.conversation.ConversationMemberDTO | ||
import com.wire.kalium.network.api.authenticated.conversation.ConversationMembersResponse | ||
import com.wire.kalium.network.api.authenticated.conversation.ConversationPagingResponse | ||
import com.wire.kalium.network.api.authenticated.conversation.ConversationResponse | ||
import com.wire.kalium.network.api.authenticated.conversation.ConversationsDetailsRequest | ||
import com.wire.kalium.network.api.authenticated.conversation.ReceiptMode | ||
import com.wire.kalium.network.api.model.ConversationAccessDTO | ||
import com.wire.kalium.network.api.model.ConversationAccessRoleDTO | ||
import com.wire.kalium.network.api.model.ConversationId | ||
import com.wire.kalium.network.api.model.UserId | ||
|
||
object ConversationMocks { | ||
|
||
val conversationId = ConversationId("conversation_id", DomainMocks.domain) | ||
|
||
val conversation = ConversationResponse( | ||
"creator", | ||
ConversationMembersResponse( | ||
ConversationMemberDTO.Self(UserId("someValue", "someDomain"), "wire_member"), | ||
emptyList() | ||
), | ||
"group name", | ||
conversationId, | ||
null, | ||
0UL, | ||
ConversationResponse.Type.GROUP, | ||
0, | ||
null, | ||
ConvProtocol.PROTEUS, | ||
lastEventTime = "2024-03-30T15:36:00.000Z", | ||
access = setOf(ConversationAccessDTO.INVITE, ConversationAccessDTO.CODE), | ||
accessRole = setOf( | ||
ConversationAccessRoleDTO.GUEST, | ||
ConversationAccessRoleDTO.TEAM_MEMBER, | ||
ConversationAccessRoleDTO.NON_TEAM_MEMBER | ||
), | ||
mlsCipherSuiteTag = null, | ||
receiptMode = ReceiptMode.DISABLED | ||
) | ||
|
||
val conversationListIdsResponse = ConversationPagingResponse( | ||
conversationsIds = listOf( | ||
conversationId, | ||
ConversationId("f4680835-2cfe-4d4d-8491-cbb201bd5c2b", "anta.wire.link") | ||
), | ||
hasMore = false, | ||
pagingState = "AQ==" | ||
) | ||
|
||
val conversationsDetailsRequest = ConversationsDetailsRequest( | ||
conversationsIds = listOf( | ||
conversationId, | ||
ConversationId("f4680835-2cfe-4d4d-8491-cbb201bd5c2b", "anta.wire.link") | ||
) | ||
) | ||
} |
Oops, something went wrong.