-
Notifications
You must be signed in to change notification settings - Fork 5
/
HolidayCreditSpec.scala
42 lines (34 loc) · 1.87 KB
/
HolidayCreditSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package com.gu.holidaystopprocessor
import java.time.LocalDate
import com.gu.holiday_stops.{Config, CurrentGuardianWeeklySubscription, HolidayCredit, RatePlan, RatePlanCharge}
import org.scalacheck.Prop.forAll
import org.scalacheck._
import org.scalatest.{EitherValues, OptionValues}
object HolidayCreditSpec extends Properties("HolidayCreditAmount") with OptionValues with EitherValues {
private val ratePlanChargeGen = for {
price <- Gen.choose(0.01, 10000)
billingPeriod <- Gen.oneOf(List("Quarter", "Annual"))
chargedThroughDate = Some(LocalDate.of(2020, 1, 1))
} yield RatePlanCharge(
name = "GW",
number = "C5",
price,
Some(billingPeriod),
effectiveStartDate = LocalDate.of(2019, 7, 10),
chargedThroughDate = chargedThroughDate,
HolidayStart__c = None,
HolidayEnd__c = None,
processedThroughDate = chargedThroughDate.map(_.minusMonths(Fixtures.billingPeriodToMonths(billingPeriod)))
)
val subscription = Fixtures.mkSubscription()
property("should be negative") = forAll(ratePlanChargeGen) { charge: RatePlanCharge =>
val ratePlans = List(RatePlan("", List(charge), Config.guardianWeeklyProductRatePlanIdsPROD.head, ""))
val currentGuardianWeeklySubscription = CurrentGuardianWeeklySubscription(subscription.copy(ratePlans = ratePlans), Fixtures.config.guardianWeeklyProductRatePlanIds)
HolidayCredit(currentGuardianWeeklySubscription.right.value) < 0
}
property("should never be overwhelmingly negative") = forAll(ratePlanChargeGen) { charge: RatePlanCharge =>
val ratePlans = List(RatePlan("", List(charge), Config.guardianWeeklyProductRatePlanIdsPROD.head, ""))
val currentGuardianWeeklySubscription = CurrentGuardianWeeklySubscription(subscription.copy(ratePlans = ratePlans), Fixtures.config.guardianWeeklyProductRatePlanIds)
HolidayCredit(currentGuardianWeeklySubscription.right.value) > -charge.price
}
}