From f63ea037ce077fedf41baaa6f4d3fbfa56e260c3 Mon Sep 17 00:00:00 2001 From: Leigh Douglas Date: Fri, 15 Nov 2024 19:25:54 -0500 Subject: [PATCH] MBL-1876: Firebase crashes Caused by android.os.TransactionTooLargeException (#2171) --- .../libs/utils/extensions/ProjectExt.kt | 8 ++- .../ui/activities/CommentsActivity.kt | 7 ++- .../PreLaunchProjectPageActivity.kt | 9 +--- .../ui/activities/ProjectPageActivity.kt | 5 +- .../kickstarter/ui/extensions/ActivityExt.kt | 14 ++--- .../FrequentlyAskedQuestionFragment.kt | 3 +- .../libs/utils/extensions/ProjectExtTest.kt | 2 +- .../viewmodels/CommentsViewModelTest.kt | 53 ++++++++++--------- .../viewmodels/CreatorBioViewModelTest.kt | 3 +- .../viewmodels/MessagesViewModelTest.kt | 45 +++++++++------- .../PrelaunchProjectViewModelTest.kt | 4 +- .../viewmodels/ProjectUpdatesViewModelTest.kt | 3 +- .../viewmodels/ReportProjectViewModelTest.kt | 3 +- .../viewmodels/ThanksViewModelTest.kt | 41 +++++++------- .../viewmodels/ThreadViewModelTest.kt | 52 ++++++++++++------ 15 files changed, 145 insertions(+), 107 deletions(-) diff --git a/app/src/main/java/com/kickstarter/libs/utils/extensions/ProjectExt.kt b/app/src/main/java/com/kickstarter/libs/utils/extensions/ProjectExt.kt index 6792cf999a..5248923e48 100644 --- a/app/src/main/java/com/kickstarter/libs/utils/extensions/ProjectExt.kt +++ b/app/src/main/java/com/kickstarter/libs/utils/extensions/ProjectExt.kt @@ -312,13 +312,14 @@ fun Project.reduce(): Project { * The end goal is to reduce to the bare minimum the amount of memory required to be serialized on Intents * when presenting screens in order to avoid `android.os.TransactionTooLargeException` */ -fun Project.reduceToPreLaunchProject(): Project { +fun Project.reduceProjectPayload(): Project { val web = Web.builder() .project(this.webProjectUrl()) .build() return Project.Builder() .id(this.id()) + .canComment(this.canComment()) .slug(this.slug()) .name(this.name()) .creator(this.creator()) @@ -331,9 +332,14 @@ fun Project.reduceToPreLaunchProject(): Project { .currentCurrency(this.currentCurrency()) .sendThirdPartyEvents(this.sendThirdPartyEvents()) .isStarred(this.isStarred()) + .isBacking(this.isBacking()) .currency(this.currency()) .currencySymbol(this.currencySymbol()) .currencyTrailingCode(this.currencyTrailingCode()) .urls(Urls.builder().web(web).build()) + .isInPostCampaignPledgingPhase(this.isInPostCampaignPledgingPhase()) + .postCampaignPledgingEnabled(this.postCampaignPledgingEnabled()) + .sendThirdPartyEvents(this.sendThirdPartyEvents()) + .state(this.state()) .build() } diff --git a/app/src/main/java/com/kickstarter/ui/activities/CommentsActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/CommentsActivity.kt index 556430bd0d..6adad65882 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/CommentsActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/CommentsActivity.kt @@ -17,6 +17,7 @@ import com.kickstarter.libs.utils.TransitionUtils import com.kickstarter.libs.utils.UrlUtils import com.kickstarter.libs.utils.extensions.addToDisposable import com.kickstarter.libs.utils.extensions.getEnvironment +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.libs.utils.extensions.showAlertDialog import com.kickstarter.libs.utils.extensions.toVisibility import com.kickstarter.models.Comment @@ -302,8 +303,9 @@ class CommentsActivity : * // TODO: https://kickstarter.atlassian.net/browse/NT-1955 */ private fun startThreadActivity(commentData: CommentCardData, openKeyboard: Boolean, projectUpdateId: String? = null) { + val reducedProject = commentData.project?.reduceProjectPayload() val threadIntent = Intent(this, ThreadActivity::class.java).apply { - putExtra(IntentKey.COMMENT_CARD_DATA, commentData) + putExtra(IntentKey.COMMENT_CARD_DATA, commentData.toBuilder().project(reducedProject).build()) putExtra(IntentKey.REPLY_EXPAND, openKeyboard) putExtra(IntentKey.UPDATE_POST_ID, projectUpdateId) } @@ -315,8 +317,9 @@ class CommentsActivity : } private fun startThreadActivityFromDeepLink(commentData: CommentCardData, projectUpdateId: String? = null) { + val reducedProject = commentData.project?.reduceProjectPayload() val threadIntent = Intent(this, ThreadActivity::class.java).apply { - putExtra(IntentKey.COMMENT_CARD_DATA, commentData) + putExtra(IntentKey.COMMENT_CARD_DATA, commentData.toBuilder().project(reducedProject).build()) putExtra(IntentKey.REPLY_EXPAND, false) putExtra(IntentKey.REPLY_SCROLL_BOTTOM, true) putExtra(IntentKey.UPDATE_POST_ID, projectUpdateId) diff --git a/app/src/main/java/com/kickstarter/ui/activities/PreLaunchProjectPageActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/PreLaunchProjectPageActivity.kt index 6379b77856..2e7531bf37 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/PreLaunchProjectPageActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/PreLaunchProjectPageActivity.kt @@ -1,6 +1,5 @@ package com.kickstarter.ui.activities -import android.app.Activity import android.content.Intent import android.os.Build import android.os.Bundle @@ -16,14 +15,13 @@ import com.kickstarter.libs.KSString import com.kickstarter.libs.featureflag.FlagKey import com.kickstarter.libs.utils.ViewUtils import com.kickstarter.libs.utils.extensions.addToDisposable -import com.kickstarter.libs.utils.extensions.getCreatorBioWebViewActivityIntent import com.kickstarter.libs.utils.extensions.getEnvironment -import com.kickstarter.models.Project import com.kickstarter.ui.IntentKey import com.kickstarter.ui.SharedPreferenceKey import com.kickstarter.ui.activities.compose.PreLaunchProjectPageScreen import com.kickstarter.ui.compose.designsystem.KickstarterApp import com.kickstarter.ui.data.LoginReason +import com.kickstarter.ui.extensions.startCreatorBioWebViewActivity import com.kickstarter.viewmodels.projectpage.PrelaunchProjectViewModel import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable @@ -144,11 +142,6 @@ class PreLaunchProjectPageActivity : ComponentActivity() { startActivityForResult(intent, ActivityRequestCodes.LOGIN_FLOW) } - fun Activity.startCreatorBioWebViewActivity(project: Project) { - startActivity(Intent().getCreatorBioWebViewActivityIntent(this, project)) - overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out_slide_out_left) - } - @Override override fun onDestroy() { compositeDisposable.clear() diff --git a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt index a822d150e8..ebd2c7ed6e 100644 --- a/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt +++ b/app/src/main/java/com/kickstarter/ui/activities/ProjectPageActivity.kt @@ -58,6 +58,7 @@ import com.kickstarter.libs.utils.ViewUtils import com.kickstarter.libs.utils.extensions.addToDisposable import com.kickstarter.libs.utils.extensions.getEnvironment import com.kickstarter.libs.utils.extensions.getPaymentSheetConfiguration +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.libs.utils.extensions.showLatePledgeFlow import com.kickstarter.libs.utils.extensions.toVisibility import com.kickstarter.models.Project @@ -1065,7 +1066,7 @@ class ProjectPageActivity : if (clearFragmentBackStack() || (projectData.project().showLatePledgeFlow() && fFLatePledge)) { startActivity( Intent(this, ThanksActivity::class.java) - .putExtra(IntentKey.PROJECT, projectData.project()) + .putExtra(IntentKey.PROJECT, projectData.project().reduceProjectPayload()) .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) .putExtra(IntentKey.PLEDGE_DATA, pledgeData) ) @@ -1135,7 +1136,7 @@ class ProjectPageActivity : startActivity( Intent(this, MessagesActivity::class.java) .putExtra(IntentKey.MESSAGE_SCREEN_SOURCE_CONTEXT, MessagePreviousScreenType.PROJECT_PAGE) - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) .putExtra(IntentKey.BACKING, project.backing()) ) } diff --git a/app/src/main/java/com/kickstarter/ui/extensions/ActivityExt.kt b/app/src/main/java/com/kickstarter/ui/extensions/ActivityExt.kt index 4b395aedf6..9efaea3f67 100644 --- a/app/src/main/java/com/kickstarter/ui/extensions/ActivityExt.kt +++ b/app/src/main/java/com/kickstarter/ui/extensions/ActivityExt.kt @@ -31,7 +31,7 @@ import com.kickstarter.libs.utils.extensions.getReportProjectActivityIntent import com.kickstarter.libs.utils.extensions.getRootCommentsActivityIntent import com.kickstarter.libs.utils.extensions.getUpdatesActivityIntent import com.kickstarter.libs.utils.extensions.getVideoActivityIntent -import com.kickstarter.libs.utils.extensions.reduceToPreLaunchProject +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.libs.utils.extensions.withData import com.kickstarter.models.Project import com.kickstarter.models.chrome.ChromeTabsHelperActivity @@ -168,8 +168,9 @@ fun Activity.startPledgeRedemption(project: Project) { * @param commentableId -> specific for deeplinking to a concrete thread */ fun Activity.startRootCommentsActivity(projectData: ProjectData, commentableId: String? = null) { + val reducedProject = projectData.project().reduceProjectPayload() startActivity( - Intent().getRootCommentsActivityIntent(this, projectData, commentableId) + Intent().getRootCommentsActivityIntent(this, projectData.toBuilder().project(reducedProject).build(), commentableId) ) this.let { @@ -185,12 +186,12 @@ fun Activity.startReportProjectActivity( project: Project, startForResult: ActivityResultLauncher ) { - startForResult.launch(Intent().getReportProjectActivityIntent(this, project = project)) + startForResult.launch(Intent().getReportProjectActivityIntent(this, project = project.reduceProjectPayload())) overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out_slide_out_left) } fun Activity.startCreatorBioWebViewActivity(project: Project) { - startActivity(Intent().getCreatorBioWebViewActivityIntent(this, project)) + startActivity(Intent().getCreatorBioWebViewActivityIntent(this, project.reduceProjectPayload())) overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out_slide_out_left) } @@ -235,7 +236,8 @@ fun Activity.startUpdatesActivity( * @param projectAndData */ fun Activity.startProjectUpdatesActivity(projectAndData: ProjectData) { - startActivity(Intent().getProjectUpdatesActivityIntent(this, projectAndData)) + val reducedProject = projectAndData.project().reduceProjectPayload() + startActivity(Intent().getProjectUpdatesActivityIntent(this, projectAndData.toBuilder().project(reducedProject).build())) overridePendingTransition(R.anim.slide_in_right, R.anim.fade_out_slide_out_left) } @@ -259,7 +261,7 @@ fun Activity.startPreLaunchProjectActivity(uri: Uri, project: Project, previousS val intent = Intent().getPreLaunchProjectActivity( this, project.slug(), - project.reduceToPreLaunchProject() + project.reduceProjectPayload() ) // Pass full deeplink for attribution tracking purposes when launching from deeplink intent.setData(uri) diff --git a/app/src/main/java/com/kickstarter/ui/fragments/projectpage/FrequentlyAskedQuestionFragment.kt b/app/src/main/java/com/kickstarter/ui/fragments/projectpage/FrequentlyAskedQuestionFragment.kt index 7d5fdfb2ae..1987f6bd62 100644 --- a/app/src/main/java/com/kickstarter/ui/fragments/projectpage/FrequentlyAskedQuestionFragment.kt +++ b/app/src/main/java/com/kickstarter/ui/fragments/projectpage/FrequentlyAskedQuestionFragment.kt @@ -18,6 +18,7 @@ import com.kickstarter.libs.MessagePreviousScreenType import com.kickstarter.libs.SimpleDividerItemDecoration import com.kickstarter.libs.utils.extensions.addToDisposable import com.kickstarter.libs.utils.extensions.getEnvironment +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.models.Project import com.kickstarter.ui.ArgumentsKey import com.kickstarter.ui.IntentKey @@ -120,7 +121,7 @@ class FrequentlyAskedQuestionFragment : Fragment(), Configure { startActivity( Intent(requireContext(), MessagesActivity::class.java) .putExtra(IntentKey.MESSAGE_SCREEN_SOURCE_CONTEXT, MessagePreviousScreenType.CREATOR_BIO_MODAL) - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) .putExtra(IntentKey.BACKING, project.backing()) ) } diff --git a/app/src/test/java/com/kickstarter/libs/utils/extensions/ProjectExtTest.kt b/app/src/test/java/com/kickstarter/libs/utils/extensions/ProjectExtTest.kt index 479a394b88..47c0f95448 100644 --- a/app/src/test/java/com/kickstarter/libs/utils/extensions/ProjectExtTest.kt +++ b/app/src/test/java/com/kickstarter/libs/utils/extensions/ProjectExtTest.kt @@ -389,7 +389,7 @@ class ProjectExtTest : KSRobolectricTestCase() { val user = UserFactory.germanUser().toBuilder().chosenCurrency("CAD").build() val deadline = DateTime(DateTimeZone.UTC).plusDays(10) val project = ProjectFactory.project().toBuilder().watchesCount(10).isStarred(true).creator(user).build() - val reducedProject = project.reduceToPreLaunchProject().toBuilder().deadline(deadline).build() + val reducedProject = project.reduceProjectPayload().toBuilder().deadline(deadline).build() assertEquals(project.id(), reducedProject.id()) assertEquals(project.name(), reducedProject.name()) diff --git a/app/src/test/java/com/kickstarter/viewmodels/CommentsViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/CommentsViewModelTest.kt index f6f8d4c181..45447a09b7 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/CommentsViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/CommentsViewModelTest.kt @@ -7,6 +7,7 @@ import com.kickstarter.libs.MockCurrentUser import com.kickstarter.libs.MockCurrentUserV2 import com.kickstarter.libs.utils.EventName import com.kickstarter.libs.utils.extensions.addToDisposable +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.mock.factories.ApiExceptionFactory import com.kickstarter.mock.factories.AvatarFactory import com.kickstarter.mock.factories.CommentEnvelopeFactory @@ -60,7 +61,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { fun testCommentsViewModel_whenUserLoggedInAndBacking_shouldShowEnabledComposer() { // Start the view model with a backed project. - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.backedProject())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.backedProject().reduceProjectPayload())) val vm = Factory( environment().toBuilder().currentUserV2(MockCurrentUserV2(UserFactory.user())).build(), intent @@ -77,7 +78,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { @Test fun testCommentsViewModel_whenUserIsLoggedOut_composerShouldBeGone() { // Start the view model with a backed project. - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory( environment().toBuilder().build(), intent @@ -94,7 +95,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { @Test fun testCommentsViewModel_whenUserIsLoggedInNotBacking_shouldShowDisabledComposer() { // Start the view model with a backed project. - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory( environment().toBuilder().currentUserV2(MockCurrentUserV2(UserFactory.user())).build(), intent @@ -114,7 +115,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { val project = ProjectFactory.project() .toBuilder() .canComment(true) - .build() + .build().reduceProjectPayload() val vm = Factory( environment().toBuilder().currentUserV2(MockCurrentUserV2(currentUser)).build(), Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(project)) @@ -134,10 +135,10 @@ class CommentsViewModelTest : KSRobolectricTestCase() { val project = ProjectFactory.project() .toBuilder() .canComment(false) - .build() + .build().reduceProjectPayload() val vm = Factory( environment().toBuilder().currentUserV2(MockCurrentUserV2(currentUser)).build(), - Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(project)) ).create(CommentsViewModel::class.java) vm.outputs.commentComposerStatus().subscribe { commentComposerStatus.onNext(it) }.addToDisposable(disposables) @@ -156,11 +157,11 @@ class CommentsViewModelTest : KSRobolectricTestCase() { .toBuilder() .creator(creator) .isBacking(false) - .build() + .build().reduceProjectPayload() val vm = Factory( environment().toBuilder().currentUserV2(MockCurrentUserV2(currentUser)).build(), - Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(project)) ).create(CommentsViewModel::class.java) vm.outputs.commentComposerStatus().subscribe { commentComposerStatus.onNext(it) }.addToDisposable(disposables) @@ -179,11 +180,11 @@ class CommentsViewModelTest : KSRobolectricTestCase() { val project = ProjectFactory.project() .toBuilder() .isBacking(false) - .build() + .build().reduceProjectPayload() val vm = Factory( environment().toBuilder().currentUserV2(MockCurrentUserV2(currentUser)).build(), - Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(project)) ).create(CommentsViewModel::class.java) val currentUserAvatar = TestSubscriber() @@ -230,7 +231,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { } }).build() - val vm = Factory(env, Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project()))).create(CommentsViewModel::class.java) + val vm = Factory(env, Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload()))).create(CommentsViewModel::class.java) val commentsList = TestSubscriber>() vm.outputs.commentsList().subscribe { commentsList.onNext(it) }.addToDisposable(disposables) @@ -277,7 +278,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { } }).build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) val commentsList = TestSubscriber?>() @@ -289,7 +290,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { @Test fun testCommentsViewModel_ProjectCommentsEmit() { val commentsList = BehaviorSubject.create?>() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(environment(), intent).create(CommentsViewModel::class.java) vm.outputs.commentsList().subscribe { commentsList.onNext(it) }.addToDisposable(disposables) @@ -353,7 +354,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { } }).build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) vm.outputs.setEmptyState().subscribe { showEmptyState.onNext(it) }.addToDisposable(disposables) @@ -380,7 +381,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { @Test fun testCommentsViewModel_ProjectRefresh() { - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(environment(), intent).create(CommentsViewModel::class.java) // Start the view model with a project. @@ -399,7 +400,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { } }).build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) vm.outputs.initialLoadCommentsError().subscribe { initialLoadError.onNext(it) }.addToDisposable(disposables) @@ -434,7 +435,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { } }).build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) firstCall = false @@ -475,7 +476,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { }) .schedulerV2(testScheduler).build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) vm.outputs.commentsList().subscribe { commentsList.onNext(it) }.addToDisposable(disposables) @@ -566,7 +567,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { @Test fun backButtonPressed_whenEmits_shouldEmitToCloseActivityStream_FromProject() { - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(environment(), intent).create(CommentsViewModel::class.java) vm.outputs.closeCommentsPage().subscribe { closeCommentPage.onNext(it) }.addToDisposable(disposables) @@ -633,7 +634,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { .schedulerV2(testScheduler) .build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) vm.inputs.onReplyClicked(comment1, true) @@ -685,7 +686,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { .commentCardState(CommentCardStatus.COMMENT_FOR_LOGIN_BACKED_USERS.commentCardStatus) .build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent = intent).create(CommentsViewModel::class.java) vm.outputs.commentsList().subscribe { commentsList.onNext(it) }.addToDisposable(disposables) @@ -783,7 +784,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { .commentCardState(CommentCardStatus.COMMENT_FOR_LOGIN_BACKED_USERS.commentCardStatus) .build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) vm.outputs.commentsList().subscribe { commentsList.onNext(it) }.addToDisposable(disposables) @@ -890,7 +891,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { .commentCardState(CommentCardStatus.COMMENT_FOR_LOGIN_BACKED_USERS.commentCardStatus) .build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) vm.outputs.commentsList().subscribe { commentsList.onNext(it) }.addToDisposable(disposables) @@ -981,7 +982,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { .commentCardState(CommentCardStatus.CANCELED_PLEDGE_COMMENT.commentCardStatus) .build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) vm.outputs.commentsList().subscribe { commentsList.onNext(it) }.addToDisposable(disposables) @@ -1034,7 +1035,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { val intent = Intent().apply { putExtra(IntentKey.COMMENT, commentID) - putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) } val vm = Factory(env, intent).create(CommentsViewModel::class.java) @@ -1090,7 +1091,7 @@ class CommentsViewModelTest : KSRobolectricTestCase() { .schedulerV2(testScheduler) .build() - val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project())) + val intent = Intent().putExtra(IntentKey.PROJECT_DATA, ProjectDataFactory.project(ProjectFactory.project().reduceProjectPayload())) val vm = Factory(env, intent).create(CommentsViewModel::class.java) vm.outputs.commentsList().subscribe { commentsList.onNext(it) }.addToDisposable(disposables) diff --git a/app/src/test/java/com/kickstarter/viewmodels/CreatorBioViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/CreatorBioViewModelTest.kt index c50cd098f7..706e2862ec 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/CreatorBioViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/CreatorBioViewModelTest.kt @@ -5,6 +5,7 @@ import com.kickstarter.KSRobolectricTestCase import com.kickstarter.libs.Environment import com.kickstarter.libs.MockCurrentUserV2 import com.kickstarter.libs.utils.extensions.addToDisposable +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.mock.factories.ProjectFactory import com.kickstarter.mock.factories.UserFactory import com.kickstarter.models.Project @@ -27,7 +28,7 @@ class CreatorBioViewModelTest : KSRobolectricTestCase() { private fun setUpEnvironment(environment: Environment, project: Project? = ProjectFactory.project()) { // Configure the view model with a project and url intent. val intent = - Intent().putExtra(IntentKey.PROJECT, project) + Intent().putExtra(IntentKey.PROJECT, project?.reduceProjectPayload()) .putExtra(IntentKey.URL, "http://www.project.com/creator-bio") this.vm = CreatorBioViewModel.Factory(environment, intent).create(CreatorBioViewModel::class.java) diff --git a/app/src/test/java/com/kickstarter/viewmodels/MessagesViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/MessagesViewModelTest.kt index 7026c3c551..1bbffb6508 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/MessagesViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/MessagesViewModelTest.kt @@ -9,12 +9,14 @@ import com.kickstarter.libs.MessagePreviousScreenType import com.kickstarter.libs.MockCurrentUser import com.kickstarter.libs.MockCurrentUserV2 import com.kickstarter.libs.utils.extensions.addToDisposable +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.mock.factories.ApiExceptionFactory import com.kickstarter.mock.factories.BackingFactory.backing import com.kickstarter.mock.factories.MessageFactory.message import com.kickstarter.mock.factories.MessageThreadEnvelopeFactory.empty import com.kickstarter.mock.factories.MessageThreadEnvelopeFactory.messageThreadEnvelope import com.kickstarter.mock.factories.MessageThreadFactory.messageThread +import com.kickstarter.mock.factories.ProjectFactory import com.kickstarter.mock.factories.ProjectFactory.project import com.kickstarter.mock.factories.UserFactory.creator import com.kickstarter.mock.factories.UserFactory.user @@ -114,7 +116,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { fun testBackingAndProject_Participant() { val project = project().toBuilder() .isBacking(false) - .build() + .build().reduceProjectPayload() val backing = backing().toBuilder() .project(project) .build() @@ -149,7 +151,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { fun testBackingInfo_NoBacking() { val project = project().toBuilder() .isBacking(false) - .build() + .build().reduceProjectPayload() val messageThread = messageThread().toBuilder() .project(project) .backing(null) @@ -186,7 +188,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { @Test fun testConfiguredWithProject_AndBacking() { val backing = backing() - val project = project() + val project = project().reduceProjectPayload() // Start the view model with a backing and a project. setUpEnvironment( @@ -205,7 +207,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { val currentUser: CurrentUserTypeV2 = MockCurrentUserV2(creator) val messageThread = messageThread() .toBuilder() - .project(project().toBuilder().creator(creator).build()) + .project(project().toBuilder().creator(creator).build().reduceProjectPayload()) .participant(participant) .build() @@ -230,7 +232,8 @@ class MessagesViewModelTest : KSRobolectricTestCase() { @Test fun testProjectData_ExistingMessages() { - val messageThread = messageThread() + val project = project().reduceProjectPayload() + val messageThread = messageThread().toBuilder().project(project).build() val apiClient: MockApiClientV2 = object : MockApiClientV2() { override fun fetchMessagesForThread(thread: MessageThread): Observable { return Observable.just(messageThreadEnvelope()) @@ -251,7 +254,8 @@ class MessagesViewModelTest : KSRobolectricTestCase() { @Test fun testMessageEditTextHint() { - val messageThread = messageThread() + val project = project().reduceProjectPayload() + val messageThread = messageThread().toBuilder().project(project).build() val apiClient: MockApiClientV2 = object : MockApiClientV2() { override fun fetchMessagesForThread(thread: MessageThread): Observable { return Observable.just(messageThreadEnvelope()) @@ -270,8 +274,11 @@ class MessagesViewModelTest : KSRobolectricTestCase() { @Test fun testMessagesEmit() { + val project = project().reduceProjectPayload() + val messageThread = messageThread().toBuilder().project(project).build() val envelope = messageThreadEnvelope() .toBuilder() + .messageThread(messageThread) .messages(listOf(message())) .build() val apiClient: MockApiClientV2 = object : MockApiClientV2() { @@ -295,7 +302,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { @Test fun testNoMessages() { val backing = backing() - val project = project() + val project = project().reduceProjectPayload() val apiClient: MockApiClientV2 = object : MockApiClientV2() { override fun fetchMessagesForBacking(backing: Backing): Observable { return Observable.just(empty()) @@ -442,7 +449,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { setUpEnvironment( environment().toBuilder().apiClientV2(apiClient).currentUserV2(MockCurrentUserV2(user())) .build(), - backerModalContextIntent(backing, project()) + backerModalContextIntent(backing, project().reduceProjectPayload()) ) messageEditTextShouldRequestFocus.assertValueCount(1) @@ -451,7 +458,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { @Test fun testStartBackingActivity_AsBacker() { val user = user() - val project = project().toBuilder().isBacking(true).build() + val project = project().toBuilder().isBacking(true).build().reduceProjectPayload() val backing = backing() val messageThread = messageThread() .toBuilder() @@ -479,7 +486,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { @Test fun testStartBackingActivity_AsBacker_EmptyThread() { val user = user() - val project = project().toBuilder().isBacking(true).build() + val project = project().toBuilder().isBacking(true).build().reduceProjectPayload() val backing = backing() val apiClient: MockApiClientV2 = object : MockApiClientV2() { override fun fetchMessagesForBacking(backing: Backing): Observable { @@ -501,7 +508,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { val backer = user().toBuilder().name("Vanessa").build() val creator = user().toBuilder().name("Jessica").build() val backing = backing() - val project = project().toBuilder().creator(creator).build() + val project = project().toBuilder().creator(creator).build().reduceProjectPayload() val messageThread = messageThread() .toBuilder() .backing(backing) @@ -540,10 +547,10 @@ class MessagesViewModelTest : KSRobolectricTestCase() { @Test fun testStartProjectPageActivity() { - val project = project().toBuilder().isBacking(true).build() + val project = project().toBuilder().isBacking(true).build().reduceProjectPayload() val messageThread = messageThread() .toBuilder() - .project(project) + .project(project.reduceProjectPayload()) .build() val messageThreadEnvelope = messageThreadEnvelope() .toBuilder() @@ -598,7 +605,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { setUpEnvironment( environment().toBuilder().apiClientV2(apiClient).currentUserV2(MockCurrentUserV2(user())) .build(), - backerModalContextIntent(backing, project()) + backerModalContextIntent(backing, project().reduceProjectPayload()) ) vm.inputs.messageEditTextIsFocused(true) @@ -624,7 +631,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { setUpEnvironment( environment().toBuilder().apiClientV2(apiClient).currentUserV2(MockCurrentUserV2(user())) .build(), - backerModalContextIntent(backing, project()) + backerModalContextIntent(backing, project().reduceProjectPayload()) ) vm.inputs.messageEditTextIsFocused(true) @@ -646,7 +653,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { fun testViewPledgeButton_IsGone_backerModal() { setUpEnvironment( environment().toBuilder().currentUserV2(MockCurrentUserV2(user())).build(), - backerModalContextIntent(backing(), project()) + backerModalContextIntent(backing(), project().reduceProjectPayload()) ) // View pledge button is hidden when context is from the backer modal. @@ -657,7 +664,7 @@ class MessagesViewModelTest : KSRobolectricTestCase() { fun testViewPledgeButton_IsVisible_creatorBioModal() { setUpEnvironment( environment().toBuilder().currentUserV2(MockCurrentUserV2(user())).build(), - creatorBioModalContextIntent(backing(), project()) + creatorBioModalContextIntent(backing(), project().reduceProjectPayload()) ) // View pledge button is shown when context is from the creator bio modal. @@ -706,7 +713,9 @@ class MessagesViewModelTest : KSRobolectricTestCase() { } private fun pushContextIntent(): Intent { - return messagesContextIntent(messageThread()) + val project = ProjectFactory.project().reduceProjectPayload() + val messageThread = messageThread().toBuilder().project(project).build() + return messagesContextIntent(messageThread) .putExtra(IntentKey.MESSAGE_SCREEN_SOURCE_CONTEXT, MessagePreviousScreenType.PUSH) } } diff --git a/app/src/test/java/com/kickstarter/viewmodels/PrelaunchProjectViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/PrelaunchProjectViewModelTest.kt index ce7281f2f7..7fd964044a 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/PrelaunchProjectViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/PrelaunchProjectViewModelTest.kt @@ -10,7 +10,7 @@ import com.kickstarter.libs.MockCurrentUserV2 import com.kickstarter.libs.featureflag.FlagKey import com.kickstarter.libs.utils.ThirdPartyEventValues import com.kickstarter.libs.utils.extensions.addToDisposable -import com.kickstarter.libs.utils.extensions.reduceToPreLaunchProject +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.mock.MockFeatureFlagClient import com.kickstarter.mock.factories.ProjectFactory import com.kickstarter.mock.factories.UserFactory @@ -147,7 +147,7 @@ class PrelaunchProjectViewModelTest : KSRobolectricTestCase() { .isStarred(true) .creator(user) .build() - .reduceToPreLaunchProject().toBuilder().deadline(deadline).build() + .reduceProjectPayload().toBuilder().deadline(deadline).build() setUpEnvironment(testEnvironment) diff --git a/app/src/test/java/com/kickstarter/viewmodels/ProjectUpdatesViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/ProjectUpdatesViewModelTest.kt index a553501611..2c0f72accb 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/ProjectUpdatesViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/ProjectUpdatesViewModelTest.kt @@ -6,6 +6,7 @@ import com.kickstarter.KSRobolectricTestCase import com.kickstarter.libs.Environment import com.kickstarter.libs.utils.EventName import com.kickstarter.libs.utils.extensions.addToDisposable +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.mock.factories.ProjectDataFactory.project import com.kickstarter.mock.factories.ProjectFactory.project import com.kickstarter.mock.factories.UpdateFactory.update @@ -42,7 +43,7 @@ class ProjectUpdatesViewModelTest : KSRobolectricTestCase() { private fun setUpEnvironment(env: Environment, project: Project, projectData: ProjectData) { // Configure the view model with a project intent. - val intent = Intent().putExtra(IntentKey.PROJECT, project) + val intent = Intent().putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) .putExtra(IntentKey.PROJECT_DATA, projectData) vm = Factory(env, intent).create(ProjectUpdatesViewModel::class.java) diff --git a/app/src/test/java/com/kickstarter/viewmodels/ReportProjectViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/ReportProjectViewModelTest.kt index d08bf72b50..227cc05bdd 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/ReportProjectViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/ReportProjectViewModelTest.kt @@ -3,6 +3,7 @@ package com.kickstarter.viewmodels import android.os.Bundle import com.kickstarter.KSRobolectricTestCase import com.kickstarter.libs.Environment +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.mock.factories.ProjectFactory import com.kickstarter.mock.services.MockApolloClientV2 import com.kickstarter.models.Project @@ -50,7 +51,7 @@ class ReportProjectViewModelTest : KSRobolectricTestCase() { val bundle = Bundle() bundle.putParcelable( IntentKey.PROJECT, - project + project.reduceProjectPayload() ) return bundle diff --git a/app/src/test/java/com/kickstarter/viewmodels/ThanksViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/ThanksViewModelTest.kt index 21e25352a7..65a6f6cd5d 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/ThanksViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/ThanksViewModelTest.kt @@ -15,6 +15,7 @@ import com.kickstarter.libs.featureflag.FlagKey import com.kickstarter.libs.preferences.MockBooleanPreference import com.kickstarter.libs.utils.EventName import com.kickstarter.libs.utils.extensions.addToDisposable +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.mock.MockFeatureFlagClient import com.kickstarter.mock.factories.CategoryFactory.artCategory import com.kickstarter.mock.factories.CategoryFactory.category @@ -105,7 +106,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { setUpEnvironment( intent = Intent() - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) ) @@ -131,7 +132,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { setUpEnvironment( intent = Intent() - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) ) @@ -140,7 +141,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { @Test fun testFinishEmits() { - setUpEnvironment(intent = Intent().putExtra(IntentKey.PROJECT, project())) + setUpEnvironment(intent = Intent().putExtra(IntentKey.PROJECT, project().reduceProjectPayload())) vm.inputs.closeButtonClicked() finish.assertValueCount(1) @@ -164,7 +165,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference) .build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project())) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project().reduceProjectPayload())) showRatingDialogTest.assertValueCount(0) } @@ -187,7 +188,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference) .build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project())) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project().reduceProjectPayload())) showRatingDialogTest.assertValueCount(1) } @@ -210,7 +211,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference) .build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project())) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project().reduceProjectPayload())) showRatingDialogTest.assertValueCount(0) } @@ -241,7 +242,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .hasSeenGamesNewsletterPreference(hasSeenGamesNewsletterPreference) .build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project)) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project.reduceProjectPayload())) showRatingDialogTest.assertValueCount(0) } @@ -262,7 +263,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .category(tabletopGamesCategory()) .build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project)) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project.reduceProjectPayload())) showGamesNewsletterDialogTest.assertValueCount(1) assertEquals(listOf(false, true), hasSeenGamesNewsletterPreference.values()) @@ -284,7 +285,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .category(ceramicsCategory()) .build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project)) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project.reduceProjectPayload())) showGamesNewsletterDialogTest.assertValueCount(0) } @@ -305,7 +306,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .category(tabletopGamesCategory()) .build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project)) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project.reduceProjectPayload())) showGamesNewsletterDialogTest.assertValueCount(0) } @@ -326,7 +327,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { .category(tabletopGamesCategory()) .build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project)) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project.reduceProjectPayload())) showGamesNewsletterDialogTest.assertValueCount(0) } @@ -355,7 +356,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { setUpEnvironment( environment, mockApiClientV2 = mockApiClientV2, - intent = Intent().putExtra(IntentKey.PROJECT, project) + intent = Intent().putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) ) vm.signupToGamesNewsletterClick() @@ -377,7 +378,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { val project = project().toBuilder().category(tabletopGamesCategory()).build() - setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project)) + setUpEnvironment(environment, intent = Intent().putExtra(IntentKey.PROJECT, project.reduceProjectPayload())) vm.signupToGamesNewsletterClick() showConfirmGamesNewsletterDialogTest.assertValueCount(1) @@ -385,7 +386,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { @Test fun testThanksViewModel_startDiscovery() { - setUpEnvironment(intent = Intent().putExtra(IntentKey.PROJECT, project())) + setUpEnvironment(intent = Intent().putExtra(IntentKey.PROJECT, project().reduceProjectPayload())) val category = category() @@ -414,7 +415,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { val intent = Intent() .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) .putExtra(IntentKey.PLEDGE_DATA, pledgeData) - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) setUpEnvironment(intent = intent) @@ -458,7 +459,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { val intent = Intent() .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) .putExtra(IntentKey.PLEDGE_DATA, pledgeData) - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) setUpEnvironment( environment().toBuilder() @@ -521,7 +522,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { val intent = Intent() .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) .putExtra(IntentKey.PLEDGE_DATA, pledgeData) - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) setUpEnvironment( environment().toBuilder() @@ -575,7 +576,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { val intent = Intent() .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) .putExtra(IntentKey.PLEDGE_DATA, pledgeData) - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) setUpEnvironment(environment, intent = intent) @@ -608,7 +609,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { val intent = Intent() .putExtra(IntentKey.CHECKOUT_DATA, checkoutData) .putExtra(IntentKey.PLEDGE_DATA, pledgeData) - .putExtra(IntentKey.PROJECT, project) + .putExtra(IntentKey.PROJECT, project.reduceProjectPayload()) setUpEnvironment(intent = intent) @@ -618,7 +619,7 @@ class ThanksViewModelTest : KSRobolectricTestCase() { @Test fun testTracking_whenCheckoutDataAndPledgeDataExtrasNull() { val intent = Intent() - .putExtra(IntentKey.PROJECT, project()) + .putExtra(IntentKey.PROJECT, project().reduceProjectPayload()) setUpEnvironment(intent = intent) diff --git a/app/src/test/java/com/kickstarter/viewmodels/ThreadViewModelTest.kt b/app/src/test/java/com/kickstarter/viewmodels/ThreadViewModelTest.kt index 30f84bd858..670fb6f0ea 100644 --- a/app/src/test/java/com/kickstarter/viewmodels/ThreadViewModelTest.kt +++ b/app/src/test/java/com/kickstarter/viewmodels/ThreadViewModelTest.kt @@ -7,6 +7,7 @@ import com.kickstarter.libs.Environment import com.kickstarter.libs.MockCurrentUserV2 import com.kickstarter.libs.utils.EventName import com.kickstarter.libs.utils.extensions.addToDisposable +import com.kickstarter.libs.utils.extensions.reduceProjectPayload import com.kickstarter.mock.factories.AvatarFactory import com.kickstarter.mock.factories.CommentCardDataFactory import com.kickstarter.mock.factories.CommentEnvelopeFactory @@ -65,7 +66,8 @@ class ThreadViewModelTest : KSRobolectricTestCase() { fun testGetRootComment() { setUpEnvironment() - val commentCardData = CommentCardDataFactory.commentCardData() + val project = ProjectFactory.project().reduceProjectPayload() + val commentCardData = CommentCardDataFactory.commentCardData().toBuilder().project(project).build() this.vm.intent(Intent().putExtra(IntentKey.COMMENT_CARD_DATA, commentCardData)) getComment.assertValue(commentCardData) @@ -122,11 +124,12 @@ class ThreadViewModelTest : KSRobolectricTestCase() { vm.outputs.showReplyComposer().subscribe { showReplyComposer.onNext(it) } .addToDisposable(disposables) + val project = ProjectFactory.backedProject().reduceProjectPayload() // Start the view model with a backed project and comment. vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardDataBacked() + CommentCardDataFactory.commentCardDataBacked().toBuilder().project(project).build() ) ) @@ -145,10 +148,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { .addToDisposable(disposables) // Start the view model with a backed project and comment. + val project = ProjectFactory.backedProject().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) @@ -167,11 +171,12 @@ class ThreadViewModelTest : KSRobolectricTestCase() { vm.outputs.showReplyComposer().subscribe { showReplyComposer.onNext(it) } .addToDisposable(disposables) - // Start the view model with a backed project and comment. + // Start the view model with a project and comment. + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) @@ -193,10 +198,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { .addToDisposable(disposables) // Start the view model with a backed project and comment. + val project = ProjectFactory.backedProject().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardDataBacked() + CommentCardDataFactory.commentCardDataBacked().toBuilder().project(project).build() ) ) @@ -218,10 +224,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { .addToDisposable(disposables) // Start the view model with a backed project and comment. + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) @@ -248,10 +255,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { setUpEnvironment(env) // Start the view model with a backed project and comment. + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) @@ -275,10 +283,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { setUpEnvironment(env) // Start the view model with a backed project and comment. + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) @@ -311,10 +320,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { this.vm.onCommentReplies().subscribe { onReplies.onNext(it) }.addToDisposable(disposables) // Start the view model with a backed project and comment. + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) @@ -333,10 +343,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { fun testThreadsViewModel_openCommentGuidelinesLink() { setUpEnvironment() - this.vm.intent( + val project = ProjectFactory.project().reduceProjectPayload() + vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) @@ -396,10 +407,12 @@ class ThreadViewModelTest : KSRobolectricTestCase() { val onReplies = BehaviorSubject.create, Boolean>>() val vm = ThreadViewModel.ThreadViewModel(env) + + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) vm.outputs.onCommentReplies().subscribe { onReplies.onNext(it) } @@ -482,10 +495,12 @@ class ThreadViewModelTest : KSRobolectricTestCase() { val vm = ThreadViewModel.ThreadViewModel(env) // Start the view model with a backed project and comment. + + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) vm.outputs.onCommentReplies().subscribe { onReplies.onNext(it) } @@ -612,10 +627,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { val vm = ThreadViewModel.ThreadViewModel(env) // Start the view model with a backed project and comment. + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) vm.outputs.onCommentReplies().subscribe { onReplies.onNext(it) } @@ -767,10 +783,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { val vm = ThreadViewModel.ThreadViewModel(env) // Start the view model with a backed project and comment. + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) vm.outputs.onCommentReplies().subscribe { onReplies.onNext(it) } @@ -887,10 +904,11 @@ class ThreadViewModelTest : KSRobolectricTestCase() { val vm = ThreadViewModel.ThreadViewModel(env) // Start the view model with a backed project and comment. + val project = ProjectFactory.project().reduceProjectPayload() vm.intent( Intent().putExtra( IntentKey.COMMENT_CARD_DATA, - CommentCardDataFactory.commentCardData() + CommentCardDataFactory.commentCardData().toBuilder().project(project).build() ) ) vm.outputs.onCommentReplies().subscribe { onReplies.onNext(it) }