diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/WhatYourRentIncludesForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/WhatYourRentIncludesForm.scala index 0f2535ed..154e7de0 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/WhatYourRentIncludesForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/WhatYourRentIncludesForm.scala @@ -149,11 +149,11 @@ object WhatYourRentIncludesForm extends CommonFormValidators with Mappings { if (whatYourRentIncludesForm.livingAccommodationRadio.equals("livingAccommodationYes")) { if (bedroomNumber.isEmpty) Invalid("whatYourRentIncludes.bedroom.number.required.error") - else if (Try(Integer.parseInt(bedroomNumber.get)).isFailure) + else if (Try(bedroomNumber.get.toLong).isFailure) Invalid("whatYourRentIncludes.bedroom.number.invalid.error") - else if (Integer.parseInt(bedroomNumber.get) < 1) + else if (bedroomNumber.get.toLong < 1) Invalid("whatYourRentIncludes.bedroom.number.minimum.error") - else if (Integer.parseInt(bedroomNumber.get) > 99) + else if (bedroomNumber.get.toLong > 99) Invalid("whatYourRentIncludes.bedroom.number.maximum.error") else Valid diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/WhatYourRentIncludesFormSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/WhatYourRentIncludesFormSpec.scala index a96df05a..2209c5b7 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/WhatYourRentIncludesFormSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/WhatYourRentIncludesFormSpec.scala @@ -186,6 +186,21 @@ class WhatYourRentIncludesFormSpec extends AnyWordSpec with Matchers { ) val boundForm = WhatYourRentIncludesForm.form.bind(data) + boundForm.hasErrors shouldBe true + boundForm.errors should contain(FormError("", List("whatYourRentIncludes.bedroom.number.maximum.error"))) + } + "fail to bind when bedroomNumbers input is 12 digits long" in { + val data = Map( + "livingAccommodationRadio" -> "livingAccommodationYes", + "rentPartAddressRadio" -> "Yes", + "rentEmptyShellRadio" -> "Yes", + "rentIncBusinessRatesRadio" -> "Yes", + "rentIncWaterChargesRadio" -> "Yes", + "rentIncServiceRadio" -> "Yes", + "bedroomNumbers" -> "123123123123" + ) + val boundForm = WhatYourRentIncludesForm.form.bind(data) + boundForm.hasErrors shouldBe true boundForm.errors should contain(FormError("", List("whatYourRentIncludes.bedroom.number.maximum.error"))) }