Skip to content

Commit

Permalink
Inject siteStore in constructor
Browse files Browse the repository at this point in the history
Also fix tests
  • Loading branch information
jhnstn committed Jan 16, 2024
1 parent b246b84 commit 825e67e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ class RetryFailedMediaUploadUseCase @Inject constructor(
private val getMediaModelUseCase: GetMediaModelUseCase,
private val updateMediaModelUseCase: UpdateMediaModelUseCase,
private val uploadMediaUseCase: UploadMediaUseCase,
private val tracker: AnalyticsTrackerWrapper
private val tracker: AnalyticsTrackerWrapper,
private val siteStore: SiteStore
) {
@Inject
lateinit var siteStore: SiteStore
suspend fun retryFailedMediaAsync(
editorMediaListener: EditorMediaListener,
failedMediaLocalIds: List<Int>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import org.wordpress.android.analytics.AnalyticsTracker.Stat
import org.wordpress.android.fluxc.model.MediaModel
import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState
import org.wordpress.android.fluxc.model.MediaModel.MediaUploadState.QUEUED
import org.wordpress.android.fluxc.model.PostImmutableModel
import org.wordpress.android.fluxc.store.SiteStore
import org.wordpress.android.util.analytics.AnalyticsTrackerWrapper

@ExperimentalCoroutinesApi
Expand All @@ -29,8 +31,9 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
val getMediaModelUseCase = createGetMediaModelUseCase()
val useCase = createUseCase(getMediaModelUseCase = getMediaModelUseCase)


// Act
useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS)
useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS)
// Assert
verify(getMediaModelUseCase).loadMediaByLocalId(FAILED_MEDIA_IDS)
}
Expand All @@ -42,7 +45,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
val useCase = createUseCase(updateMediaModelUseCase = updateMediaModelUseCase)

// Act
useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS)
useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS)

// Assert
verify(updateMediaModelUseCase, times(FAILED_MEDIA_IDS.size)).updateMediaModel(
Expand All @@ -59,7 +62,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
val useCase = createUseCase(uploadMediaUseCase = uploadMediaUseCase)

// Act
useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS)
useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS)

// Assert
verify(uploadMediaUseCase).saveQueuedPostAndStartUpload(
Expand All @@ -74,7 +77,7 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
val trackerWrapper: AnalyticsTrackerWrapper = mock()
val useCase = createUseCase(tracker = trackerWrapper)
// Act
useCase.retryFailedMediaAsync(mock(), FAILED_MEDIA_IDS)
useCase.retryFailedMediaAsync(createEditorMediaListener(), FAILED_MEDIA_IDS)
// Assert
verify(trackerWrapper).track(Stat.EDITOR_UPLOAD_MEDIA_RETRIED)
}
Expand Down Expand Up @@ -112,13 +115,15 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
getMediaModelUseCase: GetMediaModelUseCase = createGetMediaModelUseCase(),
updateMediaModelUseCase: UpdateMediaModelUseCase = mock(),
uploadMediaUseCase: UploadMediaUseCase = mock(),
tracker: AnalyticsTrackerWrapper = mock()
tracker: AnalyticsTrackerWrapper = mock(),
siteStore: SiteStore = mock()
): RetryFailedMediaUploadUseCase {
return RetryFailedMediaUploadUseCase(
getMediaModelUseCase,
updateMediaModelUseCase,
uploadMediaUseCase,
tracker
tracker,
siteStore
)
}

Expand All @@ -136,5 +141,13 @@ class RetryFailedMediaUploadUseCaseTest : BaseUnitTest() {
this.id = mediaModelId
this.uploadState = MediaUploadState.FAILED.name
}

fun createEditorMediaListener() = mock<EditorMediaListener> {
on { getImmutablePost() } doAnswer {
mock<PostImmutableModel> {
on { localSiteId } doAnswer { 0 }
}
}
}
}
}

0 comments on commit 825e67e

Please sign in to comment.