From 8be30153e123602160460044df53f7d3541a3430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BBerko?= Date: Tue, 8 Oct 2024 13:26:52 +0200 Subject: [PATCH] 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 --- .../ConfirmationDeliveryHandler.kt | 2 +- .../com/wire/kalium/logic/util/TimeLogger.kt | 55 +++++++++ .../asset/AssetMocks.kt} | 27 ++--- .../kalium/mocks/mocks/client/ClientMocks.kt | 42 +++++++ .../client/TokenMocks.kt} | 38 ++---- .../mocks/mocks/connection/ConnectionMocks.kt | 111 ++++++++++++++++++ .../mocks/conversation/ConversationMocks.kt | 77 ++++++++++++ .../kalium/mocks/mocks/domain/DomainMocks.kt | 25 ++++ .../wire/kalium/mocks/mocks/user/UserMocks.kt | 52 ++++++++ .../mocks/requests/ConnectionRequests.kt | 40 +++++++ .../mocks/requests/ConversationRequests.kt | 64 ++++++++++ .../mocks/requests/NotificationRequests.kt | 11 +- .../kalium/mocks/requests/PreKeyRequests.kt | 89 ++++++++++++++ .../mocks/responses/AccessTokenDTOJson.kt | 83 ------------- .../kalium/mocks/responses/CommonResponses.kt | 2 +- .../NotificationEventsResponseJson.kt | 12 ++ .../kalium/mocks/responses/UserDTOJson.kt | 97 --------------- .../asset/AssetUploadResponseJson.kt | 60 ---------- .../connection/ConnectionResponsesJson.kt | 107 ----------------- .../ConversationListIdsResponseJson.kt | 67 ----------- .../conversation/ConversationResponseJson.kt | 4 +- .../network/utils/MockUnboundNetworkClient.kt | 1 + .../kalium/api/v0/asset/AssetApiV0Test.kt | 16 +-- .../api/v0/connection/ConnectionApiV0Test.kt | 30 ++--- .../v0/conversation/ConversationApiV0Test.kt | 13 +- .../api/v0/user/login/LoginApiV0Test.kt | 24 ++-- .../api/v0/user/login/SSOLoginApiV0Test.kt | 35 +++--- .../api/v0/user/register/RegisterApiV0Test.kt | 7 +- .../kalium/api/v0/user/self/SelfApiV0Test.kt | 9 +- .../com/wire/kalium/api/v2/AssetApiV2Test.kt | 17 ++- .../kalium/api/v2/ConversationApiV2Test.kt | 9 +- .../wire/kalium/api/v4/ConnectionApiV4Test.kt | 7 +- tango-tests/build.gradle.kts | 1 + .../kotlin/PocIntegrationTest.kt | 109 ++++++++++++++++- 34 files changed, 794 insertions(+), 549 deletions(-) create mode 100644 logic/src/commonMain/kotlin/com/wire/kalium/logic/util/TimeLogger.kt rename mocks/src/commonMain/kotlin/com/wire/kalium/mocks/{responses/asset/AssetDownloadResponseJson.kt => mocks/asset/AssetMocks.kt} (57%) create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt rename mocks/src/commonMain/kotlin/com/wire/kalium/mocks/{responses/connection/ConnectionRequestsJson.kt => mocks/client/TokenMocks.kt} (51%) create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/connection/ConnectionMocks.kt create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/conversation/ConversationMocks.kt create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/domain/DomainMocks.kt create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/user/UserMocks.kt create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/ConnectionRequests.kt create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/ConversationRequests.kt create mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/PreKeyRequests.kt delete mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/AccessTokenDTOJson.kt delete mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/UserDTOJson.kt delete mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/asset/AssetUploadResponseJson.kt delete mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/connection/ConnectionResponsesJson.kt delete mode 100644 mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationListIdsResponseJson.kt diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/confirmation/ConfirmationDeliveryHandler.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/confirmation/ConfirmationDeliveryHandler.kt index 7a8e7a54a7e..fe5ccfaa950 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/confirmation/ConfirmationDeliveryHandler.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/confirmation/ConfirmationDeliveryHandler.kt @@ -147,7 +147,7 @@ internal class ConfirmationDeliveryHandlerImpl( }, { kaliumLogger.logStructuredJson( level = KaliumLogLevel.DEBUG, - leadingMessage = "Delivery confirmation sent for ${conversation.name} and message count: ${messages.size}", + leadingMessage = "Delivery confirmation sent for ${conversation.id.toLogString()} and message count: ${messages.size}", jsonStringKeyValues = mapOf( "conversationId" to conversation.id.toLogString(), "messages" to messages.joinToString { it.obfuscateId() }, diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/util/TimeLogger.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/util/TimeLogger.kt new file mode 100644 index 00000000000..9c98636c4c1 --- /dev/null +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/util/TimeLogger.kt @@ -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") + } + +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/asset/AssetDownloadResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/asset/AssetMocks.kt similarity index 57% rename from mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/asset/AssetDownloadResponseJson.kt rename to mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/asset/AssetMocks.kt index 28ebcbb7675..1edb4bc8b25 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/asset/AssetDownloadResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/asset/AssetMocks.kt @@ -15,25 +15,20 @@ * 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.asset -package com.wire.kalium.mocks.responses.asset - -import com.wire.kalium.mocks.responses.ValidJsonProvider +import com.wire.kalium.network.api.authenticated.asset.AssetResponse import com.wire.kalium.network.api.model.ErrorResponse -object AssetDownloadResponseJson { - private val invalidJsonProvider = { serializable: ErrorResponse -> - """ - |{ - | "code": "${serializable.code}", - | "message": "${serializable.message}", - | "label": "${serializable.label}" - |} - """.trimMargin() - } +object AssetMocks { + + val invalid = ErrorResponse(code = 401, message = "Invalid Asset Token", label = "invalid_asset_token") - val invalid = ValidJsonProvider( - ErrorResponse(code = 401, message = "Invalid Asset Token", label = "invalid_asset_token"), - invalidJsonProvider + val asset = AssetResponse( + key = "3-1-e7788668-1b22-488a-b63c-acede42f771f", + expires = "expiration_date", + token = "asset_token", + domain = "staging.wire.link" ) + } diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt new file mode 100644 index 00000000000..94c7f1fe86c --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/ClientMocks.kt @@ -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 + ) +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/connection/ConnectionRequestsJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/TokenMocks.kt similarity index 51% rename from mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/connection/ConnectionRequestsJson.kt rename to mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/TokenMocks.kt index 03049d8c486..70b43fd946f 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/connection/ConnectionRequestsJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/client/TokenMocks.kt @@ -15,35 +15,17 @@ * 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 -package com.wire.kalium.mocks.responses.connection +import com.wire.kalium.network.api.model.AccessTokenDTO -import com.wire.kalium.mocks.responses.ValidJsonProvider +object TokenMocks { -object ConnectionRequestsJson { - - val validEmptyBody = ValidJsonProvider(String) { - """ - { - "size":500 - } - """.trimIndent() - } - - val validPagingState = ValidJsonProvider("PAGING_STATE_1234") { - """ - { - "paging_state": "$it", - "size":500 - } - """.trimIndent() - } - - val validConnectionStatusUpdate = ValidJsonProvider("accepted") { - """ - { - "status": "$it" - } - """.trimIndent() - } + val accessToken = AccessTokenDTO( + userId = "user_id", // TODO check structure of userId to connect with User Mocks + value = "Nlrhltkj-NgJUjEVevHz8Ilgy_pyWCT2b0kQb-GlnamyswanghN9DcC3an5RUuA7sh1_nC3hv2ZzMRlIhPM7Ag==.v=1.k=1.d=1637254939." + + "t=a.l=.u=75ebeb16-a860-4be4-84a7-157654b492cf.c=18401233206926541098", + expiresIn = 900, + tokenType = "Bearer" + ) } diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/connection/ConnectionMocks.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/connection/ConnectionMocks.kt new file mode 100644 index 00000000000..aa4085db774 --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/connection/ConnectionMocks.kt @@ -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) +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/conversation/ConversationMocks.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/conversation/ConversationMocks.kt new file mode 100644 index 00000000000..b4ec178bc9d --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/conversation/ConversationMocks.kt @@ -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") + ) + ) +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/domain/DomainMocks.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/domain/DomainMocks.kt new file mode 100644 index 00000000000..04d3a2337ad --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/domain/DomainMocks.kt @@ -0,0 +1,25 @@ +/* + * 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.domain + +object DomainMocks { + + const val domain = "domain.com" + const val federatedDomain = "federated.com" + +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/user/UserMocks.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/user/UserMocks.kt new file mode 100644 index 00000000000..3aff76d8705 --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/mocks/user/UserMocks.kt @@ -0,0 +1,52 @@ +/* + * 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.user + +import com.wire.kalium.mocks.mocks.domain.DomainMocks +import com.wire.kalium.network.api.model.QualifiedID +import com.wire.kalium.network.api.model.SelfUserDTO + +object UserMocks { + + val selfId = QualifiedID("selfId", DomainMocks.domain) + val otherId = QualifiedID("otherId", DomainMocks.domain) + val secondId = QualifiedID("secondId", DomainMocks.domain) + val thirdId = QualifiedID("thirdId", DomainMocks.domain) + + val federatedId = QualifiedID("federatedId", DomainMocks.federatedDomain) + val federatedSecondId = QualifiedID("federatedSecondId", DomainMocks.federatedDomain) + + val selfUser = SelfUserDTO( + id = selfId, + name = "selfUser", + accentId = 2, + assets = listOf(), + deleted = null, + email = null, + handle = null, + service = null, + teamId = null, + expiresAt = "", + nonQualifiedId = "", + locale = "", + managedByDTO = null, + phone = null, + ssoID = null, + supportedProtocols = null + ) +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/ConnectionRequests.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/ConnectionRequests.kt new file mode 100644 index 00000000000..26a17c5d3b1 --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/ConnectionRequests.kt @@ -0,0 +1,40 @@ +/* + * 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.requests + +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.connection.ConnectionMocks +import com.wire.kalium.mocks.responses.CommonResponses +import com.wire.kalium.network.api.authenticated.connection.ConnectionResponse +import com.wire.kalium.network.utils.TestRequestHandler +import io.ktor.http.HttpMethod +import io.ktor.http.HttpStatusCode + +object ConnectionRequests { + private const val PATH_CONNECTION_LIST = "${CommonResponses.BASE_PATH_V1}list-connections" + fun connectionRequestResponseSuccess( + connectionResponse: ConnectionResponse = ConnectionMocks.connectionsResponse + ) = listOf( + TestRequestHandler( + path = PATH_CONNECTION_LIST, + httpMethod = HttpMethod.Post, + responseBody = connectionResponse.toJsonString(), + statusCode = HttpStatusCode.OK, + ) + ) +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/ConversationRequests.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/ConversationRequests.kt new file mode 100644 index 00000000000..041950c0ffa --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/ConversationRequests.kt @@ -0,0 +1,64 @@ +/* + * 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.requests + +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.conversation.ConversationMocks +import com.wire.kalium.mocks.responses.CommonResponses +import com.wire.kalium.mocks.responses.conversation.ConversationResponseJson +import com.wire.kalium.network.api.authenticated.conversation.ConversationResponseDTO +import com.wire.kalium.network.utils.TestRequestHandler +import io.ktor.http.HttpMethod +import io.ktor.http.HttpStatusCode + +object ConversationRequests { + private const val PATH_CONVERSATION_ID_LIST = "${CommonResponses.BASE_PATH_V1}conversations/list-ids" + private const val PATH_CONVERSATIONS = "${CommonResponses.BASE_PATH_V1}conversations" + private const val PATH_CONVERSATIONS_LIST_V2 = "${CommonResponses.BASE_PATH_V1}/conversations/list/v2" + + private val conversationIdListApiRequestSuccess = TestRequestHandler( + path = PATH_CONVERSATION_ID_LIST, + httpMethod = HttpMethod.Post, + responseBody = ConversationMocks.conversationListIdsResponse.toJsonString(), + statusCode = HttpStatusCode.OK, + ) + + private val createConversationRequestSuccess = TestRequestHandler( + path = PATH_CONVERSATIONS, + httpMethod = HttpMethod.Post, + responseBody = ConversationResponseJson.v0().rawJson, + statusCode = HttpStatusCode.OK, + ) + + private val getConversationDetailsListRequestSuccess = TestRequestHandler( + path = PATH_CONVERSATIONS_LIST_V2, + httpMethod = HttpMethod.Post, + responseBody = ConversationResponseDTO( + conversationsFound = listOf(ConversationMocks.conversation), + conversationsNotFound = emptyList(), + conversationsFailed = emptyList() + ).toJsonString(), + statusCode = HttpStatusCode.OK, + ) + + val conversationsRequestResponseSuccess = listOf( + conversationIdListApiRequestSuccess, + createConversationRequestSuccess, + getConversationDetailsListRequestSuccess + ) +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/NotificationRequests.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/NotificationRequests.kt index a75c8489b35..e31ce6c125d 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/NotificationRequests.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/NotificationRequests.kt @@ -31,6 +31,7 @@ object NotificationRequests { */ private const val PATH_LAST_NOTIFICATIONS = "${CommonResponses.BASE_PATH_V1}notifications/last" private const val PATH_PUSH_TOKENS = "${CommonResponses.BASE_PATH_V1}push/tokens" + private const val PATH_NOTIFICATIONS = "${CommonResponses.BASE_PATH_V1}notifications" /** * Request / Responses @@ -58,8 +59,16 @@ object NotificationRequests { statusCode = HttpStatusCode.OK, ) + private val notificationsListRequestResponseSuccess = TestRequestHandler( + path = PATH_NOTIFICATIONS, + httpMethod = HttpMethod.Get, + responseBody = NotificationEventsResponseJson.notificationResponseWithEmptyEvents.toJsonString(), + statusCode = HttpStatusCode.OK, + ) + val notificationsRequestResponseSuccess = listOf( pushTokenApiRequestSuccess, - lastNotificationsApiRequestSuccess + lastNotificationsApiRequestSuccess, + notificationsListRequestResponseSuccess ) } diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/PreKeyRequests.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/PreKeyRequests.kt new file mode 100644 index 00000000000..ed0fd4e5069 --- /dev/null +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/requests/PreKeyRequests.kt @@ -0,0 +1,89 @@ +/* + * 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.requests + +import com.wire.kalium.mocks.mocks.domain.DomainMocks +import com.wire.kalium.mocks.responses.CommonResponses +import com.wire.kalium.mocks.responses.ValidJsonProvider +import com.wire.kalium.network.api.authenticated.prekey.PreKeyDTO +import com.wire.kalium.network.utils.TestRequestHandler +import io.ktor.http.HttpMethod +import io.ktor.http.HttpStatusCode + +object PreKeyRequests { + private const val PATH_CLIENTS_PRE_KEYS = "${CommonResponses.BASE_PATH_V1}clients/defkrr8e7grgsoufhg8/prekeys" + private const val PATH_CLIENTS = "${CommonResponses.BASE_PATH_V1}clients/defkrr8e7grgsoufhg8" + + private const val PATH_USERS_PRE_KEYS = "${CommonResponses.BASE_PATH_V1}users/list-prekeys" + + private const val USER_1 = "someValue" + private const val USER_1_CLIENT = "defkrr8e7grgsoufhg8" + private val USER_1_CLIENT_PREYKEY = PreKeyDTO(key = "preKey1CoQBYIOjl7hw0D8YRNq", id = 1) + + private val clientPreKeysApiRequestSuccess = TestRequestHandler( + path = PATH_CLIENTS_PRE_KEYS, + httpMethod = HttpMethod.Get, + responseBody = "[1]", + statusCode = HttpStatusCode.OK, + ) + private val putClientPreKeysApiRequestSuccess = TestRequestHandler( + path = PATH_CLIENTS, + httpMethod = HttpMethod.Put, + responseBody = "", + statusCode = HttpStatusCode.OK, + ) + + private val jsonProvider = { _: Map>> -> + """ + |{ + | "${DomainMocks.domain}": { + | "$USER_1": { + | "$USER_1_CLIENT": { + | "key": "${USER_1_CLIENT_PREYKEY.key}", + | "id": ${USER_1_CLIENT_PREYKEY.id} + | } + | } + | } + |} + """.trimMargin() + } + + val valid = ValidJsonProvider( + mapOf( + DomainMocks.domain to + mapOf( + USER_1 to + mapOf(USER_1_CLIENT to USER_1_CLIENT_PREYKEY) + ) + ), + jsonProvider + ) + + private val postUserPreKeysApiRequestSuccess = TestRequestHandler( + path = PATH_USERS_PRE_KEYS, + httpMethod = HttpMethod.Post, + responseBody = valid.rawJson, + statusCode = HttpStatusCode.OK, + ) + + val preKeyRequestResponseSuccess = listOf( + clientPreKeysApiRequestSuccess, + putClientPreKeysApiRequestSuccess, + postUserPreKeysApiRequestSuccess + ) +} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/AccessTokenDTOJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/AccessTokenDTOJson.kt deleted file mode 100644 index bef3dfac4c5..00000000000 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/AccessTokenDTOJson.kt +++ /dev/null @@ -1,83 +0,0 @@ -/* - * 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.responses - -import com.wire.kalium.network.api.model.AccessTokenDTO - -object AccessTokenDTOJson { - private val jsonProvider = { serializable: AccessTokenDTO -> - """ - |{ - | "expires_in": ${serializable.expiresIn}, - | "access_token": "${serializable.value}", - | "user": "${serializable.userId}", - | "token_type": "${serializable.tokenType}" - |} - """.trimMargin() - } - - fun createValid(accessTokenDTO: AccessTokenDTO) = ValidJsonProvider(accessTokenDTO, jsonProvider) - - val valid = ValidJsonProvider( - AccessTokenDTO( - userId = "user_id", - value = "Nlrhltkj-NgJUjEVevHz8Ilgy_pyWCT2b0kQb-GlnamyswanghN9DcC3an5RUuA7sh1_nC3hv2ZzMRlIhPM7Ag==.v=1.k=1.d=1637254939." + - "t=a.l=.u=75ebeb16-a860-4be4-84a7-157654b492cf.c=18401233206926541098", - expiresIn = 900, - tokenType = "Bearer" - ), jsonProvider - ) - - val missingAccessToken = FaultyJsonProvider( - """ - |{ - | "expires_in": 900, - | "user": "75ebeb16-a860-4be4-84a7-157654b492", - | "token_type": "Bearer" - |} - """.trimMargin() - ) - val missingTokenType = FaultyJsonProvider( - """ - |{ - | "expires_in": 900, - | "access_token": "Nlrhltkj-NgJUjEVevHz8Ilgy_pyWCT2b0kQb-GlnamyswanghN9DcC3an5RUuA7sh1_nC3hv2ZzMRlIhPM7Ag==.v=1.k=1.d=1637254939.t=a.l=.u=75ebeb16-a860-4be4-84a7-157654b492cf.c=18401233206926541098", - | "user": "75ebeb16-a860-4be4-84a7-157654b492" - |} - """.trimMargin() - ) - val missingUser = FaultyJsonProvider( - """ - |{ - | "expires_in": 900, - | "access_token": "Nlrhltkj-NgJUjEVevHz8Ilgy_pyWCT2b0kQb-GlnamyswanghN9DcC3an5RUuA7sh1_nC3hv2ZzMRlIhPM7Ag==.v=1.k=1.d=1637254939.t=a.l=.u=75ebeb16-a860-4be4-84a7-157654b492cf.c=18401233206926541098", - | "token_type": "Bearer" - |} - """.trimMargin() - ) - val missingExpiration = FaultyJsonProvider( - """ - |{ - | "access_token": "Nlrhltkj-NgJUjEVevHz8Ilgy_pyWCT2b0kQb-GlnamyswanghN9DcC3an5RUuA7sh1_nC3hv2ZzMRlIhPM7Ag==.v=1.k=1.d=1637254939.t=a.l=.u=75ebeb16-a860-4be4-84a7-157654b492cf.c=18401233206926541098", - | "user": "75ebeb16-a860-4be4-84a7-157654b492", - | "token_type": "Bearer" - |} - """.trimMargin() - ) -} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/CommonResponses.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/CommonResponses.kt index 0d73a8495e5..12499c3ad4d 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/CommonResponses.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/CommonResponses.kt @@ -50,7 +50,7 @@ object CommonResponses { /** * DTO */ - val userID = QualifiedID("user_id", "user.domain.io") + val userID = QualifiedID("someValue", "someDomain") private val accessTokenDTO = AccessTokenDTO( userId = userID.value, value = "Nlrhltkj-NgJUjEVevHz8Ilgy_pyWCT2b0kQb-GlnamyswanghN9DcC3an5RUuA7sh1_nC3hv2ZzMRlIhPM7Ag==.v=1.k=1.d=1637254939." + diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt index d737b629a73..b80008137f6 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/NotificationEventsResponseJson.kt @@ -390,4 +390,16 @@ object NotificationEventsResponseJson { payload = listOf(), transient = false ) + + val notificationResponseWithEmptyEvents = NotificationResponse( + time = "2022-02-15T12:54:30Z", + hasMore = false, + notifications = listOf( + EventResponse( + id = "eventId", + payload = listOf(), + transient = false + ) + ) + ) } diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/UserDTOJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/UserDTOJson.kt deleted file mode 100644 index d61930e0c3d..00000000000 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/UserDTOJson.kt +++ /dev/null @@ -1,97 +0,0 @@ -/* - * 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.responses - -import com.wire.kalium.network.api.model.SelfUserDTO -import com.wire.kalium.network.api.model.UserId -import kotlinx.serialization.json.addJsonObject -import kotlinx.serialization.json.buildJsonObject -import kotlinx.serialization.json.put -import kotlinx.serialization.json.putJsonArray -import kotlinx.serialization.json.putJsonObject - -object UserDTOJson { - - private val jsonProvider = { serializable: SelfUserDTO -> - buildJsonObject { - put("accent_id", serializable.accentId) - put("id", serializable.nonQualifiedId) - putJsonObject("qualified_id") { - put("id", serializable.id.value) - put("domain", serializable.id.domain) - } - put("name", serializable.name) - put("locale", serializable.locale) - putJsonArray("assets") { - if (serializable.assets.isNotEmpty()) { - addJsonObject { - serializable.assets.forEach { userAsset -> - put("key", userAsset.key) - put("type", userAsset.type.toString()) - userAsset.size?.let { put("size", it.toString()) } - } - } - } - } - serializable.deleted?.let { put("deleted", it) } - serializable.email?.let { put("email", it) } - serializable.phone?.let { put("phone", it) } - serializable.expiresAt?.let { put("expires_at", it) } - serializable.handle?.let { put("handle", it) } - serializable.service?.let { service -> - putJsonObject("service") { - put("id", service.id) - put("provider", service.provider) - } - } - serializable.teamId?.let { put("team", it) } - serializable.managedByDTO?.let { put("managed_by", it.toString()) } - serializable.ssoID?.let { userSsoID -> - putJsonObject("sso_id") { - userSsoID.subject?.let { put("subject", it) } - userSsoID.scimExternalId?.let { put("scim_external_id", it) } - userSsoID.tenant?.let { put("tenant", it) } - } - } - }.toString() - } - - fun createValid(userDTO: SelfUserDTO) = ValidJsonProvider(userDTO, jsonProvider) - - val valid = ValidJsonProvider( - SelfUserDTO( - id = UserId("user_id", "domain.com"), - name = "user_name_123", - accentId = 2, - assets = listOf(), - deleted = null, - email = null, - handle = null, - service = null, - teamId = null, - expiresAt = "", - nonQualifiedId = "", - locale = "", - managedByDTO = null, - phone = null, - ssoID = null, - supportedProtocols = null - ), jsonProvider - ) -} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/asset/AssetUploadResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/asset/AssetUploadResponseJson.kt deleted file mode 100644 index 55fe101f76b..00000000000 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/asset/AssetUploadResponseJson.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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.responses.asset - -import com.wire.kalium.mocks.responses.ValidJsonProvider -import com.wire.kalium.network.api.authenticated.asset.AssetResponse -import com.wire.kalium.network.api.model.ErrorResponse - -object AssetUploadResponseJson { - private val validJsonProvider = { serializable: AssetResponse -> - """ - |{ - | "key": "${serializable.key}", - | "expires": "${serializable.expires}", - | "token": "${serializable.token}", - | "domain": "${serializable.domain}" - |} - """.trimMargin() - } - private val invalidJsonProvider = { serializable: ErrorResponse -> - """ - |{ - | "code": "${serializable.code}", - | "message": "${serializable.message}", - | "label": "${serializable.label}" - |} - """.trimMargin() - } - - val valid = ValidJsonProvider( - AssetResponse( - key = "3-1-e7788668-1b22-488a-b63c-acede42f771f", - expires = "expiration_date", - token = "asset_token", - domain = "staging.wire.link" - ), - validJsonProvider - ) - - val invalid = ValidJsonProvider( - ErrorResponse(code = 401, message = "Invalid Asset Token", label = "invalid_asset_token"), - invalidJsonProvider - ) -} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/connection/ConnectionResponsesJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/connection/ConnectionResponsesJson.kt deleted file mode 100644 index 2aff49f8346..00000000000 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/connection/ConnectionResponsesJson.kt +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.responses.connection - -import com.wire.kalium.mocks.responses.AnyResponseProvider -import com.wire.kalium.mocks.responses.ValidJsonProvider - -object ConnectionResponsesJson { - - object GetConnections { - private val jsonProvider = { _: String -> - """ - |{ - | "connections": [ - | { - | "conversation": "addb6fbf-2bc3-4b59-b428-6fa4c594fb05", - | "from": "36ef84a9-837a-4f75-af81-5a2e70e06836", - | "last_update": "2022-04-04T16:11:28.388Z", - | "qualified_conversation": { - | "domain": "staging.zinfra.io", - | "id": "addb6fbf-2bc3-4b59-b428-6fa4c594fb05" - | }, - | "qualified_to": { - | "domain": "staging.zinfra.io", - | "id": "76ebeb16-a849-4be4-84a7-157654b492cf" - | }, - | "status": "accepted", - | "to": "76ebeb16-a849-4be4-84a7-157654b492cf" - | }, - | { - | "conversation": "af6d3c9a-7934-4790-9ebf-f655e13acc76", - | "from": "36ef84a9-837a-4f75-af81-5a2e70e06836", - | "last_update": "2022-03-23T16:53:32.515Z", - | "qualified_conversation": { - | "domain": "staging.zinfra.io", - | "id": "af6d3c9a-7934-4790-9ebf-f655e13acc76" - | }, - | "qualified_to": { - | "domain": "staging.zinfra.io", - | "id": "787db7f1-f5ba-481b-af3e-9c27705a6440" - | }, - | "status": "accepted", - | "to": "787db7f1-f5ba-481b-af3e-9c27705a6440" - | }, - | { - | "conversation": "f15a944a-b62b-4d9a-aff4-014d78a02294", - | "from": "36ef84a9-837a-4f75-af81-5a2e70e06836", - | "last_update": "2022-03-25T17:20:13.637Z", - | "qualified_conversation": { - | "domain": "staging.zinfra.io", - | "id": "f15a944a-b62b-4d9a-aff4-014d78a02294" - | }, - | "qualified_to": { - | "domain": "staging.zinfra.io", - | "id": "ba6b0fa1-32b1-4e25-8072-a71f07bfba5e" - | }, - | "status": "accepted", - | "to": "ba6b0fa1-32b1-4e25-8072-a71f07bfba5e" - | } - | ], - | "has_more": false, - | "paging_state": "AQ==" - |} - """.trimIndent() - } - - val validGetConnections = AnyResponseProvider(data = "", jsonProvider) - } - - object CreateConnectionResponse { - val jsonProvider = ValidJsonProvider(String) { - """ - { - "conversation": "addb6fbf-2bc3-4b59-b428-6fa4c594fb05", - "from": "36ef84a9-837a-4f75-af81-5a2e70e06836", - "last_update": "2022-04-04T16:11:28.388Z", - "qualified_conversation": { - "domain": "staging.zinfra.io", - "id": "addb6fbf-2bc3-4b59-b428-6fa4c594fb05" - }, - "qualified_to": { - "domain": "staging.zinfra.io", - "id": "76ebeb16-a849-4be4-84a7-157654b492cf" - }, - "status": "accepted", - "to": "76ebeb16-a849-4be4-84a7-157654b492cf" - } - """.trimIndent() - } - } -} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationListIdsResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationListIdsResponseJson.kt deleted file mode 100644 index b7fd220ab77..00000000000 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationListIdsResponseJson.kt +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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.responses.conversation - -import com.wire.kalium.mocks.responses.AnyResponseProvider -import com.wire.kalium.mocks.responses.ValidJsonProvider -import com.wire.kalium.network.api.authenticated.conversation.ConversationsDetailsRequest - -object ConversationListIdsResponseJson { - - private val jsonProvider = { _: String -> - """ - |{ - | "has_more": false, - | "paging_state": "AQ==", - | "qualified_conversations": [ - | { - | "domain": "anta.wire.link", - | "id": "ebafd3d4-1548-49f2-ac4e-b2757e6ca44b" - | }, - | { - | "domain": "anta.wire.link", - | "id": "f4680835-2cfe-4d4d-8491-cbb201bd5c2b" - | } - | ] - |} - """.trimIndent() - } - - val validGetIds = AnyResponseProvider(data = "", jsonProvider) - - val validRequestIds = ValidJsonProvider( - ConversationsDetailsRequest(emptyList()) - ) { - """ - |{ - | "qualified_ids": [ - | { - | "id": "ebafd3d4-1548-49f2-ac4e-b2757e6ca44b", - | "domain": "anta.wire.link" - | }, - | { - | "id": "f4680835-2cfe-4d4d-8491-cbb201bd5c2b", - | "domain": "anta.wire.link" - | } - | ] - |} - """.trimIndent() - } - -} diff --git a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt index d9dc9934fe9..d8a59679053 100644 --- a/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt +++ b/mocks/src/commonMain/kotlin/com/wire/kalium/mocks/responses/conversation/ConversationResponseJson.kt @@ -58,7 +58,9 @@ object ConversationResponseJson { otrMutedRef = "2022-04-11T14:15:48.044Z", otrMutedStatus = MutedStatus.fromOrdinal(0) ), - listOf(ConversationMemberDTO.Other(id = QualifiedIDSamples.two, conversationRole = "wire_member")) + listOf( +// ConversationMemberDTO.Other(id = QualifiedIDSamples.two, conversationRole = "wire_member") + ) ), "group name", QualifiedIDSamples.one, diff --git a/network/src/commonMain/kotlin/com/wire/kalium/network/utils/MockUnboundNetworkClient.kt b/network/src/commonMain/kotlin/com/wire/kalium/network/utils/MockUnboundNetworkClient.kt index 7fff288ccb8..3e9031e6dff 100644 --- a/network/src/commonMain/kotlin/com/wire/kalium/network/utils/MockUnboundNetworkClient.kt +++ b/network/src/commonMain/kotlin/com/wire/kalium/network/utils/MockUnboundNetworkClient.kt @@ -68,6 +68,7 @@ object MockUnboundNetworkClient { ) } } + println("no expected response was found for ${currentRequest.method.value}:${currentRequest.url}") throw UnsupportedOperationException("no expected response was found for ${currentRequest.method.value}:${currentRequest.url}") } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/asset/AssetApiV0Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/asset/AssetApiV0Test.kt index 6efc55a2a96..0043d3d25e8 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/asset/AssetApiV0Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/asset/AssetApiV0Test.kt @@ -19,8 +19,8 @@ package com.wire.kalium.api.v0.asset import com.wire.kalium.api.ApiTest -import com.wire.kalium.mocks.responses.asset.AssetDownloadResponseJson -import com.wire.kalium.mocks.responses.asset.AssetUploadResponseJson +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.asset.AssetMocks import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.authenticated.asset.AssetMetadataRequest import com.wire.kalium.network.api.model.AssetId @@ -54,7 +54,7 @@ internal class AssetApiV0Test : ApiTest() { val encryptedData = "some-data".encodeToByteArray() val encryptedDataSource = { getDummyDataSource(fileSystem, encryptedData) } val networkClient = mockAuthenticatedNetworkClient( - VALID_ASSET_UPLOAD_RESPONSE.rawJson, + VALID_ASSET_UPLOAD_RESPONSE.toJsonString(), statusCode = HttpStatusCode.Created, assertion = { assertPost() @@ -70,7 +70,7 @@ internal class AssetApiV0Test : ApiTest() { // Then assertTrue(response.isSuccessful()) - assertEquals(response.value, VALID_ASSET_UPLOAD_RESPONSE.serializableData) + assertEquals(response.value, VALID_ASSET_UPLOAD_RESPONSE) } private fun getDummyDataSource(fileSystem: FakeFileSystem, dummyData: ByteArray): Source { @@ -89,7 +89,7 @@ internal class AssetApiV0Test : ApiTest() { val encryptedData = "some-data".encodeToByteArray() val encryptedDataSource = { getDummyDataSource(fileSystem, encryptedData) } val networkClient = mockAuthenticatedNetworkClient( - INVALID_ASSET_UPLOAD_RESPONSE.rawJson, + INVALID_ASSET_UPLOAD_RESPONSE.toJsonString(), statusCode = HttpStatusCode.BadRequest, assertion = { assertPost() @@ -186,7 +186,7 @@ internal class AssetApiV0Test : ApiTest() { // Given val apiPath = "$PATH_ASSETS_V4/$ASSET_DOMAIN/$ASSET_KEY" val networkClient = mockAuthenticatedNetworkClient( - responseBody = AssetDownloadResponseJson.invalid.rawJson, + responseBody = AssetMocks.invalid.toJsonString(), statusCode = HttpStatusCode.BadRequest, assertion = { assertGet() @@ -204,8 +204,8 @@ internal class AssetApiV0Test : ApiTest() { } companion object { - val VALID_ASSET_UPLOAD_RESPONSE = AssetUploadResponseJson.valid - val INVALID_ASSET_UPLOAD_RESPONSE = AssetUploadResponseJson.invalid + val VALID_ASSET_UPLOAD_RESPONSE = AssetMocks.asset + val INVALID_ASSET_UPLOAD_RESPONSE = AssetMocks.invalid const val PATH_ASSETS_V3 = "/assets/v3" const val PATH_ASSETS_V4 = "/assets/v4" const val HEADER_ASSET_TOKEN = "Asset-Token" diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/connection/ConnectionApiV0Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/connection/ConnectionApiV0Test.kt index 56d644bf4b9..7f93fae9861 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/connection/ConnectionApiV0Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/connection/ConnectionApiV0Test.kt @@ -19,8 +19,8 @@ package com.wire.kalium.api.v0.connection import com.wire.kalium.api.ApiTest -import com.wire.kalium.mocks.responses.connection.ConnectionRequestsJson -import com.wire.kalium.mocks.responses.connection.ConnectionResponsesJson +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.connection.ConnectionMocks import com.wire.kalium.network.api.base.authenticated.connection.ConnectionApi import com.wire.kalium.network.api.authenticated.connection.ConnectionStateDTO import com.wire.kalium.network.api.model.UserId @@ -36,12 +36,12 @@ internal class ConnectionApiV0Test : ApiTest() { @Test fun givenAGetConnectionsRequest_whenRequestingAllConnectionsWithSuccess_thenRequestShouldBeConfiguredCorrectly() = runTest { val networkClient = mockAuthenticatedNetworkClient( - GET_CONNECTIONS_RESPONSE.rawJson, + GET_CONNECTIONS_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertJson() assertPost() - assertJsonBodyContent(GET_CONNECTIONS_NO_PAGING_REQUEST.rawJson) + assertJsonBodyContent(GET_CONNECTIONS_NO_PAGING_REQUEST.toJsonString()) assertPathEqual(PATH_CONNECTIONS) } ) @@ -53,18 +53,18 @@ internal class ConnectionApiV0Test : ApiTest() { @Test fun givenAGetConnectionsRequestWithPaging_whenRequestingAllConnectionsWithSuccess_thenRequestShouldBeConfiguredCorrectly() = runTest { val networkClient = mockAuthenticatedNetworkClient( - GET_CONNECTIONS_RESPONSE.rawJson, + GET_CONNECTIONS_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertJson() assertPost() - assertJsonBodyContent(GET_CONNECTIONS_WITH_PAGING_REQUEST.rawJson) + assertJsonBodyContent(GET_CONNECTIONS_WITH_PAGING_REQUEST.toJsonString()) assertPathEqual(PATH_CONNECTIONS) } ) val connectionApi: ConnectionApi = ConnectionApiV0(networkClient) - connectionApi.fetchSelfUserConnections(pagingState = GET_CONNECTIONS_WITH_PAGING_REQUEST.serializableData) + connectionApi.fetchSelfUserConnections(pagingState = GET_CONNECTIONS_WITH_PAGING_REQUEST.pagingState) } @Test @@ -72,7 +72,7 @@ internal class ConnectionApiV0Test : ApiTest() { // given val userId = UserId("user_id", "domain_id") val httpClient = mockAuthenticatedNetworkClient( - CREATE_CONNECTION_RESPONSE.rawJson, + CREATE_CONNECTION_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertJson() @@ -96,13 +96,13 @@ internal class ConnectionApiV0Test : ApiTest() { // given val userId = UserId("user_id", "domain_id") val httpClient = mockAuthenticatedNetworkClient( - CREATE_CONNECTION_RESPONSE.rawJson, + CREATE_CONNECTION_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertJson() assertPut() assertPathEqual("$PATH_CONNECTIONS_ENDPOINT/${userId.domain}/${userId.value}") - assertJsonBodyContent(GET_CONNECTION_STATUS_REQUEST.rawJson) + assertJsonBodyContent(GET_CONNECTION_STATUS_REQUEST.toJsonString()) } ) val connectionApi = ConnectionApiV0(httpClient) @@ -118,10 +118,10 @@ internal class ConnectionApiV0Test : ApiTest() { const val PATH_CONNECTIONS = "/list-connections" const val PATH_CONNECTIONS_ENDPOINT = "/connections" - val GET_CONNECTIONS_RESPONSE = ConnectionResponsesJson.GetConnections.validGetConnections - val CREATE_CONNECTION_RESPONSE = ConnectionResponsesJson.CreateConnectionResponse.jsonProvider - val GET_CONNECTIONS_NO_PAGING_REQUEST = ConnectionRequestsJson.validEmptyBody - val GET_CONNECTIONS_WITH_PAGING_REQUEST = ConnectionRequestsJson.validPagingState - val GET_CONNECTION_STATUS_REQUEST = ConnectionRequestsJson.validConnectionStatusUpdate + val GET_CONNECTIONS_RESPONSE = ConnectionMocks.connectionsResponse + val CREATE_CONNECTION_RESPONSE = ConnectionMocks.connection + val GET_CONNECTIONS_NO_PAGING_REQUEST = ConnectionMocks.emptyPaginationRequest + val GET_CONNECTIONS_WITH_PAGING_REQUEST = ConnectionMocks.paginationRequest + val GET_CONNECTION_STATUS_REQUEST = ConnectionMocks.acceptedConnectionRequest } } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/conversation/ConversationApiV0Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/conversation/ConversationApiV0Test.kt index e3f903200b0..ee9d04dfee4 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/conversation/ConversationApiV0Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/conversation/ConversationApiV0Test.kt @@ -19,11 +19,12 @@ package com.wire.kalium.api.v0.conversation import com.wire.kalium.api.ApiTest +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.conversation.ConversationMocks import com.wire.kalium.mocks.responses.AddServiceResponseJson import com.wire.kalium.mocks.responses.EventContentDTOJson import com.wire.kalium.mocks.responses.EventContentDTOJson.validGenerateGuestRoomLink import com.wire.kalium.mocks.responses.conversation.ConversationDetailsResponse -import com.wire.kalium.mocks.responses.conversation.ConversationListIdsResponseJson import com.wire.kalium.mocks.responses.conversation.ConversationResponseJson import com.wire.kalium.mocks.responses.conversation.CreateConversationRequestJson import com.wire.kalium.mocks.responses.conversation.MemberUpdateRequestJson @@ -103,7 +104,7 @@ internal class ConversationApiV0Test : ApiTest() { @Test fun givenFetchConversationsIds_whenCallingFetchConversations_thenTheRequestShouldBeConfiguredOK() = runTest { val networkClient = mockAuthenticatedNetworkClient( - responseBody = CONVERSATION_IDS_RESPONSE.rawJson, + responseBody = CONVERSATION_IDS_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertPost() @@ -124,7 +125,7 @@ internal class ConversationApiV0Test : ApiTest() { assertion = { assertPost() assertJson() - assertJsonBodyContent(CREATE_CONVERSATION_IDS_REQUEST.rawJson) + assertJsonBodyContent(CREATE_CONVERSATION_IDS_REQUEST.toJsonString()) assertPathEqual(PATH_CONVERSATIONS_LIST_V2) } ) @@ -132,7 +133,7 @@ internal class ConversationApiV0Test : ApiTest() { val conversationApi = ConversationApiV0(networkClient) conversationApi.fetchConversationsListDetails( listOf( - ConversationId("ebafd3d4-1548-49f2-ac4e-b2757e6ca44b", "anta.wire.link"), + ConversationMocks.conversationId, ConversationId("f4680835-2cfe-4d4d-8491-cbb201bd5c2b", "anta.wire.link") ) ) @@ -466,9 +467,9 @@ internal class ConversationApiV0Test : ApiTest() { const val PATH_TYPING_NOTIFICATION = "typing" val CREATE_CONVERSATION_RESPONSE = ConversationResponseJson.v0().rawJson val CREATE_CONVERSATION_REQUEST = CreateConversationRequestJson.v0 - val CREATE_CONVERSATION_IDS_REQUEST = ConversationListIdsResponseJson.validRequestIds + val CREATE_CONVERSATION_IDS_REQUEST = ConversationMocks.conversationsDetailsRequest val UPDATE_ACCESS_ROLE_REQUEST = UpdateConversationAccessRequestJson.v0 - val CONVERSATION_IDS_RESPONSE = ConversationListIdsResponseJson.validGetIds + val CONVERSATION_IDS_RESPONSE = ConversationMocks.conversationListIdsResponse val CONVERSATION_DETAILS_RESPONSE = ConversationDetailsResponse.validGetDetailsForIds val MEMBER_UPDATE_REQUEST = MemberUpdateRequestJson.valid } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/login/LoginApiV0Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/login/LoginApiV0Test.kt index 1da54c1092c..3046d6170c5 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/login/LoginApiV0Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/login/LoginApiV0Test.kt @@ -20,9 +20,9 @@ package com.wire.kalium.api.v0.user.login import com.wire.kalium.api.ApiTest import com.wire.kalium.api.json.model.ErrorResponseJson -import com.wire.kalium.mocks.responses.AccessTokenDTOJson +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.client.TokenMocks import com.wire.kalium.mocks.responses.LoginWithEmailRequestJson -import com.wire.kalium.mocks.responses.UserDTOJson import com.wire.kalium.network.api.model.AccessTokenDTO import com.wire.kalium.network.api.model.QualifiedID import com.wire.kalium.network.api.model.SelfUserDTO @@ -49,7 +49,7 @@ internal class LoginApiV0Test : ApiTest() { fun givenAValidLoginRequest_whenCallingTheLoginEndpoint_theRequestShouldBeConfiguredCorrectly() = runTest { val expectedLoginRequest = TestRequestHandler( path = PATH_LOGIN, - responseBody = VALID_ACCESS_TOKEN_RESPONSE.rawJson, + responseBody = VALID_ACCESS_TOKEN_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertPost() @@ -61,9 +61,9 @@ internal class LoginApiV0Test : ApiTest() { }, headers = mapOf("set-cookie" to "zuid=$refreshToken") ) - val expectedSelfResponse = ApiTest.TestRequestHandler( + val expectedSelfResponse = TestRequestHandler( path = PATH_SELF, - responseBody = VALID_SELF_RESPONSE.rawJson, + responseBody = VALID_SELF_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertGet() @@ -74,9 +74,9 @@ internal class LoginApiV0Test : ApiTest() { val networkClient = mockUnauthenticatedNetworkClient( listOf(expectedLoginRequest, expectedSelfResponse) ) - val expected = with(VALID_ACCESS_TOKEN_RESPONSE.serializableData) { + val expected = with(VALID_ACCESS_TOKEN_RESPONSE) { SessionDTO( - userId = VALID_SELF_RESPONSE.serializableData.id, + userId = VALID_SELF_RESPONSE.id, accessToken = value, tokenType = tokenType, refreshToken = refreshToken, @@ -106,13 +106,13 @@ internal class LoginApiV0Test : ApiTest() { @Test fun givenLoginRequestSuccessAndSelfInfoFail_thenExceptionIsPropagated() = runTest { - val expectedLoginRequest = ApiTest.TestRequestHandler( + val expectedLoginRequest = TestRequestHandler( path = PATH_LOGIN, - responseBody = VALID_ACCESS_TOKEN_RESPONSE.rawJson, + responseBody = VALID_ACCESS_TOKEN_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, headers = mapOf("set-cookie" to "zuid=$refreshToken") ) - val expectedSelfResponse = ApiTest.TestRequestHandler( + val expectedSelfResponse = TestRequestHandler( path = PATH_SELF, responseBody = ErrorResponseJson.valid.rawJson, statusCode = HttpStatusCode.BadRequest @@ -157,8 +157,8 @@ internal class LoginApiV0Test : ApiTest() { ssoID = null, supportedProtocols = null ) - val VALID_ACCESS_TOKEN_RESPONSE = AccessTokenDTOJson.createValid(accessTokenDto) - val VALID_SELF_RESPONSE = UserDTOJson.createValid(userDTO) + val VALID_ACCESS_TOKEN_RESPONSE = accessTokenDto + val VALID_SELF_RESPONSE = userDTO val LOGIN_WITH_EMAIL_REQUEST = LoginWithEmailRequestJson.validLoginWithEmail val ERROR_RESPONSE = ErrorResponseJson.valid.serializableData diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/login/SSOLoginApiV0Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/login/SSOLoginApiV0Test.kt index 904223b9343..3e992549b99 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/login/SSOLoginApiV0Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/login/SSOLoginApiV0Test.kt @@ -20,11 +20,12 @@ package com.wire.kalium.api.v0.user.login import com.wire.kalium.api.ApiTest import com.wire.kalium.api.TEST_BACKEND -import com.wire.kalium.mocks.responses.AccessTokenDTOJson -import com.wire.kalium.mocks.responses.UserDTOJson +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.client.TokenMocks +import com.wire.kalium.mocks.mocks.user.UserMocks +import com.wire.kalium.network.api.base.unauthenticated.sso.SSOLoginApi import com.wire.kalium.network.api.model.AuthenticationResultDTO import com.wire.kalium.network.api.unauthenticated.sso.InitiateParam -import com.wire.kalium.network.api.base.unauthenticated.sso.SSOLoginApi import com.wire.kalium.network.api.v0.unauthenticated.SSOLoginApiV0 import com.wire.kalium.network.utils.CustomErrors import com.wire.kalium.network.utils.NetworkResponse @@ -32,13 +33,11 @@ import io.ktor.http.HttpHeaders import io.ktor.http.HttpStatusCode import io.ktor.http.Url import io.ktor.http.protocolWithAuthority -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertIs -@OptIn(ExperimentalCoroutinesApi::class) internal class SSOLoginApiV0Test : ApiTest() { @Test @@ -107,13 +106,13 @@ internal class SSOLoginApiV0Test : ApiTest() { @Test fun givenBEResponseSuccess_whenFetchingAuthToken_thenTheRefreshTokenIsClean() = runTest { val cookie = "zuid=cookie" - val authResponse = AccessTokenDTOJson.valid - val selfResponse = UserDTOJson.valid + val authResponse = TokenMocks.accessToken + val selfResponse = UserMocks.selfUser val networkClient = mockUnauthenticatedNetworkClient( listOf( - ApiTest.TestRequestHandler( + TestRequestHandler( path = PATH_ACCESS, - authResponse.rawJson, + authResponse.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertGet() @@ -121,9 +120,9 @@ internal class SSOLoginApiV0Test : ApiTest() { assertPathEqual(PATH_ACCESS) } ), - ApiTest.TestRequestHandler( + TestRequestHandler( path = PATH_SELF, - selfResponse.rawJson, + selfResponse.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertGet() @@ -137,21 +136,21 @@ internal class SSOLoginApiV0Test : ApiTest() { assertIs>(actual) assertEquals(cookie.removePrefix("zuid="), actual.value.sessionDTO.refreshToken) - assertEquals(authResponse.serializableData.value, actual.value.sessionDTO.accessToken) - assertEquals(authResponse.serializableData.tokenType, actual.value.sessionDTO.tokenType) - assertEquals(selfResponse.serializableData.id, actual.value.sessionDTO.userId) - assertEquals(selfResponse.serializableData, actual.value.userDTO) + assertEquals(authResponse.value, actual.value.sessionDTO.accessToken) + assertEquals(authResponse.tokenType, actual.value.sessionDTO.tokenType) + assertEquals(selfResponse.id, actual.value.sessionDTO.userId) + assertEquals(selfResponse, actual.value.userDTO) } @Test fun cookieIsMissingZuidToke_whenFetchingAuthToken_thenReturnError() = runTest { val cookie = "cookie" - val authResponse = AccessTokenDTOJson.valid + val authResponse = TokenMocks.accessToken val networkClient = mockUnauthenticatedNetworkClient( listOf( - ApiTest.TestRequestHandler( + TestRequestHandler( path = PATH_ACCESS, - authResponse.rawJson, + authResponse.toJsonString(), statusCode = HttpStatusCode.OK ) ) diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/register/RegisterApiV0Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/register/RegisterApiV0Test.kt index 25fc8e33984..0116020a95e 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/register/RegisterApiV0Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/register/RegisterApiV0Test.kt @@ -20,10 +20,11 @@ package com.wire.kalium.api.v0.user.register import com.wire.kalium.api.ApiTest import com.wire.kalium.api.json.model.ErrorResponseJson +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.user.UserMocks import com.wire.kalium.mocks.responses.ActivationRequestJson import com.wire.kalium.mocks.responses.RegisterAccountJson import com.wire.kalium.mocks.responses.RequestActivationCodeJson -import com.wire.kalium.mocks.responses.UserDTOJson import io.ktor.http.HttpStatusCode import kotlinx.coroutines.test.runTest import kotlin.test.Ignore @@ -36,7 +37,7 @@ internal class RegisterApiV0Test : ApiTest() { @Test fun givenAValidEmail_whenRegisteringAccountWithEMail_theRequestShouldBeConfiguredCorrectly() = runTest { val networkClient = mockUnauthenticatedNetworkClient( - VALID_REGISTER_RESPONSE.rawJson, + VALID_REGISTER_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertPost() @@ -170,7 +171,7 @@ internal class RegisterApiV0Test : ApiTest() { private companion object { val VALID_PERSONAL_ACCOUNT_REQUEST = RegisterAccountJson.validPersonalAccountRegister - val VALID_REGISTER_RESPONSE = UserDTOJson.valid + val VALID_REGISTER_RESPONSE = UserMocks.selfUser val VALID_SEND_ACTIVATE_EMAIL = RequestActivationCodeJson.validActivateEmail val VALID_ACTIVATE_EMAIL = ActivationRequestJson.validActivateEmail val ERROR_RESPONSE = ErrorResponseJson.valid diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/self/SelfApiV0Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/self/SelfApiV0Test.kt index d55565a5234..2af47d29ff4 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/self/SelfApiV0Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v0/user/self/SelfApiV0Test.kt @@ -20,7 +20,8 @@ package com.wire.kalium.api.v0.user.self import com.wire.kalium.api.ApiTest import com.wire.kalium.api.json.model.ErrorResponseJson -import com.wire.kalium.mocks.responses.UserDTOJson +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.user.UserMocks import com.wire.kalium.network.api.model.SupportedProtocolDTO import com.wire.kalium.network.api.v0.authenticated.SelfApiV0 import com.wire.kalium.network.exceptions.KaliumException @@ -40,7 +41,7 @@ internal class SelfApiV0Test : ApiTest() { fun givenAValidRegisterLogoutRequest_whenCallingTheRegisterLogoutEndpoint_theRequestShouldBeConfiguredCorrectly() = runTest { val networkClient = mockAuthenticatedNetworkClient( - VALID_SELF_RESPONSE.rawJson, + VALID_SELF_RESPONSE.toJsonString(), statusCode = HttpStatusCode.Created, assertion = { assertGet() @@ -51,7 +52,7 @@ internal class SelfApiV0Test : ApiTest() { val selfApi = SelfApiV0(networkClient, TEST_SESSION_MANAGER) val response = selfApi.getSelfInfo() assertTrue(response.isSuccessful()) - assertEquals(response.value, VALID_SELF_RESPONSE.serializableData) + assertEquals(response.value, VALID_SELF_RESPONSE) } @Test @@ -135,7 +136,7 @@ internal class SelfApiV0Test : ApiTest() { private companion object { const val PATH_SELF = "/self" - val VALID_SELF_RESPONSE = UserDTOJson.valid + val VALID_SELF_RESPONSE = UserMocks.selfUser val ERROR_RESPONSE = ErrorResponseJson.valid.serializableData } } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v2/AssetApiV2Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v2/AssetApiV2Test.kt index b5ee2f4f576..fd87882f5ec 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v2/AssetApiV2Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v2/AssetApiV2Test.kt @@ -19,9 +19,10 @@ package com.wire.kalium.api.v2 import com.wire.kalium.api.ApiTest -import com.wire.kalium.mocks.responses.asset.AssetUploadResponseJson -import com.wire.kalium.network.api.base.authenticated.asset.AssetApi +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.asset.AssetMocks import com.wire.kalium.network.api.authenticated.asset.AssetMetadataRequest +import com.wire.kalium.network.api.base.authenticated.asset.AssetApi import com.wire.kalium.network.api.model.AssetId import com.wire.kalium.network.api.model.AssetRetentionType import com.wire.kalium.network.api.model.UserId @@ -31,7 +32,6 @@ import com.wire.kalium.network.utils.NetworkResponse import com.wire.kalium.network.utils.isSuccessful import io.ktor.http.HttpStatusCode import io.ktor.utils.io.ByteReadChannel -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import okio.Path.Companion.toPath import okio.Source @@ -41,7 +41,6 @@ import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertTrue -@OptIn(ExperimentalCoroutinesApi::class) internal class AssetApiV2Test : ApiTest() { private val userId: UserId = UserId("user_id", "domain") @@ -54,7 +53,7 @@ internal class AssetApiV2Test : ApiTest() { val encryptedData = "some-data".encodeToByteArray() val encryptedDataSource = { getDummyDataSource(fileSystem, encryptedData) } val networkClient = mockAuthenticatedNetworkClient( - VALID_ASSET_UPLOAD_RESPONSE.rawJson, + VALID_ASSET_UPLOAD_RESPONSE.toJsonString(), statusCode = HttpStatusCode.Created, assertion = { assertPost() @@ -70,7 +69,7 @@ internal class AssetApiV2Test : ApiTest() { // Then assertTrue(response.isSuccessful()) - assertEquals(response.value, VALID_ASSET_UPLOAD_RESPONSE.serializableData) + assertEquals(response.value, VALID_ASSET_UPLOAD_RESPONSE) } @Test @@ -81,7 +80,7 @@ internal class AssetApiV2Test : ApiTest() { val encryptedData = "some-data".encodeToByteArray() val encryptedDataSource = { getDummyDataSource(fileSystem, encryptedData) } val networkClient = mockAuthenticatedNetworkClient( - INVALID_ASSET_UPLOAD_RESPONSE.rawJson, + INVALID_ASSET_UPLOAD_RESPONSE.toJsonString(), statusCode = HttpStatusCode.BadRequest, assertion = { assertPost() @@ -161,8 +160,8 @@ internal class AssetApiV2Test : ApiTest() { const val ASSET_KEY = "3-1-e7788668-1b22-488a-b63c-acede42f771f" const val ASSET_DOMAIN = "wire.com" const val ASSET_TOKEN = "assetToken" - val VALID_ASSET_UPLOAD_RESPONSE = AssetUploadResponseJson.valid - val INVALID_ASSET_UPLOAD_RESPONSE = AssetUploadResponseJson.invalid + val VALID_ASSET_UPLOAD_RESPONSE = AssetMocks.asset + val INVALID_ASSET_UPLOAD_RESPONSE = AssetMocks.invalid val assetId: AssetId = AssetId(ASSET_KEY, ASSET_DOMAIN) val tempFileSink = blackholeSink() } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v2/ConversationApiV2Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v2/ConversationApiV2Test.kt index e60bd61a637..4daea7c82fd 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v2/ConversationApiV2Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v2/ConversationApiV2Test.kt @@ -19,9 +19,10 @@ package com.wire.kalium.api.v2 import com.wire.kalium.api.ApiTest +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.conversation.ConversationMocks import com.wire.kalium.mocks.responses.EventContentDTOJson import com.wire.kalium.mocks.responses.conversation.ConversationDetailsResponse -import com.wire.kalium.mocks.responses.conversation.ConversationListIdsResponseJson import com.wire.kalium.network.api.authenticated.conversation.AddConversationMembersRequest import com.wire.kalium.network.api.authenticated.conversation.ReceiptMode import com.wire.kalium.network.api.model.ConversationId @@ -43,7 +44,7 @@ internal class ConversationApiV2Test : ApiTest() { assertion = { assertPost() assertJson() - assertJsonBodyContent(CREATE_CONVERSATION_IDS_REQUEST.rawJson) + assertJsonBodyContent(CREATE_CONVERSATION_IDS_REQUEST.toJsonString()) assertPathEqual(PATH_CONVERSATIONS_LIST) } ) @@ -51,7 +52,7 @@ internal class ConversationApiV2Test : ApiTest() { val conversationApi = ConversationApiV2(networkClient) conversationApi.fetchConversationsListDetails( listOf( - ConversationId("ebafd3d4-1548-49f2-ac4e-b2757e6ca44b", "anta.wire.link"), + ConversationMocks.conversationId, ConversationId("f4680835-2cfe-4d4d-8491-cbb201bd5c2b", "anta.wire.link") ) ) @@ -94,7 +95,7 @@ internal class ConversationApiV2Test : ApiTest() { const val PATH_CONVERSATIONS_LIST = "/conversations/list" const val PATH_CONVERSATIONS = "/conversations" const val PATH_MEMBERS = "members" - val CREATE_CONVERSATION_IDS_REQUEST = ConversationListIdsResponseJson.validRequestIds + val CREATE_CONVERSATION_IDS_REQUEST = ConversationMocks.conversationsDetailsRequest val CONVERSATION_DETAILS_RESPONSE = ConversationDetailsResponse.validGetDetailsForIds } } diff --git a/network/src/commonTest/kotlin/com/wire/kalium/api/v4/ConnectionApiV4Test.kt b/network/src/commonTest/kotlin/com/wire/kalium/api/v4/ConnectionApiV4Test.kt index 0227b9d0807..e0cbfb4766d 100644 --- a/network/src/commonTest/kotlin/com/wire/kalium/api/v4/ConnectionApiV4Test.kt +++ b/network/src/commonTest/kotlin/com/wire/kalium/api/v4/ConnectionApiV4Test.kt @@ -20,7 +20,8 @@ package com.wire.kalium.api.v4 import com.wire.kalium.api.ApiTest import com.wire.kalium.api.json.model.ErrorResponseJson -import com.wire.kalium.mocks.responses.connection.ConnectionResponsesJson +import com.wire.kalium.mocks.extensions.toJsonString +import com.wire.kalium.mocks.mocks.connection.ConnectionMocks import com.wire.kalium.network.api.model.ErrorResponse import com.wire.kalium.network.api.model.UserId import com.wire.kalium.network.api.v4.authenticated.ConnectionApiV4 @@ -40,7 +41,7 @@ internal class ConnectionApiV4Test : ApiTest() { // given val userId = UserId("user_id", "domain_id") val httpClient = mockAuthenticatedNetworkClient( - CREATE_CONNECTION_RESPONSE.rawJson, + CREATE_CONNECTION_RESPONSE.toJsonString(), statusCode = HttpStatusCode.OK, assertion = { assertJson() @@ -93,6 +94,6 @@ internal class ConnectionApiV4Test : ApiTest() { private companion object { const val PATH_CONNECTIONS_ENDPOINT = "/connections" - val CREATE_CONNECTION_RESPONSE = ConnectionResponsesJson.CreateConnectionResponse.jsonProvider + val CREATE_CONNECTION_RESPONSE = ConnectionMocks.connection } } diff --git a/tango-tests/build.gradle.kts b/tango-tests/build.gradle.kts index fbf70768876..9354918570d 100644 --- a/tango-tests/build.gradle.kts +++ b/tango-tests/build.gradle.kts @@ -32,6 +32,7 @@ kotlin { implementation(project(":logic")) implementation(project(":persistence")) implementation(project(":mocks")) + implementation(project(":cryptography")) implementation(libs.kotlin.test) implementation(libs.settings.kmpTest) diff --git a/tango-tests/src/integrationTest/kotlin/PocIntegrationTest.kt b/tango-tests/src/integrationTest/kotlin/PocIntegrationTest.kt index 6e865ff85ae..ffcc205ca7a 100644 --- a/tango-tests/src/integrationTest/kotlin/PocIntegrationTest.kt +++ b/tango-tests/src/integrationTest/kotlin/PocIntegrationTest.kt @@ -21,20 +21,38 @@ import action.ClientActions import action.LoginActions import com.wire.kalium.logic.CoreLogic import com.wire.kalium.logic.configuration.server.ServerConfig +import com.wire.kalium.logic.data.event.EventGenerator +import com.wire.kalium.logic.data.id.ConversationId +import com.wire.kalium.logic.data.id.QualifiedClientID import com.wire.kalium.logic.data.logout.LogoutReason +import com.wire.kalium.logic.data.user.UserId +import com.wire.kalium.logic.feature.UserSessionScope import com.wire.kalium.logic.feature.auth.AuthenticationScope import com.wire.kalium.logic.feature.auth.autoVersioningAuth.AutoVersionAuthScopeUseCase import com.wire.kalium.logic.featureFlags.KaliumConfigs +import com.wire.kalium.logic.functional.getOrFail +import com.wire.kalium.logic.util.TimeLogger +import com.wire.kalium.mocks.mocks.conversation.ConversationMocks import com.wire.kalium.mocks.requests.ACMERequests import com.wire.kalium.mocks.requests.ClientRequests +import com.wire.kalium.mocks.requests.ConnectionRequests +import com.wire.kalium.mocks.requests.ConversationRequests import com.wire.kalium.mocks.requests.FeatureConfigRequests import com.wire.kalium.mocks.requests.LoginRequests +import com.wire.kalium.mocks.requests.NotificationRequests +import com.wire.kalium.mocks.requests.PreKeyRequests import com.wire.kalium.network.NetworkState +import com.wire.kalium.network.api.authenticated.notification.NotificationResponse import com.wire.kalium.network.api.unbound.configuration.ServerConfigDTO import com.wire.kalium.network.utils.TestRequestHandler import com.wire.kalium.network.utils.TestRequestHandler.Companion.TEST_BACKEND_CONFIG +import kotlinx.coroutines.flow.first +import kotlinx.coroutines.flow.toList import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest +import kotlinx.datetime.Clock +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json import org.junit.Ignore import org.junit.Test @@ -74,6 +92,10 @@ class PocIntegrationTest { addAll(LoginRequests.loginRequestResponseSuccess) addAll(ClientRequests.clientRequestResponseSuccess) addAll(FeatureConfigRequests.responseSuccess) + addAll(NotificationRequests.notificationsRequestResponseSuccess) + addAll(ConversationRequests.conversationsRequestResponseSuccess) + addAll(ConnectionRequests.connectionRequestResponseSuccess()) + addAll(PreKeyRequests.preKeyRequestResponseSuccess) } val coreLogic = createCoreLogic(mockedRequests) @@ -90,19 +112,92 @@ class PocIntegrationTest { authScope = authScope ) - val userSessionScope = ClientActions.registerClient( + val userSession = ClientActions.registerClient( password = USER_PASSWORD, userId = loginAuthToken.userId, coreLogic = coreLogic ) - val x = userSessionScope.client.fetchSelfClients() - println(x.toString()) + userSession.logout.invoke(LogoutReason.SELF_SOFT_LOGOUT) + } + } + + @Test + fun givenUserWhenHandlingTextMessagesThenProcessShouldSucceed() = runTest { + val mockedRequests = mutableListOf().apply { + addAll(LoginRequests.loginRequestResponseSuccess) + addAll(ClientRequests.clientRequestResponseSuccess) + addAll(FeatureConfigRequests.responseSuccess) + addAll(NotificationRequests.notificationsRequestResponseSuccess) + addAll(ConversationRequests.conversationsRequestResponseSuccess) + addAll(ConnectionRequests.connectionRequestResponseSuccess()) + addAll(PreKeyRequests.preKeyRequestResponseSuccess) + } + + TestNetworkStateObserver.DEFAULT_TEST_NETWORK_STATE_OBSERVER.updateNetworkState(NetworkState.ConnectedWithInternet) + + launch { + val userSession = initUserSession(createCoreLogic(mockedRequests)) + + val selfUserId = userSession.users.getSelfUser().first().id + val selfClientId = userSession.clientIdProvider().getOrFail { throw IllegalStateException("No self client is registered") } + val targetUserId = UserId(value = selfUserId.value, domain = selfUserId.domain) + + userSession.debug.breakSession(selfUserId, selfClientId) - userSessionScope.logout.invoke(LogoutReason.SELF_SOFT_LOGOUT) + userSession.debug.establishSession( + userId = targetUserId, + clientId = selfClientId + ) + val generator = EventGenerator( + selfClient = QualifiedClientID( + clientId = selfClientId, + userId = selfUserId + ), + targetClient = QualifiedClientID( + clientId = selfClientId, + userId = targetUserId + ), + proteusClient = userSession.proteusClientProvider.getOrCreate() + ) + + val events = generator.generateEvents( + limit = 1000, + conversationId = ConversationId(ConversationMocks.conversationId.value, ConversationMocks.conversationId.domain), + ) + + val response = NotificationResponse( + time = Clock.System.now().toString(), + hasMore = false, + notifications = events.toList() + ) + + val encodedData = json.encodeToString(response) + + val logger = TimeLogger("entire process") + logger.start() + userSession.debug.synchronizeExternalData(encodedData) + logger.finish() } } + private suspend fun initUserSession(coreLogic: CoreLogic): UserSessionScope { + val authScope = getAuthScope(coreLogic, TEST_BACKEND_CONFIG.links) + + val loginAuthToken = LoginActions.loginAndAddAuthenticatedUser( + email = USER_EMAIL, + password = USER_PASSWORD, + coreLogic = coreLogic, + authScope = authScope + ) + + return ClientActions.registerClient( + password = USER_PASSWORD, + userId = loginAuthToken.userId, + coreLogic = coreLogic + ) + } + private suspend fun getAuthScope(coreLogic: CoreLogic, backend: ServerConfigDTO.Links): AuthenticationScope { val result = coreLogic.versionedAuthenticationScope( ServerConfig.Links( @@ -127,6 +222,9 @@ class PocIntegrationTest { private val HOME_DIRECTORY: String = System.getProperty("user.home") private val USER_EMAIL = "user@domain.com" private val USER_PASSWORD = "password" + private var json = Json { + prettyPrint = true + } fun createCoreLogic(mockedRequests: List) = CoreLogic( rootPath = "$HOME_DIRECTORY/.kalium/accounts-test", @@ -137,7 +235,8 @@ class PocIntegrationTest { wipeOnDeviceRemoval = true, mockedRequests = mockedRequests, mockNetworkStateObserver = TestNetworkStateObserver.DEFAULT_TEST_NETWORK_STATE_OBSERVER, - enableCalling = false + enableCalling = false, + mockedWebSocket = true ), userAgent = "Wire Integration Tests" )