Skip to content

Commit

Permalink
package-refactor: created folder for formProvider for profile journey…
Browse files Browse the repository at this point in the history
… and moves files and also created packages for Categorisation journey and implemented changes for 1 page(CategoryGuidancePage)
  • Loading branch information
kenneth-rayner committed Nov 6, 2024
1 parent 0cb1e89 commit 26d1244
Show file tree
Hide file tree
Showing 14 changed files with 138 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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] =
Expand Down
44 changes: 44 additions & 0 deletions app/navigation/CategorisationNavigator.scala
Original file line number Diff line number Diff line change
@@ -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()
}


}
3 changes: 2 additions & 1 deletion app/navigation/Navigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

package pages
package pages.categorisation

import pages.Page

case class CategoryGuidancePage(recordId: String) extends Page
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h1 class="govuk-heading-l">@messages("categoryGuidance.heading")</h1>
<h2 class="govuk-heading-m">@messages("categoryGuidance.subheading")</h2>
<p class="govuk-body">@messages("categoryGuidance.p4")</p>

@formHelper(action = CategoryGuidanceController.onSubmit(recordId)) {
@formHelper(action = controllers.categorisation.routes.CategoryGuidanceController.onSubmit(recordId)) {
@govukButton(
ButtonViewModel(messages("site.continue"))
)
Expand Down
2 changes: 2 additions & 0 deletions conf/app.categorisation.routes
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 1 addition & 3 deletions conf/app.routes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# microservice specific routes

-> / app.profile.Routes
-> / app.categorisation.Routes
-> /hmrc-frontend hmrcfrontend.Routes

GET / controllers.IndexController.onPageLoad()
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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

Expand All @@ -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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
55 changes: 55 additions & 0 deletions test/navigation/CategorisationNavigatorSpec.scala
Original file line number Diff line number Diff line change
@@ -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" - {}

}
}
4 changes: 4 additions & 0 deletions test/navigation/FakeNavigator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
19 changes: 6 additions & 13 deletions test/navigation/NavigatorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

Expand All @@ -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)

}

Expand All @@ -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)

}

Expand All @@ -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)

}

Expand All @@ -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)

}

Expand All @@ -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)

}
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 26d1244

Please sign in to comment.