From d1d8ce053e053b3bd017aeabfbc4dc11d58df9b9 Mon Sep 17 00:00:00 2001
From: JakeReid2020 <75027964+JakeReid2020@users.noreply.github.com>
Date: Wed, 20 Aug 2025 16:17:49 +0100
Subject: [PATCH 1/2] [NGR-1145] Adding Page and tests
---
...idYouAgreeRentWithLandlordController.scala | 84 ++++++++++++++
.../models/RaldUserAnswers.scala | 6 +-
.../models/components/NGRRadio.scala | 4 +
.../DidYouAgreeRentWithLandlordForm.scala | 50 ++++++++
.../hmrc/ngrraldfrontend/repo/RaldRepo.scala | 5 +
...DidYouAgreeRentWithLandlordView.scala.html | 45 ++++++++
conf/app.routes | 10 +-
conf/messages | 6 +
...uAgreeRentWithLandlordControllerSpec.scala | 107 ++++++++++++++++++
.../DidYouAgreeRentWithLandlordFormSpec.scala | 78 +++++++++++++
.../ngrraldfrontend/repo/RaldRepoSpec.scala | 18 ++-
.../DidYouAgreeRentWithLandlordViewSpec.scala | 99 ++++++++++++++++
.../TellUsAboutYourNewAgreementViewSpec.scala | 0
13 files changed, 505 insertions(+), 7 deletions(-)
create mode 100644 app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordController.scala
create mode 100644 app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouAgreeRentWithLandlordForm.scala
create mode 100644 app/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordView.scala.html
create mode 100644 test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordControllerSpec.scala
create mode 100644 test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouAgreeRentWithLandlordFormSpec.scala
create mode 100644 test/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordViewSpec.scala
delete mode 100644 test/uk/gov/hmrc/ngrraldfrontend/views/TellUsAboutYourNewAgreementViewSpec.scala
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordController.scala b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordController.scala
new file mode 100644
index 00000000..0d5d3656
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordController.scala
@@ -0,0 +1,84 @@
+/*
+ * 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.http.NotFoundException
+import uk.gov.hmrc.ngrraldfrontend.actions.{AuthRetrievals, PropertyLinkingAction}
+import uk.gov.hmrc.ngrraldfrontend.config.AppConfig
+import uk.gov.hmrc.ngrraldfrontend.models.components.*
+import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
+import uk.gov.hmrc.ngrraldfrontend.models.components.NavBarPageContents.createDefaultNavBar
+import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouAgreeRentWithLandlordForm
+import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouAgreeRentWithLandlordForm.form
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.repo.RaldRepo
+import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouAgreeRentWithLandlordView
+import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendController
+
+import javax.inject.{Inject, Singleton}
+import scala.concurrent.{ExecutionContext, Future}
+
+@Singleton
+class DidYouAgreeRentWithLandlordController @Inject()(didYouAgreeRentWithLandlordView: DidYouAgreeRentWithLandlordView,
+ authenticate: AuthRetrievals,
+ hasLinkedProperties: PropertyLinkingAction,
+ raldRepo: RaldRepo,
+ mcc: MessagesControllerComponents)(implicit appConfig: AppConfig, ec: ExecutionContext)
+ extends FrontendController(mcc) with I18nSupport {
+
+
+ def show: Action[AnyContent] = {
+ (authenticate andThen hasLinkedProperties).async { implicit request =>
+ request.propertyLinking.map(property =>
+ Future.successful(Ok(didYouAgreeRentWithLandlordView(
+ selectedPropertyAddress = property.addressFull,
+ navigationBarContent = createDefaultNavBar,
+ form = form,
+ ngrRadio = buildRadios(form, DidYouAgreeRentWithLandlordForm.ngrRadio(form)),
+ )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ }
+ }
+
+ def submit: Action[AnyContent] =
+ (authenticate andThen hasLinkedProperties).async { implicit request =>
+ form.bindFromRequest().fold(
+ formWithErrors => {
+ request.propertyLinking.map(property =>
+ Future.successful(BadRequest(didYouAgreeRentWithLandlordView(
+ form = formWithErrors,
+ navigationBarContent = createDefaultNavBar,
+ ngrRadio = buildRadios(formWithErrors, DidYouAgreeRentWithLandlordForm.ngrRadio(formWithErrors)),
+ selectedPropertyAddress = property.addressFull
+ )))).getOrElse(throw new NotFoundException("Couldn't find property in mongo"))
+ },
+ radioValue =>
+ raldRepo.insertDidYouAgreeRentWithLandlord(
+ credId = CredId(request.credId.getOrElse("")),
+ radioValue = radioValue.toString
+ )
+ if(radioValue.radioValue.toString == "YesTheLandlord"){
+ Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
+ }else{
+ //TODO
+ Future.successful(Redirect(routes.CheckRentFreePeriodController.show.url))
+ }
+
+ )
+ }
+}
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala
index 2a4639aa..35e0d2eb 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala
@@ -32,8 +32,10 @@ final case class RaldUserAnswers(
agreedRentChange: Option[String] = None,
agreementVerbal: Option[AgreementVerbal] = None,
hasRentFreePeriod: Option[Boolean] = None,
- agreement: Option[Agreement] = None,
- provideDetailsOfFirstSecondRentPeriod: Option[ProvideDetailsOfFirstSecondRentPeriod] = None
+ agreement: Option[Agreement] = None,
+ provideDetailsOfFirstSecondRentPeriod: Option[ProvideDetailsOfFirstSecondRentPeriod] = None,
+ agreement: Option[Agreement] = None,
+ didYouAgreeRentWithLandlord: Option[Boolean] = None
)
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala
index c98580a7..861a4213 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/components/NGRRadio.scala
@@ -63,6 +63,10 @@ sealed trait firstRentPeriod extends RadioEntry
case object yesPayedRent extends RadioEntry
case object noRentPayed extends RadioEntry
+sealed trait DidYouAgreeRentWithLandlord extends RadioEntry
+case object YesTheLandlord extends DidYouAgreeRentWithLandlord
+case object NoACourtSet extends DidYouAgreeRentWithLandlord
+
case class NGRRadioName(key: String)
case class NGRRadioButtons(radioContent: String,
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouAgreeRentWithLandlordForm.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouAgreeRentWithLandlordForm.scala
new file mode 100644
index 00000000..a744402f
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouAgreeRentWithLandlordForm.scala
@@ -0,0 +1,50 @@
+/*
+ * 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
+import play.api.i18n.Messages
+import play.api.libs.json.{Json, OFormat}
+import uk.gov.hmrc.ngrraldfrontend.models.components.*
+import uk.gov.hmrc.ngrraldfrontend.models.forms.mappings.Mappings
+
+final case class DidYouAgreeRentWithLandlordForm (radioValue: String)
+
+object DidYouAgreeRentWithLandlordForm extends Mappings {
+ implicit val format: OFormat[DidYouAgreeRentWithLandlordForm] = Json.format[DidYouAgreeRentWithLandlordForm]
+
+ private lazy val radioUnselectedError = "didYouAgreeRentWithLandlord.error.required"
+ private val didYouAgreeRentWithLandlordRadio = "did-you-agree-rent-with-landlord-radio"
+
+ def unapply(didYouAgreeRentWithLandlordForm: DidYouAgreeRentWithLandlordForm): Option[String] = Some(didYouAgreeRentWithLandlordForm.radioValue)
+
+ def form: Form[DidYouAgreeRentWithLandlordForm] = {
+ Form(
+ mapping(
+ didYouAgreeRentWithLandlordRadio -> text(radioUnselectedError)
+ )(DidYouAgreeRentWithLandlordForm.apply)(DidYouAgreeRentWithLandlordForm.unapply)
+ )
+ }
+
+ private val yes: NGRRadioButtons = NGRRadioButtons(radioContent = "didYouAgreeRentWithLandlord.yes", radioValue = YesTheLandlord)
+ private val no: NGRRadioButtons = NGRRadioButtons(radioContent = "didYouAgreeRentWithLandlord.no", radioValue = NoACourtSet)
+
+ def ngrRadio(form: Form[DidYouAgreeRentWithLandlordForm])(implicit messages: Messages): NGRRadio =
+ NGRRadio(NGRRadioName("did-you-agree-rent-with-landlord-radio"),NGRRadioButtons = Seq(yes,no))
+}
+
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala b/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala
index 25c69a54..45a1a2f6 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepo.scala
@@ -184,6 +184,11 @@ case class RaldRepo @Inject()(mongo: MongoComponent,
findAndUpdateByCredId(credId, updates: _*)
}
+ def insertDidYouAgreeRentWithLandlord(credId: CredId, radioValue: String): Future[Option[RaldUserAnswers]] = {
+ findAndUpdateByCredId(credId, Updates.set("didYouAgreeRentWithLandlord", if(radioValue == "YesTheLandlord") true else false))
+ }
+
+
def findByCredId(credId: CredId): Future[Option[RaldUserAnswers]] = {
collection.find(
equal("credId.value", credId.value)
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordView.scala.html b/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordView.scala.html
new file mode 100644
index 00000000..94dc1c9b
--- /dev/null
+++ b/app/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordView.scala.html
@@ -0,0 +1,45 @@
+@*
+ * 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.ngrraldfrontend.models.components.NavigationBarContent
+@import uk.gov.hmrc.ngrraldfrontend.viewmodels.govuk.all._
+@import uk.gov.hmrc.govukfrontend.views.html.components._
+@import uk.gov.hmrc.ngrraldfrontend.views.html.components._
+@import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouAgreeRentWithLandlordForm
+
+@this(
+ layout: Layout,
+ govukRadios : GovukRadios,
+ govukErrorSummary: GovukErrorSummary,
+ saveAndContinueButton: saveAndContinueButton,
+ formHelper: FormWithCSRF
+)
+
+@(navigationBarContent: NavigationBarContent, selectedPropertyAddress: String, form: Form[DidYouAgreeRentWithLandlordForm], ngrRadio: Radios)(implicit request: RequestHeader, messages: Messages, appConfig: AppConfig)
+
+@layout(pageTitle = Some(messages("didYouAgreeRentWithLandlord.title")), showBackLink = true, fullWidth = false, navigationBarContent = Some(navigationBarContent)) {
+
+ @formHelper(action = uk.gov.hmrc.ngrraldfrontend.controllers.routes.DidYouAgreeRentWithLandlordController.submit, Symbol("autoComplete") -> "off") {
+ @if(form.errors.nonEmpty) {
+ @govukErrorSummary(ErrorSummaryViewModel(form))
+ }
+ @selectedPropertyAddress
+
@messages("didYouAgreeRentWithLandlord.title")
+ @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 b919020e..818022fc 100644
--- a/conf/app.routes
+++ b/conf/app.routes
@@ -22,9 +22,11 @@ GET /have-you-agreed-rent-changes-with-landlord uk.gov.hmrc.ngrraldfront
POST /have-you-agreed-rent-changes-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.AgreedRentChangeController.submit
GET /agreement-verbal uk.gov.hmrc.ngrraldfrontend.controllers.AgreementVerbalController.show
POST /agreement-verbal uk.gov.hmrc.ngrraldfrontend.controllers.AgreementVerbalController.submit
-GET /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.show
-POST /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.submit
-GET /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.show
-POST /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.submit
+GET /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.show
+POST /do-you-have-a-rent-free-period uk.gov.hmrc.ngrraldfrontend.controllers.CheckRentFreePeriodController.submit
+GET /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.show
+POST /agreement uk.gov.hmrc.ngrraldfrontend.controllers.AgreementController.submit
+GET /did-you-agree-rent-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouAgreeRentWithLandlordController.show
+POST /did-you-agree-rent-with-landlord uk.gov.hmrc.ngrraldfrontend.controllers.DidYouAgreeRentWithLandlordController.submit
GET /provide-details-of-first-second-rent-period uk.gov.hmrc.ngrraldfrontend.controllers.ProvideDetailsOfFirstSecondRentPeriodController.show
POST /provide-details-of-first-second-rent-period uk.gov.hmrc.ngrraldfrontend.controllers.ProvideDetailsOfFirstSecondRentPeriodController.submit
\ No newline at end of file
diff --git a/conf/messages b/conf/messages
index db06ba6a..0b5de10c 100644
--- a/conf/messages
+++ b/conf/messages
@@ -174,6 +174,12 @@ agreement.radio.breakClause.required.error = Select yes if your agreement has a
agreement.radio.conditional.breakClause.required.error = Tell us about your break clause or clauses
agreement.radio.conditional.breakClause.tooLong.error = Maximum character allowed is 250
+#DidYouAgreeRentWithLandlord
+didYouAgreeRentWithLandlord.title = Did you agree the rent with your landlord or their agent?
+didYouAgreeRentWithLandlord.yes = Yes
+didYouAgreeRentWithLandlord.no = No, a court set the rent
+didYouAgreeRentWithLandlord.error.required = Select yes if you agreed the rent with your landlord or their agent
+
#ProvideDetailsOfFirstSecondRentPeriod
provideDetailsOfFirstSecondRentPeriod.title = Provide details of each rent period
provideDetailsOfFirstSecondRentPeriod.firstPeriod.subheading = First rent period
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordControllerSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordControllerSpec.scala
new file mode 100644
index 00000000..0a99ee2a
--- /dev/null
+++ b/test/uk/gov/hmrc/ngrraldfrontend/controllers/DidYouAgreeRentWithLandlordControllerSpec.scala
@@ -0,0 +1,107 @@
+/*
+ * 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.mockito.ArgumentMatchers.any
+import org.mockito.Mockito.when
+import org.scalatest.matchers.should.Matchers.shouldBe
+import play.api.test.FakeRequest
+import play.api.test.Helpers.{await, contentAsString, redirectLocation, status}
+import play.api.test.Helpers.{await, contentAsString, defaultAwaitTimeout, redirectLocation, status}
+import play.api.http.Status.{BAD_REQUEST, OK, SEE_OTHER}
+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.{AuthenticatedUserRequest, RaldUserAnswers}
+import uk.gov.hmrc.ngrraldfrontend.models.registration.CredId
+import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouAgreeRentWithLandlordView
+
+import scala.concurrent.Future
+
+class DidYouAgreeRentWithLandlordControllerSpec extends ControllerSpecSupport {
+ val pageTitle = "Did you agree the rent with your landlord or their agent?"
+ val view: DidYouAgreeRentWithLandlordView = inject[DidYouAgreeRentWithLandlordView]
+ val controller: DidYouAgreeRentWithLandlordController = new DidYouAgreeRentWithLandlordController(view, mockAuthJourney, mockPropertyLinkingAction, mockRaldRepo, mcc)(mockConfig, ec)
+
+ "Did you agree rent with landlord controller" must {
+ "method show" must {
+ "Return OK and the correct view" in {
+ when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
+ val result = controller.show()(authenticatedFakeRequest())
+ status(result) mustBe OK
+ val content = contentAsString(result)
+ content must include(pageTitle)
+ }
+ "Return NotFoundException when property is not found in the mongo" in {
+ mockRequestWithoutProperty()
+ val exception = intercept[NotFoundException] {
+ await(controller.show(authenticatedFakeRequest()))
+ }
+ exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ }
+ }
+
+ "method submit" must {
+ "Return OK and the correct view after submitting with written radio button" in {
+ when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
+ mockRequest(hasCredId = true)
+ val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.DidYouAgreeRentWithLandlordController.submit)
+ .withFormUrlEncodedBody(("did-you-agree-rent-with-landlord-radio", "YesTheLandlord"))
+ .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") shouldBe Some("/ngr-rald-frontend/do-you-have-a-rent-free-period")
+ })
+ status(result) mustBe SEE_OTHER
+ redirectLocation(result) shouldBe Some(routes.CheckRentFreePeriodController.show.url)
+ }
+ "Return OK and the correct view after submitting with verbal radio button" in {
+ when(mockRaldRepo.findByCredId(any())) thenReturn (Future.successful(Some(RaldUserAnswers(credId = CredId(null), NewAgreement, selectedProperty = property))))
+ mockRequest(hasCredId = true)
+ val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit)
+ .withFormUrlEncodedBody(("did-you-agree-rent-with-landlord-radio", "NoACourtSet"))
+ .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") shouldBe Some("/ngr-rald-frontend/do-you-have-a-rent-free-period")
+ })
+ status(result) mustBe SEE_OTHER
+ redirectLocation(result) shouldBe Some(routes.CheckRentFreePeriodController.show.url)
+ }
+ "Return Form with Errors when no radio button is selected" in {
+ mockRequest(hasCredId = true)
+ val result = controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit)
+ .withFormUrlEncodedBody(("did-you-agree-rent-with-landlord-radio", ""))
+ .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") shouldBe Some("/ngr-rald-frontend/what-type-of-agreement-do-you-have ")
+ })
+ status(result) mustBe BAD_REQUEST
+ val content = contentAsString(result)
+ content must include(pageTitle)
+ }
+ "Return Exception if no address is in the mongo" in {
+ mockRequestWithoutProperty()
+ val exception = intercept[NotFoundException] {
+ await(controller.submit()(AuthenticatedUserRequest(FakeRequest(routes.WhatTypeOfAgreementController.submit)
+ .withFormUrlEncodedBody(("did-you-agree-rent-with-landlord-radio", ""))
+ .withHeaders(HeaderNames.authorisation -> "Bearer 1"), None, None, None, Some(property), credId = Some(credId.value), None, None, nino = Nino(true, Some("")))))
+ }
+ exception.getMessage contains "Couldn't find property in mongo" mustBe true
+ }
+ }
+ }
+}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouAgreeRentWithLandlordFormSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouAgreeRentWithLandlordFormSpec.scala
new file mode 100644
index 00000000..f36faa30
--- /dev/null
+++ b/test/uk/gov/hmrc/ngrraldfrontend/models/forms/DidYouAgreeRentWithLandlordFormSpec.scala
@@ -0,0 +1,78 @@
+/*
+ * 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.matchers.must.Matchers
+import org.scalatest.matchers.should.Matchers.{should, shouldBe}
+import org.scalatest.wordspec.AnyWordSpec
+import play.api.data.FormError
+import play.api.libs.json.Json
+
+class DidYouAgreeRentWithLandlordFormSpec extends AnyWordSpec with Matchers {
+
+ "DidYouAgreeRentWithLandlordForm" should {
+
+ "bind successfully with a valid DidYouAgreeRentWithLandlordRadio value" in {
+ val data = Map("did-you-agree-rent-with-landlord-radio" -> "YesTheLandlord")
+ val boundForm = DidYouAgreeRentWithLandlordForm.form.bind(data)
+
+ boundForm.hasErrors shouldBe false
+ boundForm.value shouldBe Some(DidYouAgreeRentWithLandlordForm("YesTheLandlord"))
+ }
+
+ "fail to bind when DidYouAgreeRentWithLandlordRadio is missing" in {
+ val data = Map.empty[String, String]
+ val boundForm = DidYouAgreeRentWithLandlordForm.form.bind(data)
+
+ boundForm.hasErrors shouldBe true
+ boundForm.errors should contain(FormError("did-you-agree-rent-with-landlord-radio", List("didYouAgreeRentWithLandlord.error.required")))
+ }
+
+ "fail to bind when DidYouAgreeRentWithLandlordRadio is empty" in {
+ val data = Map("did-you-agree-rent-with-landlord-radio" -> "")
+ val boundForm = DidYouAgreeRentWithLandlordForm.form.bind(data)
+
+ boundForm.hasErrors shouldBe true
+ boundForm.errors should contain(FormError("did-you-agree-rent-with-landlord-radio", List("didYouAgreeRentWithLandlord.error.required")))
+ }
+
+
+ "serialize to JSON correctly" in {
+ val form = DidYouAgreeRentWithLandlordForm("YesTheLandlord")
+ val json = Json.toJson(form)
+
+ json shouldBe Json.obj(
+ "radioValue" -> "YesTheLandlord"
+ )
+ }
+
+ "deserialize from JSON correctly" in {
+ val json = Json.obj("radioValue" -> "NoACourtSet")
+ val result = json.validate[DidYouAgreeRentWithLandlordForm]
+
+ result.isSuccess shouldBe true
+ result.get shouldBe DidYouAgreeRentWithLandlordForm("NoACourtSet")
+ }
+
+ "fail deserialization if DidYouAgreeRentWithLandlordRadio is missing" in {
+ val json = Json.obj()
+ val result = json.validate[DidYouAgreeRentWithLandlordForm]
+
+ result.isError shouldBe true
+ }
+ }
+}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala
index 426cb7bd..11a4aca6 100644
--- a/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala
+++ b/test/uk/gov/hmrc/ngrraldfrontend/repo/RaldRepoSpec.scala
@@ -280,7 +280,7 @@ class RaldRepoSpec extends TestSupport with TestData
result mustBe actual
}
-
+
"insert rent based on with other desc successfully" in {
await(
repository.insertRentBased(
@@ -345,6 +345,22 @@ class RaldRepoSpec extends TestSupport with TestData
actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, hasRentFreePeriod = Some(true)))
}
+ "insert Did You Agree Rent With Landlord successfully with true" in {
+ val yes = "YesTheLandlord"
+
+ await(repository.insertDidYouAgreeRentWithLandlord(credId, yes))
+ val actual = await(repository.findByCredId(credId))
+ actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, didYouAgreeRentWithLandlord = Some(true)))
+ }
+
+ "insert Did You Agree Rent With Landlord successfully with false" in {
+ val no = "NoACourtSet"
+
+ await(repository.insertDidYouAgreeRentWithLandlord(credId, no))
+ val actual = await(repository.findByCredId(credId))
+ actual shouldBe Some(RaldUserAnswers(credId, NewAgreement, property, didYouAgreeRentWithLandlord = Some(false)))
+ }
+
"insert hasRentFreePeriod successfully with No" in {
val hasRentFreePeriod = "No"
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordViewSpec.scala
new file mode 100644
index 00000000..fd0147c5
--- /dev/null
+++ b/test/uk/gov/hmrc/ngrraldfrontend/views/DidYouAgreeRentWithLandlordViewSpec.scala
@@ -0,0 +1,99 @@
+/*
+ * 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.viewmodels.radios.Radios
+import uk.gov.hmrc.ngrraldfrontend.helpers.ViewBaseSpec
+import uk.gov.hmrc.ngrraldfrontend.models.components.*
+import uk.gov.hmrc.ngrraldfrontend.models.components.NGRRadio.buildRadios
+import uk.gov.hmrc.ngrraldfrontend.models.forms.DidYouAgreeRentWithLandlordForm
+import uk.gov.hmrc.ngrraldfrontend.views.html.DidYouAgreeRentWithLandlordView
+
+class DidYouAgreeRentWithLandlordViewSpec extends ViewBaseSpec {
+ lazy val view: DidYouAgreeRentWithLandlordView = inject[DidYouAgreeRentWithLandlordView]
+
+ object Strings {
+ val heading = "Did you agree the rent with your landlord or their agent?"
+ val radio1 = "Yes"
+ val radio2 = "No, a court set the rent"
+ val continue = "Continue"
+ }
+
+ object Selectors {
+ val heading = "#main-content > div > div > form > h1"
+ val radio1 = "#main-content > div > div > form > div > div > div:nth-child(1) > label"
+ val radio2 = "#main-content > div > div > form > div > div > div:nth-child(2) > label"
+ val radio3 = "#main-content > div > div > form > div > div > div:nth-child(3) > label"
+ val continue = "#continue"
+ }
+
+ val content: NavigationBarContent = NavBarPageContents.CreateNavBar(
+ contents = NavBarContents(
+ homePage = Some(true),
+ messagesPage = Some(false),
+ profileAndSettingsPage = Some(false),
+ signOutPage = Some(true)
+ ),
+ currentPage = NavBarCurrentPage(homePage = true),
+ notifications = Some(1)
+ )
+
+ val address = "5 Brixham Marina, Berry Head Road, Brixham, Devon, TQ5 9BW"
+ private val yesButton: NGRRadioButtons = NGRRadioButtons("Yes", YesTheLandlord)
+ private val noButton: NGRRadioButtons = NGRRadioButtons("No, a court set the rent", NoACourtSet)
+ private val ngrRadio: NGRRadio = NGRRadio(NGRRadioName("what-type-of-agreement-radio"), Seq(yesButton, noButton))
+ val form = DidYouAgreeRentWithLandlordForm.form.fillAndValidate(DidYouAgreeRentWithLandlordForm("YesTheLandlord"))
+ val radio: Radios = buildRadios(form, ngrRadio)
+
+ "DidYouAgreeRentWithLandlordView" must {
+ val whatTypeOfAgreementView = view(content, address, form, radio)
+ lazy implicit val document: Document = Jsoup.parse(whatTypeOfAgreementView.body)
+ val htmlApply = view.apply(content, address, form, radio).body
+ val htmlRender = view.render(content, address, form, radio, request, messages, mockConfig).body
+ lazy val htmlF = view.f(content, address, form, radio)
+
+ "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
+ }
+ }
+}
diff --git a/test/uk/gov/hmrc/ngrraldfrontend/views/TellUsAboutYourNewAgreementViewSpec.scala b/test/uk/gov/hmrc/ngrraldfrontend/views/TellUsAboutYourNewAgreementViewSpec.scala
deleted file mode 100644
index e69de29b..00000000
From 78aafb5088c75a7f00b694df26cf03b3ca92ffb2 Mon Sep 17 00:00:00 2001
From: JakeReid2020 <75027964+JakeReid2020@users.noreply.github.com>
Date: Thu, 21 Aug 2025 09:11:05 +0100
Subject: [PATCH 2/2] [NGR-1145] Rebase
---
app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala | 1 -
1 file changed, 1 deletion(-)
diff --git a/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala b/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala
index 35e0d2eb..85ddf32c 100644
--- a/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala
+++ b/app/uk/gov/hmrc/ngrraldfrontend/models/RaldUserAnswers.scala
@@ -34,7 +34,6 @@ final case class RaldUserAnswers(
hasRentFreePeriod: Option[Boolean] = None,
agreement: Option[Agreement] = None,
provideDetailsOfFirstSecondRentPeriod: Option[ProvideDetailsOfFirstSecondRentPeriod] = None,
- agreement: Option[Agreement] = None,
didYouAgreeRentWithLandlord: Option[Boolean] = None
)