Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class InterimRentSetByTheCourtController @Inject()(interimRentSetByTheCourtView:
case (key, messages) if messages.contains("interimRentSetByTheCourt.startDate.before.1900.error") ||
messages.contains("interimRentSetByTheCourt.year.required.error") =>
formError.copy(key = "date.year")
case ("date", messages) if messages.contains("interimRentSetByTheCourt.year.format.error") =>
formError.copy(key = "date.year")
case ("date", messages) =>
formError.copy(key = "date.month")
case _ =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ trait CommonFormValidators {
monthYearEmptyValidation(input.asInstanceOf[NGRMonthYear], errorKeys)
)

protected def isMonthYearValid[A](errorKey: String): Constraint[A] =
protected def isMonthYearValid[A](monthError: String, yearError: String) : Constraint[A] =
Constraint((input: A) =>
val date = input.asInstanceOf[NGRMonthYear]
monthYearValidation(date, errorKey)
monthYearValidation(date, monthError, yearError)
)

protected def isMonthYearAfter1900[A](errorKey: String): Constraint[A] =
Expand Down Expand Up @@ -146,14 +146,16 @@ trait CommonFormValidators {
else
Valid

protected def monthYearValidation(date: NGRMonthYear, errorKey: String) = {
protected def monthYearValidation(date: NGRMonthYear, monthError: String, yearError:String) = {
val maybeMonth = date.month.toIntOption
val maybeYear = date.year.toIntOption
(maybeMonth, maybeYear) match {
case (Some(month), Some(year)) if month > 0 && month <= 12 && (month + year != 0) =>
case (Some(month), Some(year)) if month > 0 && month <= 12 =>
Valid
case _ =>
Invalid(errorKey)
case (_, None) =>
Invalid(yearError)
case (_, _) =>
Invalid(monthError)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ object InterimRentSetByTheCourtForm extends CommonFormValidators with MonthYearM
.verifying(
firstError(
isMonthYearEmpty(errorKeys("interimRentSetByTheCourt")),
isMonthYearValid("interimRentSetByTheCourt.monthYear.format.error"),
isMonthYearValid(monthError = "interimRentSetByTheCourt.month.format.error", yearError = "interimRentSetByTheCourt.year.format.error"),
isMonthYearAfter1900("interimRentSetByTheCourt.startDate.before.1900.error")
)
),
Expand Down
5 changes: 3 additions & 2 deletions conf/messages
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ date.year = Year
interimRentSetByTheCourt.interimAmount.required.error = Enter how much the interim rent was, in pounds
interimRentSetByTheCourt.interimAmount.tooLarge.error = Interim rent must be £9,999,999.99 or less
interimRentSetByTheCourt.interimAmount.format.error = Interim rent must be a number, like 50,000
interimRentSetByTheCourt.monthYear.format.error = Date your interim rent started must be a real date
interimRentSetByTheCourt.required.error = Enter the date you started paying interim rent
interimRentSetByTheCourt.month.format.error = Date your interim rent started must be a real date
interimRentSetByTheCourt.year.format.error = Date your interim rent started must be a real date
interimRentSetByTheCourt.required.error = Date you started paying the interim rent must include a month and year
interimRentSetByTheCourt.month.required.error = Date you started paying the interim rent must include a month
interimRentSetByTheCourt.year.required.error = Date you started paying the interim rent must include a year
interimRentSetByTheCourt.startDate.before.1900.error = The date you started paying interim rent must be 1900 or after
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class InterimRentSetByTheCourtFormSpec extends AnyWordSpec with Matchers {
)
val boundForm = InterimRentSetByTheCourtForm.form.bind(data)

boundForm.errors should contain(FormError("date", "interimRentSetByTheCourt.monthYear.format.error"))
boundForm.errors should contain(FormError("date", "interimRentSetByTheCourt.month.format.error"))
}
"fail to bind year before 1900 for year input field" in {
val data = Map(
Expand Down Expand Up @@ -200,7 +200,7 @@ class InterimRentSetByTheCourtFormSpec extends AnyWordSpec with Matchers {
)
val boundForm = InterimRentSetByTheCourtForm.form.bind(data)

boundForm.errors should contain(FormError("date", "interimRentSetByTheCourt.monthYear.format.error"))
boundForm.errors should contain(FormError("date", "interimRentSetByTheCourt.month.format.error"))
}

"fail to bind non numeric format for year input" in {
Expand All @@ -211,7 +211,7 @@ class InterimRentSetByTheCourtFormSpec extends AnyWordSpec with Matchers {
)
val boundForm = InterimRentSetByTheCourtForm.form.bind(data)

boundForm.errors should contain(FormError("date", "interimRentSetByTheCourt.monthYear.format.error"))
boundForm.errors should contain(FormError("date", "interimRentSetByTheCourt.year.format.error"))
}

}
Expand Down