mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-22 21:57:11 +00:00
Unit Tests for hourglasses
This commit is contained in:
parent
a69fe94ad0
commit
15f3b05337
2 changed files with 27 additions and 18 deletions
|
|
@ -47,21 +47,21 @@ open class SubscriptionPlan : RealmObject(), BaseObject {
|
|||
return totalNumberOfGems - (gemsBought ?: 0)
|
||||
}
|
||||
|
||||
/*
|
||||
If user has a initial basic monthly subscription, receive hourglasses on fourth month,
|
||||
else receive on third month (subtract 1 from total consecutive count)
|
||||
*/
|
||||
val monthsUntilNextHourglass: Int?
|
||||
get() {
|
||||
var renewalUntilNextHourglass = 0
|
||||
if (planId != null && dateTerminated == null && consecutive?.count != null) {
|
||||
when (planId) {
|
||||
// If user has a initial basic monthly subscription, receive hourglasses on fourth month, else receive on third month.
|
||||
PLANID_BASIC -> renewalUntilNextHourglass = if (consecutive?.count!! < 3) { 4 } else 3
|
||||
PLANID_BASICEARNED -> renewalUntilNextHourglass = if (consecutive?.count!! < 3) { 4 } else 3
|
||||
PLANID_BASIC3MONTH -> renewalUntilNextHourglass = 3
|
||||
PLANID_BASIC6MONTH -> renewalUntilNextHourglass = 6
|
||||
PLANID_BASIC12MONTH -> renewalUntilNextHourglass = 12
|
||||
return if (consecutive?.offset == 0) {
|
||||
if (consecutive?.count == 0) {
|
||||
4
|
||||
} else {
|
||||
(3 - (((consecutive?.count ?: 0) - 1) % 3))
|
||||
}
|
||||
return renewalUntilNextHourglass - (consecutive?.count!! % renewalUntilNextHourglass)
|
||||
} else {
|
||||
consecutive?.offset
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -71,34 +71,43 @@ class SubscriptionPlanTest : WordSpec({
|
|||
"monthsUntilNextHourglass" should {
|
||||
beforeEach {
|
||||
plan.consecutive = SubscriptionPlanConsecutive()
|
||||
plan.consecutive?.count = 1
|
||||
plan.consecutive?.count = 0
|
||||
plan.dateTerminated = null
|
||||
}
|
||||
|
||||
"months until next hourglass with initial basic sub" {
|
||||
plan.planId = SubscriptionPlan.PLANID_BASIC
|
||||
plan.monthsUntilNextHourglass shouldBe 3
|
||||
plan.monthsUntilNextHourglass shouldBe 4
|
||||
}
|
||||
|
||||
"months until receiving first hourglass with basic sub" {
|
||||
plan.consecutive?.count = 2
|
||||
plan.planId = SubscriptionPlan.PLANID_BASIC
|
||||
plan.monthsUntilNextHourglass shouldBe 1
|
||||
}
|
||||
|
||||
"months until next hourglass with basic sub after receiving initial hourglass" {
|
||||
plan.consecutive?.count = 4
|
||||
plan.consecutive?.count = 3
|
||||
plan.planId = SubscriptionPlan.PLANID_BASIC
|
||||
plan.monthsUntilNextHourglass shouldBe 2
|
||||
plan.monthsUntilNextHourglass shouldBe 3
|
||||
}
|
||||
|
||||
"months until next hourglass with three month sub" {
|
||||
plan.consecutive?.offset = 3
|
||||
plan.planId = SubscriptionPlan.PLANID_BASIC3MONTH
|
||||
plan.monthsUntilNextHourglass shouldBe 2
|
||||
plan.monthsUntilNextHourglass shouldBe 3
|
||||
}
|
||||
|
||||
"months until next hourglass with six month sub" {
|
||||
plan.consecutive?.offset = 6
|
||||
plan.planId = SubscriptionPlan.PLANID_BASIC6MONTH
|
||||
plan.monthsUntilNextHourglass shouldBe 5
|
||||
plan.monthsUntilNextHourglass shouldBe 6
|
||||
}
|
||||
|
||||
"months until next hourglass with 12 month sub" {
|
||||
plan.consecutive?.offset = 12
|
||||
plan.planId = SubscriptionPlan.PLANID_BASIC12MONTH
|
||||
plan.monthsUntilNextHourglass shouldBe 11
|
||||
plan.monthsUntilNextHourglass shouldBe 12
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue