diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtController.scala index 00600d15..f5c20428 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/InterimRentSetByTheCourtController.scala @@ -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 _ => diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/CommonFormValidators.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/CommonFormValidators.scala index b8ddcff4..2c7f595e 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/CommonFormValidators.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/CommonFormValidators.scala @@ -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] = @@ -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) } } } diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/InterimRentSetByTheCourtForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/InterimRentSetByTheCourtForm.scala index 5daa5d7e..dea9f3ec 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/InterimRentSetByTheCourtForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/InterimRentSetByTheCourtForm.scala @@ -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") ) ), diff --git a/conf/messages b/conf/messages index bdc13cf4..3b8dae08 100644 --- a/conf/messages +++ b/conf/messages @@ -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 \ No newline at end of file diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/InterimRentSetByTheCourtFormSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/InterimRentSetByTheCourtFormSpec.scala index b499801b..2a6cef4f 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/InterimRentSetByTheCourtFormSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/InterimRentSetByTheCourtFormSpec.scala @@ -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( @@ -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 { @@ -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")) } }