From 81ff8cf8ddeb4e5b62c251e60f0a543e6b48c7f8 Mon Sep 17 00:00:00 2001 From: mywyau <47248104+mywyau@users.noreply.github.com> Date: Thu, 6 May 2021 11:31:00 +0100 Subject: [PATCH 1/2] added year check for claimPeriod End Date --- app/forms/ClaimPeriodEndFormProvider.scala | 24 +++++++++++++------ conf/messages.en | 1 + .../ClaimPeriodEndFormProviderSpec.scala | 18 ++++++++++++++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/app/forms/ClaimPeriodEndFormProvider.scala b/app/forms/ClaimPeriodEndFormProvider.scala index 5bcef3e24..b4444bca8 100644 --- a/app/forms/ClaimPeriodEndFormProvider.scala +++ b/app/forms/ClaimPeriodEndFormProvider.scala @@ -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 } } @@ -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") diff --git a/conf/messages.en b/conf/messages.en index f36c5c1b6..08ccc8024 100644 --- a/conf/messages.en +++ b/conf/messages.en @@ -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 diff --git a/test/forms/ClaimPeriodEndFormProviderSpec.scala b/test/forms/ClaimPeriodEndFormProviderSpec.scala index a7f6623ee..d01be4c23 100644 --- a/test/forms/ClaimPeriodEndFormProviderSpec.scala +++ b/test/forms/ClaimPeriodEndFormProviderSpec.scala @@ -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 { From acbc25ac57268148f78fe1f26b0207434cecd53e Mon Sep 17 00:00:00 2001 From: mywyau <47248104+mywyau@users.noreply.github.com> Date: Thu, 6 May 2021 14:33:12 +0100 Subject: [PATCH 2/2] add welsh key for new error message --- conf/messages.cy | 1 + 1 file changed, 1 insertion(+) diff --git a/conf/messages.cy b/conf/messages.cy index 4213f0575..203282cfb 100644 --- a/conf/messages.cy +++ b/conf/messages.cy @@ -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