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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}
Expand Down