Skip to content

Commit

Permalink
fix: Asset message resend transfer status #WPB-11035
Browse files Browse the repository at this point in the history
  • Loading branch information
m-zagorski committed Oct 15, 2024
1 parent 0bc15da commit aa3699e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,10 @@ class RetryFailedMessageUseCase internal constructor(

else -> handleError("Asset message with transfer status $assetTransferStatus cannot be retried")
}
.onSuccess { retrySendingMessage(it) }
.onSuccess {
updateAssetMessageTransferStatus(AssetTransferStatus.UPLOADED, message.conversationId, message.id)
retrySendingMessage(it)
}
.map { /* returns Unit */ }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit aa3699e

Please sign in to comment.