Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Asset message resend transfer status #WPB-11035 #3063

Open
wants to merge 1 commit into
base: release/candidate
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: should the status be changed to UPLOADED before the message is actually uploaded? Maybe UPLOAD_IN_PROGRESS would be more appropriate and change to UPLOADED only after the successful resend 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that - but isnt that status only regarding the asset? We have the additional status for message PENDING etc. Also if we set up this status like that, we can see:

  • Error sending
  • Uploading
  • Uploaded
  • Message pending (until its sent)
  • If there will be any connection problem the message will get back to failed state

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
Loading