Skip to content

Commit

Permalink
NTV-399 Reply comments created with invalid commentable (#1549)
Browse files Browse the repository at this point in the history
* Fix deeplink commentable id

* increase deeplink delay

* Update test delay time

* Fix test

Co-authored-by: Isabel Martin <arkariang@gmail.com>
  • Loading branch information
hadia and Arkariang committed Feb 25, 2022
1 parent 4806933 commit 94934a9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
20 changes: 11 additions & 9 deletions app/src/main/java/com/kickstarter/viewmodels/CommentsViewModel.kt
Expand Up @@ -115,7 +115,7 @@ interface CommentsViewModel {
private val initialError = BehaviorSubject.create<Throwable>()
private val paginationError = BehaviorSubject.create<Throwable>()
private val pullToRefreshError = BehaviorSubject.create<Throwable>()
private var commentableId: String? = null
private var commentableId = BehaviorSubject.create<String?>()

private val isFetchingComments = BehaviorSubject.create<Boolean>()
private lateinit var project: Project
Expand Down Expand Up @@ -220,16 +220,17 @@ interface CommentsViewModel {
}

deepLinkCommentableId
.compose(Transformers.takeWhen(projectOrUpdateComment))
.compose(takePairWhen(projectOrUpdateComment))
.switchMap {
return@switchMap apolloClient.getComment(it)
return@switchMap apolloClient.getComment(it.first)
}.compose(Transformers.neverError())
.compose(combineLatestPair(deepLinkCommentableId))
.compose(combineLatestPair(commentableId))
.map {
CommentCardData.builder()
.comment(it.first)
.comment(it.first.first)
.project(this.project)
.commentCardState(it.first.cardStatus())
.commentCardState(it.first.first.cardStatus())
.commentableId(it.second)
.build()
}.withLatestFrom(projectOrUpdateComment) { commentData, projectOrUpdate ->
Expand All @@ -254,13 +255,14 @@ interface CommentsViewModel {
commentData, project ->
Pair(commentData, project)
}
.compose(combineLatestPair(commentableId))
.map {
Pair(
it.first.first,
CommentCardData.builder()
.comment(it.first.second)
.project(it.second)
.commentableId(commentableId)
.comment(it.first.first.second)
.project(it.first.second)
.commentableId(it.second)
.commentCardState(CommentCardStatus.TRYING_TO_POST.commentCardStatus)
.build()
)
Expand Down Expand Up @@ -488,7 +490,7 @@ interface CommentsViewModel {
apolloClient.getProjectComments(it.first?.slug() ?: "", cursor)
}
}.doOnNext {
commentableId = it.commentableId
commentableId.onNext(it.commentableId)
// Remove Pagination errorFrom View
this.displayPaginationError.onNext(false)
this.displayInitialError.onNext(false)
Expand Down
Expand Up @@ -544,7 +544,7 @@ interface ProjectPageViewModel {

intent()
.take(1)
.delay(1, TimeUnit.SECONDS, environment.scheduler()) // add delay to wait until activity subscribed to viewmodel
.delay(3, TimeUnit.SECONDS, environment.scheduler()) // add delay to wait until activity subscribed to viewmodel
.filter {
it.getBooleanExtra(IntentKey.DEEP_LINK_SCREEN_PROJECT_COMMENT, false) &&
it.getStringExtra(IntentKey.COMMENT)?.isEmpty() ?: true
Expand All @@ -559,7 +559,7 @@ interface ProjectPageViewModel {

intent()
.take(1)
.delay(1, TimeUnit.SECONDS, environment.scheduler()) // add delay to wait until activity subscribed to viewmodel
.delay(3, TimeUnit.SECONDS, environment.scheduler()) // add delay to wait until activity subscribed to viewmodel
.filter {
it.getBooleanExtra(IntentKey.DEEP_LINK_SCREEN_PROJECT_COMMENT, false) &&
it.getStringExtra(IntentKey.COMMENT)?.isNotEmpty() ?: false
Expand All @@ -574,7 +574,7 @@ interface ProjectPageViewModel {

intent()
.take(1)
.delay(1, TimeUnit.SECONDS, environment.scheduler()) // add delay to wait until activity subscribed to viewmodel
.delay(3, TimeUnit.SECONDS, environment.scheduler()) // add delay to wait until activity subscribed to viewmodel
.filter {
it.getStringExtra(IntentKey.DEEP_LINK_SCREEN_PROJECT_UPDATE)?.isNotEmpty() ?: false &&
it.getStringExtra(IntentKey.COMMENT)?.isEmpty() ?: true
Expand All @@ -594,7 +594,7 @@ interface ProjectPageViewModel {

intent()
.take(1)
.delay(1, TimeUnit.SECONDS, environment.scheduler()) // add delay to wait until activity subscribed to viewmodel
.delay(3, TimeUnit.SECONDS, environment.scheduler()) // add delay to wait until activity subscribed to viewmodel
.filter {
it.getStringExtra(IntentKey.DEEP_LINK_SCREEN_PROJECT_UPDATE)?.isNotEmpty() ?: false &&
it.getStringExtra(IntentKey.COMMENT)?.isNotEmpty() ?: false
Expand Down
Expand Up @@ -801,7 +801,8 @@ class CommentsViewModelTest : KSRobolectricTestCase() {

@Test
fun testCommentsViewModel_deepLink_to_ThreadActivity() {
val commentableId = "Q29tbWVudC0zMzU2MTY4Ng"
val commentID = "Q29tbWVudC0zMzU2MTY4Ng"
val commentableId = "RnJlZWZvcm1Qb3N0LTM0MTQ2ODk="

val currentUser = UserFactory.user()
.toBuilder()
Expand All @@ -817,6 +818,13 @@ class CommentsViewModelTest : KSRobolectricTestCase() {
override fun getComment(commentableId: String): Observable<Comment> {
return Observable.just(comment1)
}
override fun getProjectComments(slug: String, cursor: String?, limit: Int): Observable<CommentEnvelope> {
return Observable.just(
CommentEnvelopeFactory.commentsEnvelope().toBuilder().commentableId(commentableId).comments(
listOf(comment1)
).build()
)
}
}).currentUser(MockCurrentUser(currentUser))
.scheduler(testScheduler)
.build()
Expand All @@ -827,13 +835,13 @@ class CommentsViewModelTest : KSRobolectricTestCase() {

vm.intent(
Intent().apply {
putExtra(IntentKey.COMMENT, commentableId)
putExtra(IntentKey.COMMENT, commentID)
putExtra(IntentKey.PROJECT, ProjectFactory.project())
}
)

vm.outputs.startThreadActivity().take(0).subscribe {
assertEquals(it.first.first.commentableId, commentableId)
assertEquals(it.first.first.commentableId, commentID)
assertFalse(it.first.second)
}

Expand Down
Expand Up @@ -689,7 +689,7 @@ class ProjectPageViewModelTest : KSRobolectricTestCase() {

this.vm.intent(intent)

testScheduler.advanceTimeBy(2, TimeUnit.SECONDS)
testScheduler.advanceTimeBy(3, TimeUnit.SECONDS)

this.startRootCommentsActivity.assertValues(projectAndData)
}
Expand Down Expand Up @@ -717,7 +717,7 @@ class ProjectPageViewModelTest : KSRobolectricTestCase() {

this.vm.intent(intent)

testScheduler.advanceTimeBy(2, TimeUnit.SECONDS)
testScheduler.advanceTimeBy(3, TimeUnit.SECONDS)

this.startRootCommentsForCommentsThreadActivity.assertValues(deepLinkDate)
}
Expand All @@ -744,7 +744,7 @@ class ProjectPageViewModelTest : KSRobolectricTestCase() {

this.vm.intent(intent)

testScheduler.advanceTimeBy(2, TimeUnit.SECONDS)
testScheduler.advanceTimeBy(3, TimeUnit.SECONDS)

this.startProjectUpdateActivity.assertValues(updateProjectAndData)
}
Expand Down Expand Up @@ -773,7 +773,7 @@ class ProjectPageViewModelTest : KSRobolectricTestCase() {

this.vm.intent(intent)

testScheduler.advanceTimeBy(2, TimeUnit.SECONDS)
testScheduler.advanceTimeBy(3, TimeUnit.SECONDS)

this.startProjectUpdateToRepliesDeepLinkActivity.assertValues(updateProjectAndData)
}
Expand Down Expand Up @@ -801,7 +801,7 @@ class ProjectPageViewModelTest : KSRobolectricTestCase() {

this.vm.intent(intent)

testScheduler.advanceTimeBy(2, TimeUnit.SECONDS)
testScheduler.advanceTimeBy(3, TimeUnit.SECONDS)

this.startProjectUpdateActivity.assertValues(updateProjectAndData)
}
Expand Down

0 comments on commit 94934a9

Please sign in to comment.