diff --git a/app/controllers/CategoryGuidanceController.scala b/app/controllers/categorisation/CategoryGuidanceController.scala similarity index 86% rename from app/controllers/CategoryGuidanceController.scala rename to app/controllers/categorisation/CategoryGuidanceController.scala index b73f91754..5097238d3 100644 --- a/app/controllers/CategoryGuidanceController.scala +++ b/app/controllers/categorisation/CategoryGuidanceController.scala @@ -14,15 +14,16 @@ * limitations under the License. */ -package controllers +package controllers.categorisation +import controllers.BaseController import controllers.actions._ import models.NormalMode -import navigation.Navigator -import pages.CategoryGuidancePage +import navigation.CategorisationNavigator +import pages.categorisation.CategoryGuidancePage import play.api.i18n.MessagesApi import play.api.mvc.{Action, AnyContent, MessagesControllerComponents} -import views.html.CategoryGuidanceView +import views.html.categorisation.CategoryGuidanceView import javax.inject.Inject @@ -34,7 +35,7 @@ class CategoryGuidanceController @Inject() ( profileAuth: ProfileAuthenticateAction, val controllerComponents: MessagesControllerComponents, view: CategoryGuidanceView, - navigator: Navigator + navigator: CategorisationNavigator ) extends BaseController { def onPageLoad(recordId: String): Action[AnyContent] = diff --git a/app/navigation/CategorisationNavigator.scala b/app/navigation/CategorisationNavigator.scala new file mode 100644 index 000000000..e8cfaa0b6 --- /dev/null +++ b/app/navigation/CategorisationNavigator.scala @@ -0,0 +1,44 @@ +/* + * 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 navigation + +import controllers.routes +import models._ +import pages._ +import pages.categorisation.CategoryGuidancePage +import play.api.mvc.Call +import services.CategorisationService +import utils.Constants.firstAssessmentNumber + +import javax.inject.{Inject, Singleton} + +@Singleton +class CategorisationNavigator @Inject() (categorisationService: CategorisationService) extends NavigatorTrait { + + val normalRoutes: Page => UserAnswers => Call = { + case p: CategoryGuidancePage => + _ => routes.AssessmentController.onPageLoad(NormalMode, p.recordId, firstAssessmentNumber) + case _ => _ => routes.IndexController.onPageLoad() + } + + val checkRoutes: Page => UserAnswers => Call = { + + case _ => _ => routes.JourneyRecoveryController.onPageLoad() + } + + +} diff --git a/app/navigation/Navigator.scala b/app/navigation/Navigator.scala index 924404634..0f381e8c0 100644 --- a/app/navigation/Navigator.scala +++ b/app/navigation/Navigator.scala @@ -22,6 +22,7 @@ import models.Scenario.getResultAsInt import models._ import models.ott.{CategorisationInfo, CategoryAssessment} import pages._ +import pages.categorisation.CategoryGuidancePage import play.api.mvc.Call import queries.{CategorisationDetailsQuery, LongerCategorisationDetailsQuery, LongerCommodityQuery} import services.CategorisationService @@ -223,7 +224,7 @@ class Navigator @Inject() (categorisationService: CategorisationService) extends case Some(catInfo) if catInfo.isCommCodeExpired => routes.ExpiredCommodityCodeController.onPageLoad(recordId) case Some(catInfo) if catInfo.categoryAssessmentsThatNeedAnswers.nonEmpty => - routes.CategoryGuidanceController.onPageLoad(recordId) + controllers.categorisation.routes.CategoryGuidanceController.onPageLoad(recordId) case Some(catInfo) => val scenario = categorisationService.calculateResult(catInfo, answers, recordId) diff --git a/app/pages/CategoryGuidancePage.scala b/app/pages/categorisation/CategoryGuidancePage.scala similarity index 93% rename from app/pages/CategoryGuidancePage.scala rename to app/pages/categorisation/CategoryGuidancePage.scala index 417da1c3e..092255677 100644 --- a/app/pages/CategoryGuidancePage.scala +++ b/app/pages/categorisation/CategoryGuidancePage.scala @@ -14,6 +14,8 @@ * limitations under the License. */ -package pages +package pages.categorisation + +import pages.Page case class CategoryGuidancePage(recordId: String) extends Page diff --git a/app/views/CategoryGuidanceView.scala.html b/app/views/categorisation/CategoryGuidanceView.scala.html similarity index 93% rename from app/views/CategoryGuidanceView.scala.html rename to app/views/categorisation/CategoryGuidanceView.scala.html index 2e871dd55..f6dd45f61 100644 --- a/app/views/CategoryGuidanceView.scala.html +++ b/app/views/categorisation/CategoryGuidanceView.scala.html @@ -36,7 +36,7 @@

@messages("categoryGuidance.heading")

@messages("categoryGuidance.subheading")

@messages("categoryGuidance.p4")

- @formHelper(action = CategoryGuidanceController.onSubmit(recordId)) { + @formHelper(action = controllers.categorisation.routes.CategoryGuidanceController.onSubmit(recordId)) { @govukButton( ButtonViewModel(messages("site.continue")) ) diff --git a/conf/app.categorisation.routes b/conf/app.categorisation.routes new file mode 100644 index 000000000..2ddc832f9 --- /dev/null +++ b/conf/app.categorisation.routes @@ -0,0 +1,2 @@ +GET /update-record/:recordId/categorisation/start controllers.categorisation.CategoryGuidanceController.onPageLoad(recordId: String) +POST /update-record/:recordId/categorisation/start controllers.categorisation.CategoryGuidanceController.onSubmit(recordId: String) diff --git a/conf/app.routes b/conf/app.routes index 3e0b6a0af..9012a32a5 100644 --- a/conf/app.routes +++ b/conf/app.routes @@ -1,6 +1,7 @@ # microservice specific routes -> / app.profile.Routes +-> / app.categorisation.Routes -> /hmrc-frontend hmrcfrontend.Routes GET / controllers.IndexController.onPageLoad() @@ -22,9 +23,6 @@ GET /problem/unauthorised-sign-in GET /problem/unauthorised-service-user controllers.UnauthorisedServiceUserController.onPageLoad() GET /problem/unauthorised-cds-enrolment controllers.UnauthorisedCdsEnrolmentController.onPageLoad() -GET /update-record/:recordId/categorisation/start controllers.CategoryGuidanceController.onPageLoad(recordId: String) -POST /update-record/:recordId/categorisation/start controllers.CategoryGuidanceController.onSubmit(recordId: String) - GET /create-record/commodity-code controllers.CommodityCodeController.onPageLoadCreate(mode: Mode = NormalMode) POST /create-record/commodity-code controllers.CommodityCodeController.onSubmitCreate(mode: Mode = NormalMode) GET /create-record/commodity-code/check controllers.CommodityCodeController.onPageLoadCreate(mode: Mode = CheckMode) diff --git a/test/controllers/CategoryGuidanceControllerSpec.scala b/test/controllers/categorisation/CategoryGuidanceControllerSpec.scala similarity index 76% rename from test/controllers/CategoryGuidanceControllerSpec.scala rename to test/controllers/categorisation/CategoryGuidanceControllerSpec.scala index 08008a461..7bb2a4ee0 100644 --- a/test/controllers/CategoryGuidanceControllerSpec.scala +++ b/test/controllers/categorisation/CategoryGuidanceControllerSpec.scala @@ -14,16 +14,16 @@ * limitations under the License. */ -package controllers +package controllers.categorisation import base.SpecBase import base.TestConstants.testRecordId -import navigation.{FakeNavigator, Navigator} +import navigation.{CategorisationNavigator, FakeCategorisationNavigator} import play.api.inject._ import play.api.mvc.Call import play.api.test.FakeRequest import play.api.test.Helpers._ -import views.html.CategoryGuidanceView +import views.html.categorisation.CategoryGuidanceView class CategoryGuidanceControllerSpec extends SpecBase { @@ -35,7 +35,8 @@ class CategoryGuidanceControllerSpec extends SpecBase { val application = applicationBuilder(userAnswers = Some(emptyUserAnswers)).build() running(application) { - val request = FakeRequest(GET, routes.CategoryGuidanceController.onPageLoad(testRecordId).url) + val request = + FakeRequest(GET, controllers.categorisation.routes.CategoryGuidanceController.onPageLoad(testRecordId).url) val result = route(application, request).value @@ -50,12 +51,13 @@ class CategoryGuidanceControllerSpec extends SpecBase { val application = applicationBuilder(userAnswers = Some(userAnswersForCategorisation)) .overrides( - bind[Navigator].toInstance(new FakeNavigator(onwardRoute)) + bind[CategorisationNavigator].toInstance(new FakeCategorisationNavigator(onwardRoute)) ) .build() running(application) { - val request = FakeRequest(POST, routes.CategoryGuidanceController.onSubmit(testRecordId).url) + val request = + FakeRequest(POST, controllers.categorisation.routes.CategoryGuidanceController.onSubmit(testRecordId).url) val result = route(application, request).value diff --git a/test/forms/profile/RemoveNirmsFormProviderSpec.scala b/test/forms/RemoveNirmsFormProviderSpec.scala similarity index 95% rename from test/forms/profile/RemoveNirmsFormProviderSpec.scala rename to test/forms/RemoveNirmsFormProviderSpec.scala index 8710239eb..21fbda844 100644 --- a/test/forms/profile/RemoveNirmsFormProviderSpec.scala +++ b/test/forms/RemoveNirmsFormProviderSpec.scala @@ -14,9 +14,10 @@ * limitations under the License. */ -package forms.profile +package forms import forms.behaviours.BooleanFieldBehaviours +import forms.profile.RemoveNirmsFormProvider import play.api.data.FormError class RemoveNirmsFormProviderSpec extends BooleanFieldBehaviours { diff --git a/test/forms/profile/UkimsNumberFormProviderSpec.scala b/test/forms/UkimsNumberFormProviderSpec.scala similarity index 99% rename from test/forms/profile/UkimsNumberFormProviderSpec.scala rename to test/forms/UkimsNumberFormProviderSpec.scala index 0e0abbe63..a1ae80023 100644 --- a/test/forms/profile/UkimsNumberFormProviderSpec.scala +++ b/test/forms/UkimsNumberFormProviderSpec.scala @@ -14,9 +14,10 @@ * limitations under the License. */ -package forms.profile +package forms import forms.behaviours.StringFieldBehaviours +import forms.profile.UkimsNumberFormProvider import org.scalacheck.Gen import play.api.data.{Form, FormError} diff --git a/test/forms/profile/UseExistingUkimsNumberFormProviderSpec.scala b/test/forms/UseExistingUkimsNumberFormProviderSpec.scala similarity index 94% rename from test/forms/profile/UseExistingUkimsNumberFormProviderSpec.scala rename to test/forms/UseExistingUkimsNumberFormProviderSpec.scala index 5fb1d5215..8a620a29f 100644 --- a/test/forms/profile/UseExistingUkimsNumberFormProviderSpec.scala +++ b/test/forms/UseExistingUkimsNumberFormProviderSpec.scala @@ -14,9 +14,10 @@ * limitations under the License. */ -package forms.profile +package forms import forms.behaviours.BooleanFieldBehaviours +import forms.profile.UseExistingUkimsNumberFormProvider import play.api.data.FormError class UseExistingUkimsNumberFormProviderSpec extends BooleanFieldBehaviours { diff --git a/test/navigation/CategorisationNavigatorSpec.scala b/test/navigation/CategorisationNavigatorSpec.scala new file mode 100644 index 000000000..f14bd69ee --- /dev/null +++ b/test/navigation/CategorisationNavigatorSpec.scala @@ -0,0 +1,55 @@ +/* + * 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 navigation + +import base.SpecBase +import controllers.routes +import models._ +import org.scalatest.BeforeAndAfterEach +import org.scalatestplus.mockito.MockitoSugar.mock +import pages.Page +import pages.categorisation.CategoryGuidancePage +import services.CategorisationService +import utils.Constants + +class CategorisationNavigatorSpec extends SpecBase with BeforeAndAfterEach { + + private val categorisationService = mock[CategorisationService] + + private val navigator = new CategorisationNavigator(categorisationService) + + private val recordId = "dummyRecordId" + private val userAnswers = UserAnswers(recordId) + + "CategorisationNavigator" - { + + "return AssessmentController.onPageLoad for CategoryGuidancePage in normalRoutes" in { + + navigator.normalRoutes(CategoryGuidancePage(recordId))(userAnswers) mustBe routes.AssessmentController + .onPageLoad(NormalMode, recordId, Constants.firstAssessmentNumber) + } + + "return IndexController.onPageLoad for other pages in normalRoutes" in { + val page = new Page {} + + navigator.normalRoutes(page)(userAnswers) mustBe routes.IndexController.onPageLoad() + } + + "when in Check mode" - {} + + } +} diff --git a/test/navigation/FakeNavigator.scala b/test/navigation/FakeNavigator.scala index 8563387cf..d6fcbf485 100644 --- a/test/navigation/FakeNavigator.scala +++ b/test/navigation/FakeNavigator.scala @@ -38,3 +38,7 @@ class FakeNavigator(desiredRoute: Call) extends Navigator(mock[CategorisationSer class FakeProfileNavigator(desiredRoute: Call) extends ProfileNavigator { override def nextPage(page: Page, mode: Mode, userAnswers: UserAnswers): Call = desiredRoute } + +class FakeCategorisationNavigator(desiredRoute: Call) extends CategorisationNavigator(mock[CategorisationService]) { + override def nextPage(page: Page, mode: Mode, userAnswers: UserAnswers): Call = desiredRoute +} diff --git a/test/navigation/NavigatorSpec.scala b/test/navigation/NavigatorSpec.scala index 0404c3444..34203c403 100644 --- a/test/navigation/NavigatorSpec.scala +++ b/test/navigation/NavigatorSpec.scala @@ -410,7 +410,7 @@ class NavigatorSpec extends SpecBase with BeforeAndAfterEach { .value navigator.nextPage(CategorisationPreparationPage(testRecordId), NormalMode, userAnswers) mustEqual - routes.CategoryGuidanceController.onPageLoad(testRecordId) + controllers.categorisation.routes.CategoryGuidanceController.onPageLoad(testRecordId) } @@ -436,7 +436,7 @@ class NavigatorSpec extends SpecBase with BeforeAndAfterEach { CategorisationPreparationPage(testRecordId), NormalMode, userAnswers - ) mustBe routes.CategoryGuidanceController.onPageLoad(testRecordId) + ) mustBe controllers.categorisation.routes.CategoryGuidanceController.onPageLoad(testRecordId) } @@ -462,7 +462,7 @@ class NavigatorSpec extends SpecBase with BeforeAndAfterEach { CategorisationPreparationPage(testRecordId), NormalMode, userAnswers - ) mustBe routes.CategoryGuidanceController.onPageLoad(testRecordId) + ) mustBe controllers.categorisation.routes.CategoryGuidanceController.onPageLoad(testRecordId) } @@ -488,7 +488,7 @@ class NavigatorSpec extends SpecBase with BeforeAndAfterEach { CategorisationPreparationPage(testRecordId), NormalMode, userAnswers - ) mustBe routes.CategoryGuidanceController.onPageLoad(testRecordId) + ) mustBe controllers.categorisation.routes.CategoryGuidanceController.onPageLoad(testRecordId) } @@ -513,7 +513,7 @@ class NavigatorSpec extends SpecBase with BeforeAndAfterEach { CategorisationPreparationPage(testRecordId), NormalMode, userAnswers - ) mustBe routes.CategoryGuidanceController.onPageLoad(testRecordId) + ) mustBe controllers.categorisation.routes.CategoryGuidanceController.onPageLoad(testRecordId) } @@ -538,7 +538,7 @@ class NavigatorSpec extends SpecBase with BeforeAndAfterEach { CategorisationPreparationPage(testRecordId), NormalMode, userAnswers - ) mustBe routes.CategoryGuidanceController.onPageLoad(testRecordId) + ) mustBe controllers.categorisation.routes.CategoryGuidanceController.onPageLoad(testRecordId) } } @@ -1056,13 +1056,6 @@ class NavigatorSpec extends SpecBase with BeforeAndAfterEach { } } - "must go from category guidance to the first assessment page" in { - - navigator.nextPage(CategoryGuidancePage(testRecordId), NormalMode, emptyUserAnswers) mustEqual - routes.AssessmentController.onPageLoad(NormalMode, testRecordId, firstAssessmentNumber) - - } - "must go from assessment page" - { "to the next assessment if answer is yes and there are more assessments" in {