From 9e111508a973c9bbeb823664b2386bc1ad27528b Mon Sep 17 00:00:00 2001 From: Carl Thompson Date: Mon, 3 Jun 2024 08:47:41 +0100 Subject: [PATCH] removed duplicate scaffolded 'have phone' for first contact --- .../FirstContactCanWePhoneController.scala | 73 -------- .../FirstContactCanWePhoneFormProvider.scala | 31 ---- .../FirstContactCanWePhonePage.scala | 27 --- .../FirstContactCanWePhoneSummary.scala | 43 ----- .../FirstContactCanWePhoneView.scala.html | 46 ----- conf/app.routes | 5 - conf/messages.en | 6 - ...FirstContactCanWePhoneControllerSpec.scala | 158 ------------------ ...rstContactCanWePhoneFormProviderSpec.scala | 46 ----- test/navigation/NavigatorSpec.scala | 2 +- 10 files changed, 1 insertion(+), 436 deletions(-) delete mode 100644 app/controllers/addFinancialInstitution/FirstContactCanWePhoneController.scala delete mode 100644 app/forms/addFinancialInstitution/FirstContactCanWePhoneFormProvider.scala delete mode 100644 app/pages/addFinancialInstitution/FirstContactCanWePhonePage.scala delete mode 100644 app/viewmodels/checkAnswers/FirstContactCanWePhoneSummary.scala delete mode 100644 app/views/addFinancialInstitution/FirstContactCanWePhoneView.scala.html delete mode 100644 test/controllers/addFinancialInstitution/FirstContactCanWePhoneControllerSpec.scala delete mode 100644 test/forms/addFinancialInstitution/FirstContactCanWePhoneFormProviderSpec.scala diff --git a/app/controllers/addFinancialInstitution/FirstContactCanWePhoneController.scala b/app/controllers/addFinancialInstitution/FirstContactCanWePhoneController.scala deleted file mode 100644 index a7622cd6..00000000 --- a/app/controllers/addFinancialInstitution/FirstContactCanWePhoneController.scala +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2024 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 controllers.addFinancialInstitution - -import controllers.actions._ -import forms.addFinancialInstitution.FirstContactCanWePhoneFormProvider -import models.Mode -import navigation.Navigator -import pages.addFinancialInstitution.FirstContactCanWePhonePage -import play.api.i18n.{I18nSupport, MessagesApi} -import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} -import repositories.SessionRepository -import uk.gov.hmrc.play.bootstrap.frontend.controller.FrontendBaseController -import views.html.addFinancialInstitution.FirstContactCanWePhoneView - -import javax.inject.Inject -import scala.concurrent.{ExecutionContext, Future} - -class FirstContactCanWePhoneController @Inject() ( - override val messagesApi: MessagesApi, - sessionRepository: SessionRepository, - navigator: Navigator, - identify: IdentifierAction, - getData: DataRetrievalAction, - requireData: DataRequiredAction, - formProvider: FirstContactCanWePhoneFormProvider, - val controllerComponents: MessagesControllerComponents, - view: FirstContactCanWePhoneView -)(implicit ec: ExecutionContext) - extends FrontendBaseController - with I18nSupport { - - val form = formProvider() - - def onPageLoad(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData) { - implicit request => - val preparedForm = request.userAnswers.get(FirstContactCanWePhonePage) match { - case None => form - case Some(value) => form.fill(value) - } - - Ok(view(preparedForm, mode)) - } - - def onSubmit(mode: Mode): Action[AnyContent] = (identify andThen getData andThen requireData).async { - implicit request => - form - .bindFromRequest() - .fold( - formWithErrors => Future.successful(BadRequest(view(formWithErrors, mode))), - value => - for { - updatedAnswers <- Future.fromTry(request.userAnswers.set(FirstContactCanWePhonePage, value)) - _ <- sessionRepository.set(updatedAnswers) - } yield Redirect(navigator.nextPage(FirstContactCanWePhonePage, mode, updatedAnswers)) - ) - } - -} diff --git a/app/forms/addFinancialInstitution/FirstContactCanWePhoneFormProvider.scala b/app/forms/addFinancialInstitution/FirstContactCanWePhoneFormProvider.scala deleted file mode 100644 index 340d97fb..00000000 --- a/app/forms/addFinancialInstitution/FirstContactCanWePhoneFormProvider.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2024 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 forms.addFinancialInstitution - -import javax.inject.Inject - -import forms.mappings.Mappings -import play.api.data.Form - -class FirstContactCanWePhoneFormProvider @Inject() extends Mappings { - - def apply(): Form[Boolean] = - Form( - "value" -> boolean("firstContactCanWePhone.error.required") - ) - -} diff --git a/app/pages/addFinancialInstitution/FirstContactCanWePhonePage.scala b/app/pages/addFinancialInstitution/FirstContactCanWePhonePage.scala deleted file mode 100644 index 6304359b..00000000 --- a/app/pages/addFinancialInstitution/FirstContactCanWePhonePage.scala +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2024 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 pages.addFinancialInstitution - -import pages.QuestionPage -import play.api.libs.json.JsPath - -case object FirstContactCanWePhonePage extends QuestionPage[Boolean] { - - override def path: JsPath = JsPath \ toString - - override def toString: String = "firstContactCanWePhone" -} diff --git a/app/viewmodels/checkAnswers/FirstContactCanWePhoneSummary.scala b/app/viewmodels/checkAnswers/FirstContactCanWePhoneSummary.scala deleted file mode 100644 index c98fef57..00000000 --- a/app/viewmodels/checkAnswers/FirstContactCanWePhoneSummary.scala +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2024 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 viewmodels.checkAnswers - -import models.{CheckMode, UserAnswers} -import pages.addFinancialInstitution.FirstContactCanWePhonePage -import play.api.i18n.Messages -import uk.gov.hmrc.govukfrontend.views.viewmodels.summarylist.SummaryListRow -import viewmodels.govuk.summarylist._ -import viewmodels.implicits._ - -object FirstContactCanWePhoneSummary { - - def row(answers: UserAnswers)(implicit messages: Messages): Option[SummaryListRow] = - answers.get(FirstContactCanWePhonePage).map { - answer => - val value = if (answer) "site.yes" else "site.no" - - SummaryListRowViewModel( - key = "firstContactCanWePhone.checkYourAnswersLabel", - value = ValueViewModel(value), - actions = Seq( - ActionItemViewModel("site.change", controllers.addFinancialInstitution.routes.FirstContactCanWePhoneController.onPageLoad(CheckMode).url) - .withVisuallyHiddenText(messages("firstContactCanWePhone.change.hidden")) - ) - ) - } - -} diff --git a/app/views/addFinancialInstitution/FirstContactCanWePhoneView.scala.html b/app/views/addFinancialInstitution/FirstContactCanWePhoneView.scala.html deleted file mode 100644 index bc477ab4..00000000 --- a/app/views/addFinancialInstitution/FirstContactCanWePhoneView.scala.html +++ /dev/null @@ -1,46 +0,0 @@ -@* - * Copyright 2024 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. - *@ - -@this( - layout: templates.Layout, - formHelper: FormWithCSRF, - govukErrorSummary: GovukErrorSummary, - govukRadios: GovukRadios, - govukButton: GovukButton -) - -@(form: Form[_], mode: Mode)(implicit request: Request[_], messages: Messages) - -@layout(pageTitle = title(form, messages("firstContactCanWePhone.title"))) { - - @formHelper(action = controllers.addFinancialInstitution.routes.FirstContactCanWePhoneController.onSubmit(mode), Symbol("autoComplete") -> "off") { - - @if(form.errors.nonEmpty) { - @govukErrorSummary(ErrorSummaryViewModel(form)) - } - - @govukRadios( - RadiosViewModel.yesNo( - field = form("value"), - legend = LegendViewModel(messages("firstContactCanWePhone.heading")).asPageHeading() - ) - ) - - @govukButton( - ButtonViewModel(messages("site.continue")).withAttribute("id" -> "submit") - ) - } -} diff --git a/conf/app.routes b/conf/app.routes index 3c44b3c7..318c1675 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -31,11 +31,6 @@ POST /email controllers.addFinancia GET /change-email controllers.addFinancialInstitution.FirstContactEmailController.onPageLoad(mode: Mode = CheckMode) POST /change-email controllers.addFinancialInstitution.FirstContactEmailController.onSubmit(mode: Mode = CheckMode) -GET /firstContactCanWePhone controllers.addFinancialInstitution.FirstContactCanWePhoneController.onPageLoad(mode: Mode = NormalMode) -POST /firstContactCanWePhone controllers.addFinancialInstitution.FirstContactCanWePhoneController.onSubmit(mode: Mode = NormalMode) -GET /changeFirstContactCanWePhone controllers.addFinancialInstitution.FirstContactCanWePhoneController.onPageLoad(mode: Mode = CheckMode) -POST /changeFirstContactCanWePhone controllers.addFinancialInstitution.FirstContactCanWePhoneController.onSubmit(mode: Mode = CheckMode) - GET /phone controllers.addFinancialInstitution.FirstContactPhoneNumberController.onPageLoad(mode: Mode = NormalMode) POST /phone controllers.addFinancialInstitution.FirstContactPhoneNumberController.onSubmit(mode: Mode = NormalMode) GET /change-phone controllers.addFinancialInstitution.FirstContactPhoneNumberController.onPageLoad(mode: Mode = CheckMode) diff --git a/conf/messages.en b/conf/messages.en index 64f9d511..2f564750 100644 --- a/conf/messages.en +++ b/conf/messages.en @@ -77,12 +77,6 @@ signedOut.link = Sign in again to use the service unauthorised.title = You can’t access this service with this account unauthorised.heading = You can’t access this service with this account -firstContactCanWePhone.title = firstContactCanWePhone -firstContactCanWePhone.heading = firstContactCanWePhone -firstContactCanWePhone.checkYourAnswersLabel = firstContactCanWePhone -firstContactCanWePhone.error.required = Select yes if firstContactCanWePhone -firstContactCanWePhone.change.hidden = FirstContactCanWePhone - firstContactEmail.title = What is the email address for the first contact? firstContactEmail.heading = What is the email address for {0}? firstContactEmail.p1 = We will use this email address to send confirmation of reports for {0} or if we have any questions about them. diff --git a/test/controllers/addFinancialInstitution/FirstContactCanWePhoneControllerSpec.scala b/test/controllers/addFinancialInstitution/FirstContactCanWePhoneControllerSpec.scala deleted file mode 100644 index 558068e5..00000000 --- a/test/controllers/addFinancialInstitution/FirstContactCanWePhoneControllerSpec.scala +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Copyright 2024 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 controllers.addFinancialInstitution - -import base.SpecBase -import forms.addFinancialInstitution.FirstContactCanWePhoneFormProvider -import models.{NormalMode, UserAnswers} -import navigation.{FakeNavigator, Navigator} -import org.mockito.ArgumentMatchers.any -import org.mockito.Mockito.when -import org.scalatestplus.mockito.MockitoSugar -import pages.addFinancialInstitution.FirstContactCanWePhonePage -import play.api.inject.bind -import play.api.mvc.Call -import play.api.test.FakeRequest -import play.api.test.Helpers._ -import repositories.SessionRepository -import views.html.addFinancialInstitution.FirstContactCanWePhoneView - -import scala.concurrent.Future - -class FirstContactCanWePhoneControllerSpec extends SpecBase with MockitoSugar { - - def onwardRoute = Call("GET", "/foo") - - val formProvider = new FirstContactCanWePhoneFormProvider() - val form = formProvider() - - lazy val firstContactCanWePhoneRoute = routes.FirstContactCanWePhoneController.onPageLoad(NormalMode).url - - "FirstContactCanWePhone Controller" - { - - "must return OK and the correct view for a GET" in { - - val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() - - running(application) { - val request = FakeRequest(GET, firstContactCanWePhoneRoute) - - val result = route(application, request).value - - val view = application.injector.instanceOf[FirstContactCanWePhoneView] - - status(result) mustEqual OK - contentAsString(result) mustEqual view(form, NormalMode)(request, messages(application)).toString - } - } - - "must populate the view correctly on a GET when the question has previously been answered" in { - - val userAnswers = UserAnswers(userAnswersId).set(FirstContactCanWePhonePage, true).success.value - - val application = applicationBuilder(userAnswers = Some(userAnswers)).build() - - running(application) { - val request = FakeRequest(GET, firstContactCanWePhoneRoute) - - val view = application.injector.instanceOf[FirstContactCanWePhoneView] - - val result = route(application, request).value - - status(result) mustEqual OK - contentAsString(result) mustEqual view(form.fill(true), NormalMode)(request, messages(application)).toString - } - } - - "must redirect to the next page when valid data is submitted" in { - - val mockSessionRepository = mock[SessionRepository] - - when(mockSessionRepository.set(any())) thenReturn Future.successful(true) - - val application = - applicationBuilder(userAnswers = Some(emptyUserAnswers)) - .overrides( - bind[Navigator].toInstance(new FakeNavigator(onwardRoute)), - bind[SessionRepository].toInstance(mockSessionRepository) - ) - .build() - - running(application) { - val request = - FakeRequest(POST, firstContactCanWePhoneRoute) - .withFormUrlEncodedBody(("value", "true")) - - val result = route(application, request).value - - status(result) mustEqual SEE_OTHER - redirectLocation(result).value mustEqual onwardRoute.url - } - } - - "must return a Bad Request and errors when invalid data is submitted" in { - - val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() - - running(application) { - val request = - FakeRequest(POST, firstContactCanWePhoneRoute) - .withFormUrlEncodedBody(("value", "")) - - val boundForm = form.bind(Map("value" -> "")) - - val view = application.injector.instanceOf[FirstContactCanWePhoneView] - - val result = route(application, request).value - - status(result) mustEqual BAD_REQUEST - contentAsString(result) mustEqual view(boundForm, NormalMode)(request, messages(application)).toString - } - } - - "must redirect to Journey Recovery for a GET if no existing data is found" in { - - val application = applicationBuilder(userAnswers = None).build() - - running(application) { - val request = FakeRequest(GET, firstContactCanWePhoneRoute) - - val result = route(application, request).value - - status(result) mustEqual SEE_OTHER - redirectLocation(result).value mustEqual controllers.routes.JourneyRecoveryController.onPageLoad().url - } - } - - "must redirect to Journey Recovery for a POST if no existing data is found" in { - - val application = applicationBuilder(userAnswers = None).build() - - running(application) { - val request = - FakeRequest(POST, firstContactCanWePhoneRoute) - .withFormUrlEncodedBody(("value", "true")) - - val result = route(application, request).value - - status(result) mustEqual SEE_OTHER - redirectLocation(result).value mustEqual controllers.routes.JourneyRecoveryController.onPageLoad().url - } - } - } - -} diff --git a/test/forms/addFinancialInstitution/FirstContactCanWePhoneFormProviderSpec.scala b/test/forms/addFinancialInstitution/FirstContactCanWePhoneFormProviderSpec.scala deleted file mode 100644 index 51bc9807..00000000 --- a/test/forms/addFinancialInstitution/FirstContactCanWePhoneFormProviderSpec.scala +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2024 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 forms.addFinancialInstitution - -import forms.behaviours.BooleanFieldBehaviours -import play.api.data.FormError - -class FirstContactCanWePhoneFormProviderSpec extends BooleanFieldBehaviours { - - val requiredKey = "firstContactCanWePhone.error.required" - val invalidKey = "error.boolean" - - val form = new FirstContactCanWePhoneFormProvider()() - - ".value" - { - - val fieldName = "value" - - behave like booleanField( - form, - fieldName, - invalidError = FormError(fieldName, invalidKey) - ) - - behave like mandatoryField( - form, - fieldName, - requiredError = FormError(fieldName, requiredKey) - ) - } - -} diff --git a/test/navigation/NavigatorSpec.scala b/test/navigation/NavigatorSpec.scala index 5fc89d8c..adf98026 100644 --- a/test/navigation/NavigatorSpec.scala +++ b/test/navigation/NavigatorSpec.scala @@ -42,7 +42,7 @@ class NavigatorSpec extends SpecBase { navigator.nextPage(FirstContactEmailPage, NormalMode, UserAnswers("id")) mustBe routes.ContactHavePhoneController.onPageLoad(NormalMode) } - "must go from FirstContactCanWePhone" - { + "must go from ContactHavePhonePage" - { " to FirstContactPhone if Yes" in { val userAnswers = emptyUserAnswers.set(ContactHavePhonePage, true).get navigator.nextPage(ContactHavePhonePage, NormalMode, userAnswers) mustBe