Skip to content

Commit

Permalink
MLB:1856: changed copy on backingfragment whe plot selected (#2181)
Browse files Browse the repository at this point in the history
* changed copy on backingfragment whe plot selected

* added test

* no message

---------

Co-authored-by: Isa Martin <[email protected]>
  • Loading branch information
jlplks and Arkariang authored Dec 3, 2024
1 parent 91785ea commit 2b898d9
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,32 @@ object ProjectFactory {
.isBacking(true)
.build()
}

@JvmStatic
fun backedProjectWithPlotSelected(): Project {
val project = project().toBuilder().isPledgeOverTimeAllowed(true).build()
val reward = RewardFactory.reward()
val backing = Backing.builder()
.amount(10.0)
.backerId(IdFactory.id().toLong())
.cancelable(true)
.id(IdFactory.id().toLong())
.sequence(1)
.reward(reward)
.rewardId(reward.id())
.paymentSource(PaymentSourceFactory.visa())
.pledgedAt(DateTime.now())
.projectId(project.id())
.shippingAmount(0.0f)
.status(Backing.STATUS_PLEDGED)
.build()
return project
.toBuilder()
.availableCardTypes(listOf(PaymentSourceFactory.visa().type() ?: CreditCardPaymentType.CREDIT_CARD.rawValue))
.canComment(true)
.backing(backing)
.isBacking(true)
.build()
}
@JvmStatic
fun backedProjectWithRewardAndAddOnsLimitReached(): Project {
val project = project()
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/kickstarter/models/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Project private constructor(
private val goal: Double,
private val id: Long, // in the Kickstarter app, this is project.pid not project.id
private val isBacking: Boolean,
private val isPledgeOverTimeAllowed: Boolean?,
private val isStarred: Boolean,
private val lastUpdatePublishedAt: DateTime?,
private val launchedAt: DateTime?,
Expand Down Expand Up @@ -90,6 +91,7 @@ class Project private constructor(
fun goal() = this.goal
override fun id() = this.id
fun isBacking() = this.isBacking
fun isPledgeOverTimeAllowed() = this.isPledgeOverTimeAllowed
fun isStarred() = this.isStarred
fun lastUpdatePublishedAt() = this.lastUpdatePublishedAt
fun launchedAt() = this.launchedAt
Expand Down Expand Up @@ -149,6 +151,7 @@ class Project private constructor(
private var goal: Double = 0.0,
private var id: Long = 0L,
private var isBacking: Boolean = false,
private var isPledgeOverTimeAllowed: Boolean? = null,
private var isStarred: Boolean = false,
private var lastUpdatePublishedAt: DateTime? = null,
private var launchedAt: DateTime? = null,
Expand Down Expand Up @@ -209,6 +212,7 @@ class Project private constructor(
fun goal(goal: Double?) = apply { this.goal = goal ?: 0.0 }
fun id(id: Long?) = apply { this.id = id ?: 0L }
fun isBacking(isBacking: Boolean?) = apply { this.isBacking = isBacking ?: false }
fun isPledgeOverTimeAllowed(isPledgeOverTimeAllowed: Boolean?) = apply { this.isPledgeOverTimeAllowed = isPledgeOverTimeAllowed }
fun isStarred(isStarred: Boolean?) = apply { this.isStarred = isStarred ?: false }
fun lastUpdatePublishedAt(lastUpdatePublishedAt: DateTime?) = apply { this.lastUpdatePublishedAt = lastUpdatePublishedAt }
fun launchedAt(launchedAt: DateTime?) = apply { this.launchedAt = launchedAt }
Expand Down Expand Up @@ -264,6 +268,7 @@ class Project private constructor(
goal = goal,
id = id,
isBacking = isBacking,
isPledgeOverTimeAllowed = isPledgeOverTimeAllowed,
isStarred = isStarred,
lastUpdatePublishedAt = lastUpdatePublishedAt,
launchedAt = launchedAt,
Expand Down Expand Up @@ -324,6 +329,7 @@ class Project private constructor(
goal = goal,
id = id,
isBacking = isBacking,
isPledgeOverTimeAllowed = isPledgeOverTimeAllowed,
isStarred = isStarred,
lastUpdatePublishedAt = lastUpdatePublishedAt,
launchedAt = launchedAt,
Expand Down Expand Up @@ -497,6 +503,7 @@ class Project private constructor(
goal() == other.goal() &&
id() == other.id() &&
isBacking() == other.isBacking() &&
isPledgeOverTimeAllowed() == other.isPledgeOverTimeAllowed() &&
isStarred() == other.isStarred() &&
lastUpdatePublishedAt() == other.lastUpdatePublishedAt() &&
launchedAt() == other.launchedAt() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.kickstarter.R
import com.kickstarter.libs.Either
import com.kickstarter.libs.Environment
import com.kickstarter.libs.KSString
import com.kickstarter.libs.featureflag.FlagKey
import com.kickstarter.libs.rx.transformers.Transformers.combineLatestPair
import com.kickstarter.libs.rx.transformers.Transformers.neverErrorV2
import com.kickstarter.libs.rx.transformers.Transformers.takePairWhenV2
Expand Down Expand Up @@ -240,7 +241,10 @@ interface BackingFragmentViewModel {
val reward = Observable.merge(rewardA, rewardB)
.distinctUntilChanged()

val isCreator = Observable.combineLatest(this.currentUser.observable(), backedProject) { user, project ->
val isCreator = Observable.combineLatest(
this.currentUser.observable(),
backedProject
) { user, project ->
Pair(user, project)
}
.map { it.second.userIsCreator(it.first.getValue()) }
Expand Down Expand Up @@ -295,7 +299,11 @@ interface BackingFragmentViewModel {
this.pledgeSummaryIsGone.onNext(it)
}.addToDisposable(disposables)

Observable.combineLatest(backedProject, backing, this.currentUser.loggedInUser()) { p, b, user -> Triple(p, b, user) }
Observable.combineLatest(
backedProject,
backing,
this.currentUser.loggedInUser()
) { p, b, user -> Triple(p, b, user) }
.map { pledgeStatusData(it.first, it.second, it.third) }
.distinctUntilChanged()
.subscribe { this.pledgeStatusData.onNext(it) }
Expand All @@ -305,7 +313,13 @@ interface BackingFragmentViewModel {
.filter { it.shippingAmount().isNotNull() }
.map { requireNotNull(it.shippingAmount()) }
.compose<Pair<Float, Project>>(combineLatestPair(backedProject))
.map { ProjectViewUtils.styleCurrency(it.first.toDouble(), it.second, this.ksCurrency) }
.map {
ProjectViewUtils.styleCurrency(
it.first.toDouble(),
it.second,
this.ksCurrency
)
}
.distinctUntilChanged()
.subscribe { this.shippingAmount.onNext(it) }
.addToDisposable(disposables)
Expand Down Expand Up @@ -393,7 +407,10 @@ interface BackingFragmentViewModel {
backing
.compose<Pair<Backing, Project>>(combineLatestPair(backedProject))
.compose(takePairWhenV2(this.receivedCheckboxToggled))
.switchMap { this.apiClient.postBacking(it.first.second, it.first.first, it.second).compose(neverErrorV2()) }
.switchMap {
this.apiClient.postBacking(it.first.second, it.first.first, it.second)
.compose(neverErrorV2())
}
.share()
.subscribe()

Expand Down Expand Up @@ -521,7 +538,11 @@ interface BackingFragmentViewModel {
}
}

private fun pledgeStatusData(project: Project, backing: Backing, user: User): PledgeStatusData {
private fun pledgeStatusData(
project: Project,
backing: Backing,
user: User
): PledgeStatusData {

var statusStringRes: Int?

Expand All @@ -534,13 +555,22 @@ interface BackingFragmentViewModel {
Backing.STATUS_COLLECTED -> R.string.We_collected_your_pledge_for_this_project
Backing.STATUS_DROPPED -> R.string.Your_pledge_was_dropped_because_of_payment_errors
Backing.STATUS_ERRORED -> R.string.We_cant_process_your_pledge_Please_update_your_payment_method
Backing.STATUS_PLEDGED -> R.string.If_your_project_reaches_its_funding_goal_the_backer_will_be_charged_total_on_project_deadline
Backing.STATUS_PLEDGED -> {
if (project.isPledgeOverTimeAllowed() == true &&
environment.featureFlagClient()
?.getBoolean(FlagKey.ANDROID_PLEDGE_OVER_TIME) == true
) {
R.string.fpo_you_have_selected_pledge_over_time_if_the_project_reaches_its_funding_goal_the_first_charge_of
} else {
R.string.If_your_project_reaches_its_funding_goal_the_backer_will_be_charged_total_on_project_deadline
}
}

Backing.STATUS_PREAUTH -> R.string.We_re_processing_your_pledge_pull_to_refresh
else -> null
}
}
} else {

statusStringRes = when (project.state()) {
Project.STATE_CANCELED -> R.string.You_canceled_this_project_so_the_backers_payment_method_was_never_charged
Project.STATE_FAILED -> R.string.Your_project_didnt_reach_its_funding_goal_so_the_backers_payment_method_was_never_charged
Expand Down Expand Up @@ -603,13 +633,17 @@ interface BackingFragmentViewModel {

override fun cardLogo(): Observable<Int> = this.cardLogo

override fun fixPaymentMethodButtonIsGone(): Observable<Boolean> = this.fixPaymentMethodButtonIsGone
override fun fixPaymentMethodButtonIsGone(): Observable<Boolean> =
this.fixPaymentMethodButtonIsGone

override fun fixPaymentMethodMessageIsGone(): Observable<Boolean> = this.fixPaymentMethodMessageIsGone
override fun fixPaymentMethodMessageIsGone(): Observable<Boolean> =
this.fixPaymentMethodMessageIsGone

override fun notifyDelegateToRefreshProject(): Observable<Unit> = this.notifyDelegateToRefreshProject
override fun notifyDelegateToRefreshProject(): Observable<Unit> =
this.notifyDelegateToRefreshProject

override fun notifyDelegateToShowFixPledge(): Observable<Unit> = this.notifyDelegateToShowFixPledge
override fun notifyDelegateToShowFixPledge(): Observable<Unit> =
this.notifyDelegateToShowFixPledge

override fun paymentMethodIsGone(): Observable<Boolean> = this.paymentMethodIsGone

Expand All @@ -621,15 +655,18 @@ interface BackingFragmentViewModel {

override fun pledgeSummaryIsGone(): Observable<Boolean> = this.pledgeSummaryIsGone

override fun projectDataAndReward(): Observable<Pair<ProjectData, Reward>> = this.projectDataAndReward
override fun projectDataAndReward(): Observable<Pair<ProjectData, Reward>> =
this.projectDataAndReward

override fun projectDataAndAddOns(): Observable<Pair<ProjectData, List<Reward>>> = this.addOnsList
override fun projectDataAndAddOns(): Observable<Pair<ProjectData, List<Reward>>> =
this.addOnsList

override fun receivedCheckboxChecked(): Observable<Boolean> = this.receivedCheckboxChecked

override fun receivedSectionIsGone(): Observable<Boolean> = this.receivedSectionIsGone

override fun receivedSectionCreatorIsGone(): Observable<Boolean> = this.receivedSectionCreatorIsGone
override fun receivedSectionCreatorIsGone(): Observable<Boolean> =
this.receivedSectionCreatorIsGone

override fun shippingAmount(): Observable<CharSequence> = this.shippingAmount

Expand All @@ -639,15 +676,17 @@ interface BackingFragmentViewModel {

override fun showUpdatePledgeSuccess(): Observable<Unit> = this.showUpdatePledgeSuccess

override fun swipeRefresherProgressIsVisible(): Observable<Boolean> = this.swipeRefresherProgressIsVisible
override fun swipeRefresherProgressIsVisible(): Observable<Boolean> =
this.swipeRefresherProgressIsVisible

override fun totalAmount(): Observable<CharSequence> = this.totalAmount

override fun bonusSupport(): Observable<CharSequence> = this.bonusSupport

override fun estimatedDelivery(): Observable<String> = this.estimatedDelivery

override fun deliveryDisclaimerSectionIsGone(): Observable<Boolean> = this.deliveryDisclaimerSectionIsGone
override fun deliveryDisclaimerSectionIsGone(): Observable<Boolean> =
this.deliveryDisclaimerSectionIsGone

override fun onCleared() {
apolloClient.cleanDisposables()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,6 @@
<string name="fpo_collected">Collected</string>
<string name="fpo_unattempted">Unattempted</string>
<string name="fpo_payment_schedule">Payment schedule</string>
<string name="fpo_you_have_selected_pledge_over_time_if_the_project_reaches_its_funding_goal_the_first_charge_of">You have selected Pledge Over Time. If the project reaches its funding goal, the first charge of $20 will be collected on March 15, 2024.</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import com.kickstarter.R
import com.kickstarter.libs.Either
import com.kickstarter.libs.Environment
import com.kickstarter.libs.MockCurrentUserV2
import com.kickstarter.libs.featureflag.FlagKey
import com.kickstarter.libs.utils.DateTimeUtils
import com.kickstarter.libs.utils.EventName
import com.kickstarter.libs.utils.extensions.addToDisposable
import com.kickstarter.mock.MockFeatureFlagClient
import com.kickstarter.mock.factories.BackingFactory
import com.kickstarter.mock.factories.LocationFactory
import com.kickstarter.mock.factories.PaymentSourceFactory
Expand Down Expand Up @@ -768,6 +770,38 @@ class BackingFragmentViewModelTest : KSRobolectricTestCase() {
)
}

@Test
fun testPledgeStatusData_whenPlotIsAllowed() {
val mockFeatureFlagClient = object : MockFeatureFlagClient() {
override fun getBoolean(FlagKey: FlagKey): Boolean {
return true
}
}
val backing = backingWithStatus(Backing.STATUS_PLEDGED)
val deadline = DateTime.parse("2019-11-11T17:10:04+00:00")
val backedProject = ProjectFactory.backedProjectWithPlotSelected()
.toBuilder()
.deadline(deadline)
.build()

val environment = environment()
.toBuilder()
.featureFlagClient(mockFeatureFlagClient)
.apolloClientV2(mockApolloClientForBacking(backing))
.currentUserV2(MockCurrentUserV2(UserFactory.user()))
.build()
setUpEnvironment(environment)
this.vm.inputs.configureWith(ProjectDataFactory.project(backedProject))

this.pledgeStatusData.assertValue(
PledgeStatusData(
R.string.fpo_you_have_selected_pledge_over_time_if_the_project_reaches_its_funding_goal_the_first_charge_of,
expectedCurrency(environment, backedProject, 20.0),
DateTimeUtils.longDate(deadline)
)
)
}

@Test
fun testPledgeStatusData_whenBackingIsPreAuth() {
val backing = backingWithStatus(Backing.STATUS_PREAUTH)
Expand Down

0 comments on commit 2b898d9

Please sign in to comment.