Skip to content

Commit

Permalink
Merge 49f653d into 94feb76
Browse files Browse the repository at this point in the history
  • Loading branch information
pvighi committed Aug 3, 2018
2 parents 94feb76 + 49f653d commit 56a4eed
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
Expand Up @@ -24,14 +24,16 @@ case class ProductInfo(
startDateRules: Option[StartDateRules] = None
)

case class SelectableWindow(
cutOffDayInclusive: Option[DayOfWeek] = None,
startDaysAfterCutOff: Option[Int] = None,
sizeInDays: Option[Int] = None
)
case class StartDateRules(
daysOfWeek: Option[List[DayOfWeek]] = None,
cutOffDayInclusive: Option[DayOfWeek] = None,
minDaysAfterCutOff: Option[Int] = None,
windowSizeDays: Option[Int] = None,
selectableWindow: Option[SelectableWindow] = None
)


case class Group(label: String, products: List[ProductInfo])

case class Catalog(groups: List[Group])
Expand All @@ -40,7 +42,10 @@ object DayOfWeek {
implicit val writes: Writes[DayOfWeek] = { (day: DayOfWeek) => JsString(day.toString) }
}

object StartDateRules{
object SelectableWindow {
implicit val writes = Json.writes[SelectableWindow]
}
object StartDateRules {
implicit val writes = Json.writes[StartDateRules]
}
object ProductInfo {
Expand Down
Expand Up @@ -21,11 +21,14 @@ object Handler extends Logging {
}

val catalog = {
val voucherEverydayRules = StartDateRules(
val voucherWindowRules = SelectableWindow(
cutOffDayInclusive = Some(Tuesday),
startDaysAfterCutOff = Some(20),
sizeInDays = Some(28)
)
val voucherEverydayRules = StartDateRules(
daysOfWeek = Some(List(Monday)),
minDaysAfterCutOff = Some(20),
windowSizeDays = Some(28)
selectableWindow = Some(voucherWindowRules)
)

val voucherEveryday = ProductInfo(
Expand All @@ -43,8 +46,11 @@ object Handler extends Logging {
startDateRules = Some(weekendsRule)
)

val contributionWindowRules = SelectableWindow(
sizeInDays = Some(1)
)
val contributionRules = StartDateRules(
windowSizeDays = Some(1)
selectableWindow = Some(contributionWindowRules)
)

val monthlyContribution = ProductInfo(
Expand Down
Expand Up @@ -6,11 +6,14 @@ import play.api.libs.json.Json
class CatalogTest extends FlatSpec with Matchers {
it should "serialise catalog" in {

val everyDayRules = StartDateRules(
val everyDayWindowRules = SelectableWindow(
cutOffDayInclusive = Some(Tuesday),
startDaysAfterCutOff = Some(20),
sizeInDays = Some(28)
)
val everyDayRules = StartDateRules(
daysOfWeek = Some(List(Monday)),
minDaysAfterCutOff = Some(20),
windowSizeDays = Some(28)
selectableWindow = Some(everyDayWindowRules)
)

val voucherEveryday = ProductInfo(
Expand Down Expand Up @@ -45,20 +48,24 @@ class CatalogTest extends FlatSpec with Matchers {
| "id": "voucher_weekend",
| "label": "Weekend",
| "startDateRules" : {
| "cutOffDayInclusive": "Tuesday",
| "minDaysAfterCutOff" : 20,
| "windowSizeDays" : 28,
| "selectableWindow" : {
| "cutOffDayInclusive": "Tuesday",
| "startDaysAfterCutOff" : 20,
| "sizeInDays" : 28
| },
| "daysOfWeek": ["Saturday", "Sunday"]
| }
| },
| {
| "id": "voucher_everyday",
| "label": "Every day",
| "startDateRules" : {
| "cutOffDayInclusive": "Tuesday",
| "minDaysAfterCutOff" : 20,
| "windowSizeDays" : 28,
| "daysOfWeek": ["Monday"]
| "selectableWindow" : {
| "cutOffDayInclusive": "Tuesday",
| "startDaysAfterCutOff" : 20,
| "sizeInDays" : 28
| },
| "daysOfWeek": ["Monday"]
| }
| }
| ]
Expand Down

0 comments on commit 56a4eed

Please sign in to comment.