From 84daf2f9469293484ac24d4fe6214e7b3a76ec9d Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Tue, 7 Oct 2025 08:27:56 +0100 Subject: [PATCH 1/6] NGR-1133 - Added new did you get money from landlord page --- ...DidYouGetMoneyFromLandlordController.scala | 83 +++++++++++++ .../DidYouGetMoneyFromLandlordForm.scala | 55 +++++++++ .../navigation/Navigator.scala | 2 + .../DidYouGetMoneyFromLandlordPage.scala | 27 ++++ .../DidYouGetMoneyFromLandlordView.scala.html | 46 +++++++ conf/app.routes | 6 + conf/messages | 4 + ...ouGetMoneyFromLandlordControllerSpec.scala | 115 ++++++++++++++++++ .../DidYouGetMoneyFromLandlordFormSpec.scala | 81 ++++++++++++ .../DidYouGetMoneyFromLandlordViewSpec.scala | 90 ++++++++++++++ 10 files changed, 509 insertions(+) create mode 100644 app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala create mode 100644 app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala create mode 100644 app/uk/gov/hmrc/ngrraldfrontend/pages/DidYouGetMoneyFromLandlordPage.scala create mode 100644 app/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordView.scala.html create mode 100644 test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordControllerSpec.scala create mode 100644 test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordFormSpec.scala create mode 100644 test/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordViewSpec.scala diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala new file mode 100644 index 00000000..701d3c99 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala @@ -0,0 +1,83 @@ +/* + * Copyright 2025 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package uk.gov.hmrc.ngrraldfrontend.controllers + +import play.api.i18n.I18nSupport +import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} +import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, DataRetrievalAction} +import uk.gov.hmrc.ngrraldfrontend.config.AppConfig +import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios +import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouGetMoneyFromLandlordForm +import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouGetMoneyFromLandlordForm.form +import uk.gov.hmrc.ngrraldfrontend.models.{Mode, UserAnswers} +import uk.gov.hmrc.ngrraldfrontend.navigation.Navigator +import uk.gov.hmrc.ngrraldfrontend.pages.DidYouGetMoneyFromLandlordPage +import uk.gov.hmrc.ngrraldfrontend.repo.SessionRepository +import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouGetMoneyFromLandlordView +import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController + +import javax.inject.Inject +import scala.concurrent.{ExecutionContext, Future} + +class DidYouGetMoneyFromLandlordController @Inject()(didYouGetMoneyFromLandlordView: DidYouGetMoneyFromLandlordView, + authenticate: AuthRetrievals, + getData: DataRetrievalAction, + sessionRepository: SessionRepository, + navigator: Navigator, + mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext) + extends FrontendController(mcc) with I18nSupport { + + + def show(mode: Mode): Action[AnyContent] = { + (authenticate andThen getData).async { implicit request => + val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(DidYouGetMoneyFromLandlordPage) match { + case None => form + case Some(value) => form.fill(DidYouGetMoneyFromLandlordForm(if(value) {"Yes"} else {"No"})) + + } + Future.successful(Ok(didYouGetMoneyFromLandlordView( + selectedPropertyAddress = request.property.addressFull, + form = preparedForm, + ngrRadio = buildRadios(preparedForm, DidYouGetMoneyFromLandlordForm.ngrRadio(preparedForm)), + mode = mode + ))) + } + } + + def submit(mode: Mode): Action[AnyContent] = + (authenticate andThen getData).async { implicit request => + form.bindFromRequest().fold( + formWithErrors => { + Future.successful(BadRequest(didYouGetMoneyFromLandlordView( + form = formWithErrors, + ngrRadio = buildRadios(formWithErrors, DidYouGetMoneyFromLandlordForm .ngrRadio(formWithErrors)), + selectedPropertyAddress = request.property.addressFull, + mode = mode + ))) + }, + radioValue => + for { + updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(DidYouGetMoneyFromLandlordPage, radioValue.radio match { + case "Yes" => true + case _ => false + })) + _ <- sessionRepository.set(updatedAnswers) + } yield Redirect(navigator.nextPage(DidYouGetMoneyFromLandlordPage, mode, updatedAnswers)) + + ) + } +} diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala new file mode 100644 index 00000000..ffc48266 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala @@ -0,0 +1,55 @@ +/* + * Copyright 2025 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package uk.gov.hmrc.ngrraldfrontend.models.forms + +import play.api.data.Form +import play.api.data.Forms.{mapping, optional} +import play.api.data.validation.{Constraint, Invalid, Valid} +import play.api.i18n.* +import play.api.libs.json.{Json, OFormat} +import uk.gov.hmrc.govukfrontend.views.Aliases.Text +import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Legend +import uk.gov.hmrc.ngrraldfrontend.models.components.* +import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{noButton, yesButton} +import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings + +final case class DidYouGetMoneyFromLandlordForm(radio: String) + +object DidYouGetMoneyFromLandlordForm extends CommonFormValidators with Mappings{ + implicit val format: OFormat[DidYouGetMoneyFromLandlordForm] = Json.format[DidYouGetMoneyFromLandlordForm] + + private lazy val radioUnselectedError = "didYouGetMoneyFromLandlord.empty.error" + private val radio = "didYouGetMoneyFromLandlord-radio-value" + + val messagesApi: MessagesApi = new DefaultMessagesApi() + val lang: Lang = Lang.defaultLang + val messages: Messages = MessagesImpl(lang, messagesApi) + + def unapply(didYouGetMoneyFromLandlordForm: DidYouGetMoneyFromLandlordForm): Option[(String)] = + Some(DidYouGetMoneyFromLandlordForm.radio) + + def ngrRadio(form: Form[DidYouGetMoneyFromLandlordForm])(implicit messages: Messages): NGRRadio = + NGRRadio(NGRRadioName(radio), ngrTitle = Some(Legend(content = Text(messages("didYouGetMoneyFromLandlord.title")), classes = "govuk-fieldset__legend--l", isPageHeading = true)), NGRRadioButtons = Seq(yesButton, noButton)) + + def form: Form[DidYouGetMoneyFromLandlordForm] = { + Form( + mapping( + radio -> radioText(radioUnselectedError), + )(DidYouGetMoneyFromLandlordForm.apply)(DidYouGetMoneyFromLandlordForm.unapply) + ) + } +} diff --git a/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala b/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala index eb19a400..3613de9e 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/navigation/Navigator.scala @@ -143,7 +143,9 @@ class Navigator @Inject()() { } case RentFreePeriodPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.RentDatesAgreeStartController.show(NormalMode) case ConfirmBreakClausePage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.show(NormalMode) //TODO This needs to be amended when the journey is completed + case DidYouGetMoneyFromLandlordPage => _ => uk.gov.hmrc.ngrraldfrontend.controllers.routes.LandlordController.show(NormalMode) //TODO This needs to be amended when the journey is completed + case DoYouPayExtraForParkingSpacesPage => answers => answers.get(DoYouPayExtraForParkingSpacesPage) match { case Some(value) => value match { diff --git a/app/uk/gov/hmrc/ngrraldfrontend/pages/DidYouGetMoneyFromLandlordPage.scala b/app/uk/gov/hmrc/ngrraldfrontend/pages/DidYouGetMoneyFromLandlordPage.scala new file mode 100644 index 00000000..cffbd693 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/pages/DidYouGetMoneyFromLandlordPage.scala @@ -0,0 +1,27 @@ +/* + * Copyright 2025 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package uk.gov.hmrc.ngrraldfrontend.pages + +import play.api.libs.json.JsPath + +case object DidYouGetMoneyFromLandlordPage extends QuestionPage[Boolean] { + + override def toString: String = "confirmBreakClause" + + override def path: JsPath = JsPath \ toString + +} diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordView.scala.html new file mode 100644 index 00000000..c014c789 --- /dev/null +++ b/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordView.scala.html @@ -0,0 +1,46 @@ +@* + * Copyright 2025 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *@ + +@import uk.gov.hmrc.ngrraldfrontend.config.AppConfig + +@import uk.gov.hmrc.govukfrontend.views.html.components._ +@import uk.gov.hmrc.govukfrontend.views.Aliases._ +@import uk.gov.hmrc.ngrraldfrontend.views.html.components._ +@import uk.gov.hmrc.ngrraldfrontend.viewmodels.govuk.all._ +@import uk.gov.hmrc.ngrraldfrontend.config.AppConfig +@import uk.gov.hmrc.ngrraldfrontend.models.components.NavigationBarContent +@import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouGetMoneyFromLandlordForm + +@this( + layout: Layout, + formHelper: FormWithCSRF, + govukErrorSummary: GovukErrorSummary, + govukRadios : GovukRadios, + saveAndContinueButton: saveAndContinueButton +) + +@(selectedPropertyAddress: String, form: Form[DidYouGetMoneyFromLandlordForm], ngrRadio: Radios, mode: Mode)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig) + +@layout(pageTitle = Some(messages("didYouGetMoneyFromLandlord.title")), showBackLink = true, fullWidth = false) { + @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DidYouGetMoneyFromLandlordController.submit(mode), Symbol("autoComplete") -> "off") { + @if(form.errors.nonEmpty) { + @govukErrorSummary(ErrorSummaryViewModel(form)) + } + @selectedPropertyAddress + @govukRadios(ngrRadio) + @saveAndContinueButton(msg = messages("service.continue"), isStartButton = false) + } +} \ No newline at end of file diff --git a/conf/app.routes b/conf/app.routes index 75ee84b7..4f355e69 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -28,6 +28,12 @@ POST /landlord uk.gov.hmrc.ngrraldfront GET /landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.show(mode: Mode = CheckMode) POST /landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.LandlordController.submit(mode: Mode = CheckMode) +#Did you get money from landlord +GET /did-you-get-money-from-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouGetMoneyFromLandlordController.show(mode: Mode = NormalMode) +POST /did-you-get-money-from-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouGetMoneyFromLandlordController.submit(mode: Mode = NormalMode) +GET /did-you-get-money-from-landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.DidYouGetMoneyFromLandlordController.show(mode: Mode = CheckMode) +POST /did-you-get-money-from-landlord/change uk.gov.hmrc.ngrraldfrontend.controllers.DidYouGetMoneyFromLandlordController.submit(mode: Mode = CheckMode) + #What is your rent based on GET /what-is-your-rent-based-on uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.show(mode: Mode = NormalMode) POST /what-is-your-rent-based-on uk.gov.hmrc.ngrraldfrontend.controllers.WhatIsYourRentBasedOnController.submit(mode: Mode = NormalMode) diff --git a/conf/messages b/conf/messages index a9ac0a6e..28a595fd 100644 --- a/conf/messages +++ b/conf/messages @@ -398,3 +398,7 @@ repairsAndInsurance.radio.youAndLandlord = You and the landlord repairsAndInsurance.internalRepairs.radio.required.error = Select who pays for internal repairs repairsAndInsurance.externalRepairs.radio.required.error = Select who pays for external repairs repairsAndInsurance.buildingInsurance.radio.required.error = Select who pays for buildings insurance + +#DidYouGetMoneyFromLandlord +didYouGetMoneyFromLandlord.title = Did you get any money from the landlord or previous tenant to take on the lease? +didYouGetMoneyFromLandlord.empty.error = Select yes if you got any money from the landlord or previous tenant to take on the lease \ No newline at end of file diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordControllerSpec.scala new file mode 100644 index 00000000..c608b10f --- /dev/null +++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordControllerSpec.scala @@ -0,0 +1,115 @@ +/* + * Copyright 2025 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package uk.gov.hmrc.ngrraldfrontend.controllers + +import org.jsoup.Jsoup +import org.mockito.ArgumentMatchers.any +import org.mockito.Mockito.when +import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER} +import play.api.test.FakeRequest +import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status} +import uk.gov.hmrc.auth.core.Nino +import uk.gov.hmrc.http.{HeaderNames, NotFoundException} +import uk.gov.hmrc.ngrraldfrontend.helpers.ControllerSpecSupport +import uk.gov.hmrc.ngrraldfrontend.models.AgreementType.NewAgreement +import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId +import uk.gov.hmrc.ngrraldfrontend.models.{AuthenticatedUserRequest, NormalMode, UserAnswers} +import uk.gov.hmrc.ngrraldfrontend.pages.{DidYouGetMoneyFromLandlordPage, DoesYourRentIncludeParkingPage} +import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouGetMoneyFromLandlordView + +import scala.concurrent.Future + +class DidYouGetMoneyFromLandlordControllerSpec extends ControllerSpecSupport { + val pageTitle = "Did you get any money from the landlord or previous tenant to take on the lease?" + val view: DidYouGetMoneyFromLandlordView = inject[DidYouGetMoneyFromLandlordView] + val controllerNoProperty: DidYouGetMoneyFromLandlordController = new DidYouGetMoneyFromLandlordController(view, fakeAuth, fakeData(None), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec) + val controllerProperty: Option[UserAnswers] => DidYouGetMoneyFromLandlordController = answers => new DidYouGetMoneyFromLandlordController(view, fakeAuth, fakeDataProperty(Some(property),answers), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec) + val confirmBreakClauseAnswers: Option[UserAnswers] = UserAnswers("id").set(DidYouGetMoneyFromLandlordPage, true).toOption + + + "Confirm Break Clause Controller" must { + "method show" must { + "Return OK and the correct view" in { + val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest) + status(result) mustBe OK + val content = contentAsString(result) + content must include(pageTitle) + } + "Return NotFoundException when property is not found in the mongo" in { + when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None)) + val exception = intercept[NotFoundException] { + await(controllerNoProperty.show(NormalMode)(authenticatedFakeRequest)) + } + exception.getMessage contains "Could not find answers in backend mongo" mustBe true + } + } + + "method submit" must { + "Return See_Other and the correct view after submitting yes" in { + when(mockSessionRepository.set(any())).thenReturn(Future.successful(true)) + val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouGetMoneyFromLandlordController.submit(NormalMode)) + .withFormUrlEncodedBody( + "didYouGetMoneyFromLandlord-radio-value" -> "Yes", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") //TODO this is currently going to the wrong page as the journey hasn't yet been completed + }) + status(result) mustBe SEE_OTHER + redirectLocation(result) mustBe Some(routes.LandlordController.show(NormalMode).url) + } + "Return See_Other and the correct view after submitting no" in { + when(mockSessionRepository.set(any())).thenReturn(Future.successful(true)) + val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouGetMoneyFromLandlordController.submit(NormalMode)) + .withFormUrlEncodedBody( + "didYouGetMoneyFromLandlord-radio-value" -> "No", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") //TODO this is currently going to the wrong page as the journey hasn't yet been completed + }) + status(result) mustBe SEE_OTHER + redirectLocation(result) mustBe Some(routes.LandlordController.show(NormalMode).url) + } + "Return Form with Errors when no radio selection is input" in { + val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouGetMoneyFromLandlordController.submit(NormalMode)) + .withFormUrlEncodedBody( + "didYouGetMoneyFromLandlord-radio-value" -> "", + ) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) + result.map(result => { + result.header.headers.get("Location") mustBe Some("/ngr-rald-frontend/landlord") //TODO this is currently going to the wrong page as the journey hasn't yet been completed + }) + status(result) mustBe BAD_REQUEST + val content = contentAsString(result) + content must include(pageTitle) + content must include("Select yes if you got any money from the landlord or previous tenant to take on the lease") + } + + "Return Exception if no address is in the mongo" in { + when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None)) + val exception = intercept[NotFoundException] { + await(controllerNoProperty.submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.LandlordController.submit(NormalMode)) + .withFormUrlEncodedBody(("what-type-of-agreement-radio", "")) + .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some(""))))) + } + exception.getMessage contains "Could not find answers in backend mongo" mustBe true + } + } + } +} + diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordFormSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordFormSpec.scala new file mode 100644 index 00000000..c530b220 --- /dev/null +++ b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordFormSpec.scala @@ -0,0 +1,81 @@ +/* + * Copyright 2025 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package uk.gov.hmrc.ngrraldfrontend.models.forms + +import org.scalatest.flatspec.AnyFlatSpec +import org.scalatest.matchers.should.Matchers +import play.api.data.FormError +import play.api.libs.json.Json + +class DidYouGetMoneyFromLandlordFormSpec extends AnyFlatSpec with Matchers { + + val validData = Map( + "didYouGetMoneyFromLandlord-radio-value" -> "Yes" + ) + + "didYouGetMoneyFromLandlordForm" should "bind valid data successfully" in { + val boundForm = DidYouGetMoneyFromLandlordForm.form.bind(validData) + + boundForm.errors shouldBe empty + boundForm.value shouldBe Some(DidYouGetMoneyFromLandlordForm("Yes")) + } + + it should "fail when didYouGetMoneyFromLandlord (radio) is missing" in { + val data = validData - "didYouGetMoneyFromLandlord-radio-value" + val boundForm = DidYouGetMoneyFromLandlordForm.form.bind(data) + + boundForm.errors shouldBe List(FormError("didYouGetMoneyFromLandlord-radio-value", List("didYouGetMoneyFromLandlord.empty.error"), List())) + } + + it should "fail to bind when didYouGetMoneyFromLandlord is empty" in { + val data = Map("didYouGetMoneyFromLandlord-radio-value" -> "") + val boundForm = DidYouGetMoneyFromLandlordForm.form.bind(data) + + boundForm.hasErrors shouldBe true + boundForm.errors should contain(FormError("didYouGetMoneyFromLandlord-radio-value", List("didYouGetMoneyFromLandlord.empty.error"))) + } + + it should "fail when no is selected" in { + val data = Map( + "didYouGetMoneyFromLandlord-radio-value" -> "No", + ) + + val boundForm = DidYouGetMoneyFromLandlordForm.form.bind(data) + + boundForm.errors shouldBe empty + boundForm.value shouldBe Some(DidYouGetMoneyFromLandlordForm("No")) + } + + "DoesYourRentIncludeParkingForm.format" should "serialize to JSON correctly" in { + val form = DidYouGetMoneyFromLandlordForm("Yes") + val json = Json.toJson(form) + + json shouldBe Json.obj( + "radio" -> "Yes", + ) + } + + it should "deserialize from JSON correctly" in { + val json = Json.obj( + "radio" -> "No", + ) + + val result = json.validate[DidYouGetMoneyFromLandlordForm] + result.isSuccess shouldBe true + result.get shouldBe DidYouGetMoneyFromLandlordForm("No") + } +} diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordViewSpec.scala new file mode 100644 index 00000000..98a80887 --- /dev/null +++ b/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordViewSpec.scala @@ -0,0 +1,90 @@ +/* + * Copyright 2025 HM Revenue & Customs + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package uk.gov.hmrc.ngrraldfrontend.views + +import org.jsoup.Jsoup +import org.jsoup.nodes.Document +import uk.gov.hmrc.govukfrontend.views.Aliases.Text +import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Legend +import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios +import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec +import uk.gov.hmrc.ngrraldfrontend.models.NormalMode +import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{buildRadios, noButton, yesButton} +import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioName} +import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouGetMoneyFromLandlordForm +import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouGetMoneyFromLandlordView + +class DidYouGetMoneyFromLandlordViewSpec extends ViewBaseSpec { + lazy val view: DidYouGetMoneyFromLandlordView = inject[DidYouGetMoneyFromLandlordView] + + object Strings { + val heading = "Did you get any money from the landlord or previous tenant to take on the lease?" + val radio1 = "Yes" + val radio2 = "No" + val continue = "Continue" + } + + object Selectors { + val heading = "#main-content > div > div.govuk-grid-column-two-thirds > form > div > fieldset > legend > h1" + val hint = "#main-content > div > div.govuk-grid-column-two-thirds > form > p" + val radio1 = "#main-content > div > div.govuk-grid-column-two-thirds > form > div > fieldset > div > div:nth-child(1) > label" + val radio2 = "#main-content > div > div.govuk-grid-column-two-thirds > form > div > fieldset > div > div:nth-child(2) > label" + val continue = "#continue" + } + + val address = "5 Brixham Marina, Berry Head Road, Brixham, Devon, TQ5 9BW" + private val ngrRadio: NGRRadio = NGRRadio(NGRRadioName("didYouGetMoneyFromLandlord-radio-value"),ngrTitle = Some(Legend(content = Text(messages("didYouGetMoneyFromLandlord.title")), classes = "govuk-fieldset__legend--l", isPageHeading = true)) ,NGRRadioButtons = Seq(yesButton, noButton)) + val form = DidYouGetMoneyFromLandlordForm.form.fillAndValidate(DidYouGetMoneyFromLandlordForm("Yes")) + val radio: Radios = buildRadios(form, ngrRadio) + + "DidYouGetMoneyFromLandlordView" must { + val didYouGetMoneyFromLandlordView = view(address, form, radio, NormalMode) + lazy implicit val document: Document = Jsoup.parse(didYouGetMoneyFromLandlordView.body) + val htmlApply = view.apply(address, form, radio, NormalMode).body + val htmlRender = view.render(address, form, radio, NormalMode, request, messages, mockConfig).body + lazy val htmlF = view.f(address, form, radio, NormalMode) + + "htmlF is not empty" in { + htmlF.toString() must not be empty + } + + "apply must be the same as render" in { + htmlApply mustBe htmlRender + } + + "render is not empty" in { + htmlRender must not be empty + } + + "show correct heading" in { + elementText(Selectors.heading) mustBe Strings.heading + } + + "show correct radio 1" in { + elementText(Selectors.radio1) mustBe Strings.radio1 + } + + "show correct radio 2" in { + elementText(Selectors.radio2) mustBe Strings.radio2 + } + + "show correct continue button" in { + elementText(Selectors.continue) mustBe Strings.continue + } + } +} + From f906155af3f22cd5e8c17c53b1a37691aafe7ec1 Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Tue, 7 Oct 2025 09:33:02 +0100 Subject: [PATCH 2/6] NGR-1133 - Fixed issue --- .../models/forms/DidYouGetMoneyFromLandlordForm.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala index ffc48266..dfc8affb 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala @@ -23,8 +23,8 @@ import play.api.i18n.* import play.api.libs.json.{Json, OFormat} import uk.gov.hmrc.govukfrontend.views.Aliases.Text import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Legend -import uk.gov.hmrc.ngrraldfrontend.models.components.* import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{noButton, yesButton} +import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioButtons, NGRRadioName} import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings final case class DidYouGetMoneyFromLandlordForm(radio: String) From 305aa7e64741b63792605013bd6c47a5470ba7dd Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Tue, 7 Oct 2025 10:34:50 +0100 Subject: [PATCH 3/6] NGR-1133 - Resolved test issue --- ...DidYouGetMoneyFromLandlordController.scala | 4 +-- .../DidYouGetMoneyFromLandlordForm.scala | 27 ++++++++++++------- .../DidYouGetMoneyFromLandlordViewSpec.scala | 6 ++--- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala index 701d3c99..c0a55346 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala @@ -52,7 +52,7 @@ class DidYouGetMoneyFromLandlordController @Inject()(didYouGetMoneyFromLandlord Future.successful(Ok(didYouGetMoneyFromLandlordView( selectedPropertyAddress = request.property.addressFull, form = preparedForm, - ngrRadio = buildRadios(preparedForm, DidYouGetMoneyFromLandlordForm.ngrRadio(preparedForm)), + ngrRadio = buildRadios(preparedForm, DidYouGetMoneyFromLandlordForm.moneyLandlordRadio), mode = mode ))) } @@ -64,7 +64,7 @@ class DidYouGetMoneyFromLandlordController @Inject()(didYouGetMoneyFromLandlord formWithErrors => { Future.successful(BadRequest(didYouGetMoneyFromLandlordView( form = formWithErrors, - ngrRadio = buildRadios(formWithErrors, DidYouGetMoneyFromLandlordForm .ngrRadio(formWithErrors)), + ngrRadio = buildRadios(formWithErrors, DidYouGetMoneyFromLandlordForm.moneyLandlordRadio), selectedPropertyAddress = request.property.addressFull, mode = mode ))) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala index dfc8affb..d7e3733c 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala @@ -23,33 +23,40 @@ import play.api.i18n.* import play.api.libs.json.{Json, OFormat} import uk.gov.hmrc.govukfrontend.views.Aliases.Text import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Legend -import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{noButton, yesButton} -import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioButtons, NGRRadioName} +import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio +import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{ngrRadio, noButton, yesButton} import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings final case class DidYouGetMoneyFromLandlordForm(radio: String) -object DidYouGetMoneyFromLandlordForm extends CommonFormValidators with Mappings{ +object DidYouGetMoneyFromLandlordForm extends Mappings{ implicit val format: OFormat[DidYouGetMoneyFromLandlordForm] = Json.format[DidYouGetMoneyFromLandlordForm] private lazy val radioUnselectedError = "didYouGetMoneyFromLandlord.empty.error" - private val radio = "didYouGetMoneyFromLandlord-radio-value" + private val moneyFromLandlordRadio = "didYouGetMoneyFromLandlord-radio-value" val messagesApi: MessagesApi = new DefaultMessagesApi() val lang: Lang = Lang.defaultLang val messages: Messages = MessagesImpl(lang, messagesApi) - def unapply(didYouGetMoneyFromLandlordForm: DidYouGetMoneyFromLandlordForm): Option[(String)] = - Some(DidYouGetMoneyFromLandlordForm.radio) - - def ngrRadio(form: Form[DidYouGetMoneyFromLandlordForm])(implicit messages: Messages): NGRRadio = - NGRRadio(NGRRadioName(radio), ngrTitle = Some(Legend(content = Text(messages("didYouGetMoneyFromLandlord.title")), classes = "govuk-fieldset__legend--l", isPageHeading = true)), NGRRadioButtons = Seq(yesButton, noButton)) + def unapply(didYouGetMoneyFromLandlordForm: DidYouGetMoneyFromLandlordForm): Option[String] = Some(didYouGetMoneyFromLandlordForm.radio) def form: Form[DidYouGetMoneyFromLandlordForm] = { Form( mapping( - radio -> radioText(radioUnselectedError), + moneyFromLandlordRadio -> radioText(radioUnselectedError), )(DidYouGetMoneyFromLandlordForm.apply)(DidYouGetMoneyFromLandlordForm.unapply) ) } + + def moneyLandlordRadio(implicit messages: Messages): NGRRadio = + ngrRadio( + radioName = moneyFromLandlordRadio, + radioButtons = Seq( + yesButton(radioContent = "service.yes"), + noButton(radioContent = "service.no") + ), + ngrTitle = "didYouGetMoneyFromLandlord.title", + ngrTitleClass = "govuk-fieldset__legend--l" + ) } diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordViewSpec.scala index 98a80887..91f51ae2 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordViewSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouGetMoneyFromLandlordViewSpec.scala @@ -23,8 +23,8 @@ import uk.gov.hmrc.govukfrontend.views.viewmodels.fieldset.Legend import uk.gov.hmrc.govukfrontend.views.viewmodels.radios.Radios import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec import uk.gov.hmrc.ngrraldfrontend.models.NormalMode -import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.{buildRadios, noButton, yesButton} -import uk.gov.hmrc.ngrraldfrontend.models.components.{NGRRadio, NGRRadioName} +import uk.gov.hmrc.ngrraldfrontend.models.components.* +import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouGetMoneyFromLandlordForm import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouGetMoneyFromLandlordView @@ -47,7 +47,7 @@ class DidYouGetMoneyFromLandlordViewSpec extends ViewBaseSpec { } val address = "5 Brixham Marina, Berry Head Road, Brixham, Devon, TQ5 9BW" - private val ngrRadio: NGRRadio = NGRRadio(NGRRadioName("didYouGetMoneyFromLandlord-radio-value"),ngrTitle = Some(Legend(content = Text(messages("didYouGetMoneyFromLandlord.title")), classes = "govuk-fieldset__legend--l", isPageHeading = true)) ,NGRRadioButtons = Seq(yesButton, noButton)) + private val ngrRadio: NGRRadio = DidYouGetMoneyFromLandlordForm.moneyLandlordRadio val form = DidYouGetMoneyFromLandlordForm.form.fillAndValidate(DidYouGetMoneyFromLandlordForm("Yes")) val radio: Radios = buildRadios(form, ngrRadio) From d0de934189412d7618f3448535043862c9a1e811 Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Fri, 10 Oct 2025 13:44:08 +0100 Subject: [PATCH 4/6] NGR-1133 - Amended as per Annas comments --- .../DidYouGetMoneyFromLandlordController.scala | 7 ++----- .../forms/DidYouGetMoneyFromLandlordForm.scala | 4 ++-- ...idYouGetMoneyFromLandlordControllerSpec.scala | 16 ++++++++++++---- .../DidYouGetMoneyFromLandlordFormSpec.scala | 8 ++++---- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala index c0a55346..8777783e 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordController.scala @@ -46,7 +46,7 @@ class DidYouGetMoneyFromLandlordController @Inject()(didYouGetMoneyFromLandlord (authenticate andThen getData).async { implicit request => val preparedForm = request.userAnswers.getOrElse(UserAnswers(request.credId)).get(DidYouGetMoneyFromLandlordPage) match { case None => form - case Some(value) => form.fill(DidYouGetMoneyFromLandlordForm(if(value) {"Yes"} else {"No"})) + case Some(value) => form.fill(DidYouGetMoneyFromLandlordForm(value.toString)) } Future.successful(Ok(didYouGetMoneyFromLandlordView( @@ -71,10 +71,7 @@ class DidYouGetMoneyFromLandlordController @Inject()(didYouGetMoneyFromLandlord }, radioValue => for { - updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(DidYouGetMoneyFromLandlordPage, radioValue.radio match { - case "Yes" => true - case _ => false - })) + updatedAnswers <- Future.fromTry(request.userAnswers.getOrElse(UserAnswers(request.credId)).set(DidYouGetMoneyFromLandlordPage, radioValue.radio.toBoolean)) _ <- sessionRepository.set(updatedAnswers) } yield Redirect(navigator.nextPage(DidYouGetMoneyFromLandlordPage, mode, updatedAnswers)) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala index d7e3733c..69d13f3f 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordForm.scala @@ -53,8 +53,8 @@ object DidYouGetMoneyFromLandlordForm extends Mappings{ ngrRadio( radioName = moneyFromLandlordRadio, radioButtons = Seq( - yesButton(radioContent = "service.yes"), - noButton(radioContent = "service.no") + yesButton(), + noButton() ), ngrTitle = "didYouGetMoneyFromLandlord.title", ngrTitleClass = "govuk-fieldset__legend--l" diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordControllerSpec.scala index c608b10f..3c21e429 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordControllerSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouGetMoneyFromLandlordControllerSpec.scala @@ -38,10 +38,10 @@ class DidYouGetMoneyFromLandlordControllerSpec extends ControllerSpecSupport { val view: DidYouGetMoneyFromLandlordView = inject[DidYouGetMoneyFromLandlordView] val controllerNoProperty: DidYouGetMoneyFromLandlordController = new DidYouGetMoneyFromLandlordController(view, fakeAuth, fakeData(None), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec) val controllerProperty: Option[UserAnswers] => DidYouGetMoneyFromLandlordController = answers => new DidYouGetMoneyFromLandlordController(view, fakeAuth, fakeDataProperty(Some(property),answers), mockSessionRepository, mockNavigator, mcc)(mockConfig, ec) - val confirmBreakClauseAnswers: Option[UserAnswers] = UserAnswers("id").set(DidYouGetMoneyFromLandlordPage, true).toOption + val didYouGetMoneyFromLandlordAnswers: Option[UserAnswers] = UserAnswers("id").set(DidYouGetMoneyFromLandlordPage, true).toOption - "Confirm Break Clause Controller" must { + "DidYouGetMoneyFromLandlord Controller" must { "method show" must { "Return OK and the correct view" in { val result = controllerProperty(None).show(NormalMode)(authenticatedFakeRequest) @@ -49,6 +49,14 @@ class DidYouGetMoneyFromLandlordControllerSpec extends ControllerSpecSupport { val content = contentAsString(result) content must include(pageTitle) } + "return OK and the correct view with prepopulated data" in { + val result = controllerProperty(didYouGetMoneyFromLandlordAnswers).show(NormalMode)(authenticatedFakeRequest) + status(result) mustBe OK + val content = contentAsString(result) + val document = Jsoup.parse(content) + document.select("input[type=radio][name=didYouGetMoneyFromLandlord-radio-value][value=true]").hasAttr("checked") mustBe true + document.select("input[type=radio][name=didYouGetMoneyFromLandlord-radio-value][value=false]").hasAttr("checked") mustBe false + } "Return NotFoundException when property is not found in the mongo" in { when(mockNGRConnector.getLinkedProperty(any[CredId])(any())).thenReturn(Future.successful(None)) val exception = intercept[NotFoundException] { @@ -63,7 +71,7 @@ class DidYouGetMoneyFromLandlordControllerSpec extends ControllerSpecSupport { when(mockSessionRepository.set(any())).thenReturn(Future.successful(true)) val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouGetMoneyFromLandlordController.submit(NormalMode)) .withFormUrlEncodedBody( - "didYouGetMoneyFromLandlord-radio-value" -> "Yes", + "didYouGetMoneyFromLandlord-radio-value" -> "true", ) .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) result.map(result => { @@ -76,7 +84,7 @@ class DidYouGetMoneyFromLandlordControllerSpec extends ControllerSpecSupport { when(mockSessionRepository.set(any())).thenReturn(Future.successful(true)) val result = controllerProperty(None).submit(NormalMode)(AuthenticatedUserRequest(FakeRequest(routes.DidYouGetMoneyFromLandlordController.submit(NormalMode)) .withFormUrlEncodedBody( - "didYouGetMoneyFromLandlord-radio-value" -> "No", + "didYouGetMoneyFromLandlord-radio-value" -> "false", ) .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))) result.map(result => { diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordFormSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordFormSpec.scala index c530b220..ed0f9db7 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordFormSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouGetMoneyFromLandlordFormSpec.scala @@ -24,14 +24,14 @@ import play.api.libs.json.Json class DidYouGetMoneyFromLandlordFormSpec extends AnyFlatSpec with Matchers { val validData = Map( - "didYouGetMoneyFromLandlord-radio-value" -> "Yes" + "didYouGetMoneyFromLandlord-radio-value" -> "true" ) "didYouGetMoneyFromLandlordForm" should "bind valid data successfully" in { val boundForm = DidYouGetMoneyFromLandlordForm.form.bind(validData) boundForm.errors shouldBe empty - boundForm.value shouldBe Some(DidYouGetMoneyFromLandlordForm("Yes")) + boundForm.value shouldBe Some(DidYouGetMoneyFromLandlordForm("true")) } it should "fail when didYouGetMoneyFromLandlord (radio) is missing" in { @@ -51,13 +51,13 @@ class DidYouGetMoneyFromLandlordFormSpec extends AnyFlatSpec with Matchers { it should "fail when no is selected" in { val data = Map( - "didYouGetMoneyFromLandlord-radio-value" -> "No", + "didYouGetMoneyFromLandlord-radio-value" -> "false", ) val boundForm = DidYouGetMoneyFromLandlordForm.form.bind(data) boundForm.errors shouldBe empty - boundForm.value shouldBe Some(DidYouGetMoneyFromLandlordForm("No")) + boundForm.value shouldBe Some(DidYouGetMoneyFromLandlordForm("false")) } "DoesYourRentIncludeParkingForm.format" should "serialize to JSON correctly" in { From e523918c7f5b3e29d149ecbb6356c2421632b1c9 Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Fri, 10 Oct 2025 14:01:26 +0100 Subject: [PATCH 5/6] NGR-1133 - Fixed failing test --- app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala index 0e1cd0a4..0b9cf7b7 100644 --- a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala +++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordForm.scala @@ -40,7 +40,7 @@ object LandlordForm extends CommonFormValidators with Mappings{ private lazy val landlordNameEmptyError = "landlord.name.empty.error" private lazy val landlordNameTooLongError = "landlord.name.empty.tooLong.error" private lazy val radioUnselectedError = "landlord.radio.empty.error" - private lazy val landlordRelationshipEmptyError = "landlord.relationship.empty.error" + private lazy val landlordRelationshipEmptyError = "landlord.relationship.emptyText.error" private lazy val landlordRelationshipTooLongError = "landlord.radio.tooLong.error" private val landlord = "landlord-name-value" From ebca6e50d0735a38dd096d15042dc05821694113 Mon Sep 17 00:00:00 2001 From: Pete Robinson <77154273+peterdrobinson@users.noreply.github.com> Date: Fri, 10 Oct 2025 14:12:47 +0100 Subject: [PATCH 6/6] NGR-1133 - Fixed further tests --- .../hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala index f469f472..63d9852f 100644 --- a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala +++ b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/LandlordFormSpec.scala @@ -46,7 +46,7 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { val boundForm = LandlordForm.form.bind(data) boundForm.errors shouldBe List(FormError("landlord-name-value", List("landlord.name.empty.error"), ArraySeq("landlord-name-value")), - FormError("landlord-relationship", List("landlord.relationship.empty.error"))) + FormError("landlord-relationship", List("landlord.relationship.emptyText.error"))) } it should "fail when landlord type (radio) is missing" in { @@ -65,7 +65,7 @@ class LandlordFormSpec extends AnyFlatSpec with Matchers { val boundForm = LandlordForm.form.bind(data) - boundForm.errors shouldBe List(FormError("landlord-relationship", List("landlord.relationship.empty.error"), List())) + boundForm.errors shouldBe List(FormError("landlord-relationship", List("landlord.relationship.emptyText.error"), List())) } it should "pass when 'Yes' is selected and description is provided" in {