Skip to content

Commit

Permalink
Merge pull request #618 from hmrc/CVSRP-5059
Browse files Browse the repository at this point in the history
CVSRP-5059 Added year check for claim period end date
  • Loading branch information
peckover authored May 6, 2021
2 parents f71c3af + acbc25a commit 3eda110
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
24 changes: 17 additions & 7 deletions app/forms/ClaimPeriodEndFormProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ class ClaimPeriodEndFormProvider @Inject()() extends Mappings with SchemeConfigu
isDifferentCalendarMonth(claimStart, claimEndDate),
isMoreThan14daysInFuture(claimStart, claimEndDate),
isClaimLessThan7Days(claimStart, claimEndDate),
isAfterPolicyEnd(claimEndDate)) match {
case (r @ Invalid(_), _, _, _, _) => r
case (_, r @ Invalid(_), _, _, _) => r
case (_, _, r @ Invalid(_), _, _) => r
case (_, _, _, r @ Invalid(_), _) => r
case (_, _, _, _, r @ Invalid(_)) => r
case _ => Valid
isAfterPolicyEnd(claimEndDate),
isSameYear(claimStart, claimEndDate)) match {
case (r @ Invalid(_), _, _, _, _, _) => r
case (_, r @ Invalid(_), _, _, _, _) => r
case (_, _, r @ Invalid(_), _, _, _) => r
case (_, _, _, r @ Invalid(_), _, _) => r
case (_, _, _, _, r @ Invalid(_), _) => r
case (_, _, _, _, _, r @ Invalid(_)) => r
case _ => Valid
}
}

Expand All @@ -56,6 +58,14 @@ class ClaimPeriodEndFormProvider @Inject()() extends Mappings with SchemeConfigu
}
}

val isSameYear: (LocalDate, LocalDate) => ValidationResult = (start, end) => {
if (start.getYear != end.getYear) {
Invalid("claimPeriodEnd.cannot.be.different.years")
} else {
Valid
}
}

val isDifferentCalendarMonth: (LocalDate, LocalDate) => ValidationResult = (start, end) =>
if (start.isBefore(phaseTwoStartDate) && !end.isBefore(phaseTwoStartDate)) {
Invalid("claimPeriodEnd.cannot.be.after.july")
Expand Down
1 change: 1 addition & 0 deletions conf/messages.cy
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ claimPeriodEnd.cannot.be.after.july = Nodwch ddyddiad dod i ben cyn 1 Gorffennaf
claimPeriodEnd.cannot.be.of.same.month = O 1 Gorffennaf ymlaen, mae’n rhaid i hawliadau ddechrau a dod i ben yn ystod yr un mis calendr
claimPeriodEnd.cannot.be.before.claimStart = Ni all y dyddiad dod i ben fod cyn y dyddiad dechrau
claimPeriodEnd.cannot.be.lessThan.7days = Mae’n rhaid i’r cyfnod hawlio fod yn gyfnod o 7 diwrnod o leiaf
claimPeriodEnd.cannot.be.different.years = The claim period end date must be in the same year as the claim period start date
claimPeriodEnd.legend = Dyddiad dod i ben
claimPeriodEnd.hint = Er enghraifft, 31 3 2020

Expand Down
1 change: 1 addition & 0 deletions conf/messages.en
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ claimPeriodEnd.cannot.be.of.same.month = From 1 July, claims must start and end
claimPeriodEnd.cannot.be.before.claimStart = The end date cannot be before the start date
claimPeriodEnd.cannot.be.lessThan.7days = The claim period must be at least 7 days
claimPeriodEnd.cannot.be.after.14days = The end date cannot be more than 14 days after today’s date
claimPeriodEnd.cannot.be.different.years = The claim period end date must be in the same year as the claim period start date
claimPeriodEnd.cannot.be.after.july = Enter an end date before 1 July. (From July, claims must start and end in the same calendar month).
claimPeriodEnd.legend = End date
claimPeriodEnd.hint = For example, 31 3 2020
Expand Down
18 changes: 18 additions & 0 deletions test/forms/ClaimPeriodEndFormProviderSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,24 @@ class ClaimPeriodEndFormProviderSpec extends SpecBaseControllerSpecs {

result.errors shouldBe List(FormError("endDate", "claimPeriodEnd.cannot.be.of.same.month"))
}

"fail with invalid dates - if start and end are not of the same calendar year" in {

val now = LocalDate.of(2020, 8, 15)

val form = new ClaimPeriodEndFormProvider()(now)

val data = Map(
"endDate.day" -> now.getDayOfMonth.toString,
"endDate.month" -> now.getMonthValue.toString,
"endDate.year" -> now.plusYears(1).getYear.toString
)

val result = form.bind(data)

result.errors shouldBe List(FormError("endDate", "claimPeriodEnd.cannot.be.different.years"))
}

}

"start and end should be of the same calendar month starting from June 2020" in {
Expand Down

0 comments on commit 3eda110

Please sign in to comment.