From 3528f012eca61b0e0c3b570b028f640eb6b2b4c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Zag=C3=B3rski?= Date: Wed, 30 Oct 2024 13:38:04 +0100 Subject: [PATCH] fix: Asset message resend transfer status #WPB-11035 (#3063) * fix: Asset message resend transfer status #WPB-11035 * Code review --- .../message/RetryFailedMessageUseCase.kt | 1 + .../message/RetryFailedMessageUseCaseTest.kt | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCase.kt index 1d11875af16..0f85600dd07 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCase.kt @@ -160,6 +160,7 @@ class RetryFailedMessageUseCase internal constructor( .map { updatedMessage } // we need to persist new asset remoteData and status } } + .onSuccess { updateAssetMessageTransferStatus(AssetTransferStatus.UPLOADED, message.conversationId, message.id) } .onFailure { kaliumLogger.e("Failed to retry sending asset message. Failure = $it") updateAssetMessageTransferStatus(AssetTransferStatus.FAILED_UPLOAD, message.conversationId, message.id) diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCaseTest.kt index 998ca1eaa0a..885b586b299 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/message/RetryFailedMessageUseCaseTest.kt @@ -159,6 +159,38 @@ class RetryFailedMessageUseCaseTest { }.wasInvoked(exactly = once) } + @Test + fun givenAValidFailedAndNotUploadedAssetMessage_whenSuccessfullyUploadedAsset_thenAssetTransferShouldBeChangedToUploaded() = + runTest(testDispatcher.default) { + // given + val name = "some_asset.txt" + val content = MessageContent.Asset(ASSET_CONTENT.value.copy(name = name)) + val path = fakeKaliumFileSystem.providePersistentAssetPath(name) + val message = assetMessage().copy(content = content, status = Message.Status.Failed) + val uploadedAssetId = UploadedAssetId("remote_key", "remote_domain", "remote_token") + val uploadedAssetSha = SHA256Key(byteArrayOf()) + val (arrangement, useCase) = Arrangement() + .withGetMessageById(Either.Right(message)) + .withUpdateMessageStatus(Either.Right(Unit)) + .withUpdateAssetMessageTransferStatus(UpdateTransferStatusResult.Success) + .withFetchPrivateDecodedAsset(Either.Right(path)) + .withStoredData(mockedLongAssetData(), path) + .withGetAssetMessageTransferStatus(AssetTransferStatus.FAILED_UPLOAD) + .withUploadAndPersistPrivateAsset(Either.Right(uploadedAssetId to uploadedAssetSha)) + .withPersistMessage(Either.Right(Unit)) + .withSendMessage(Either.Right(Unit)) + .arrange() + + // when + useCase.invoke(message.id, message.conversationId) + advanceUntilIdle() + + // then + coVerify { + arrangement.updateAssetMessageTransferStatus.invoke(AssetTransferStatus.UPLOADED, message.conversationId, message.id) + }.wasInvoked(exactly = once) + } + @Test fun givenAValidFailedAndNotUploadedAssetMessage_whenRetryingFailedMessage_thenUploadAssetAndSendAMessageWithProperAssetRemoteData() = runTest(testDispatcher.default) {