Skip to content

Commit

Permalink
Merge pull request #1495 from hmrc/ITSASU-3671
Browse files Browse the repository at this point in the history
ITSASU-3671 update agent noSoftwareController to use new auth actions
  • Loading branch information
AlexRimmerHMRC authored Feb 21, 2025
2 parents f1270f5 + cce0ba9 commit 9be64f8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 43 deletions.
54 changes: 14 additions & 40 deletions app/controllers/agent/NoSoftwareController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,29 @@

package controllers.agent

import auth.agent.AuthenticatedController
import config.AppConfig
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents, Request}
import play.twirl.api.Html
import services.agent.ClientDetailsRetrieval
import services.{AuditingService, AuthService}
import controllers.SignUpBaseController
import controllers.agent.actions.{ConfirmedClientJourneyRefiner, IdentifierAction}
import play.api.mvc.{Action, AnyContent, MessagesControllerComponents}
import views.html.agent.NoSoftware

import javax.inject.{Inject, Singleton}
import scala.concurrent.ExecutionContext
import scala.util.matching.Regex


@Singleton
class NoSoftwareController @Inject()(val auditingService: AuditingService,
val authService: AuthService,
clientDetailsRetrieval: ClientDetailsRetrieval,
noSoftware: NoSoftware)
(implicit mcc: MessagesControllerComponents, val ec: ExecutionContext, val appConfig: AppConfig)
extends AuthenticatedController {

private val ninoRegex: Regex = """^([a-zA-Z]{2})\s*(\d{2})\s*(\d{2})\s*(\d{2})\s*([a-zA-Z])$""".r

private def formatNino(clientNino: String): String = {
clientNino match {
case ninoRegex(startLetters, firstDigits, secondDigits, thirdDigits, finalLetter) =>
s"$startLetters $firstDigits $secondDigits $thirdDigits $finalLetter"
case other => other
}
}

def view(clientName: String, clientNino: String)(implicit request: Request[_]): Html = {
noSoftware(
class NoSoftwareController @Inject()(view: NoSoftware,
identify: IdentifierAction,
journeyRefiner: ConfirmedClientJourneyRefiner)
(implicit mcc: MessagesControllerComponents,
val ec: ExecutionContext) extends SignUpBaseController {

val show: Action[AnyContent] = (identify andThen journeyRefiner) { implicit request =>
Ok(view(
backUrl = controllers.agent.routes.UsingSoftwareController.show.url,
postAction = controllers.agent.routes.AddAnotherClientController.addAnother(),
clientName,
clientNino
)
clientName = request.clientDetails.name,
clientNino = request.clientDetails.formattedNino
))
}

val show: Action[AnyContent] = Authenticated.async { implicit request =>
_ =>
clientDetailsRetrieval.getClientDetails map { clientDetails =>
Ok(view(clientName = clientDetails.name, clientNino = formatNino(clientDetails.nino)))
}
}

val submit: Action[AnyContent] = Authenticated { _ =>
_ =>
Redirect(controllers.agent.routes.AddAnotherClientController.addAnother())
}
}
18 changes: 16 additions & 2 deletions it/test/controllers/agent/NoSoftwareControllerISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,35 @@ package controllers.agent

import common.Constants.ITSASessionKeys
import connectors.stubs.SessionDataConnectorStub
import helpers.IntegrationTestConstants.testNino
import helpers.IntegrationTestConstants.{basGatewaySignIn, testNino}
import helpers.agent.ComponentSpecBase
import helpers.agent.servicemocks.AuthStub
import play.api.http.Status.OK
import play.api.http.Status.{OK, SEE_OTHER}
import play.api.libs.json.JsString
import utilities.agent.TestConstants.testUtr

class NoSoftwareControllerISpec extends ComponentSpecBase {

val serviceNameGovUk = " - Use software to report your client’s Income Tax - GOV.UK"

s"GET ${controllers.agent.routes.NoSoftwareController.show()}" should {
"return SEE_OTHER to the login page when the user is unauthenticated" in {
AuthStub.stubUnauthorised()

val res = IncomeTaxSubscriptionFrontend.showNoSoftware()

res must have(
httpStatus(SEE_OTHER),
redirectURI(basGatewaySignIn("/client/no-compatible-software"))
)
}

"return OK and show the No Software page" in {
Given("I setup the Wiremock stubs")
AuthStub.stubAuthSuccess()
SessionDataConnectorStub.stubGetSessionData(ITSASessionKeys.NINO)(OK, JsString(testNino))
SessionDataConnectorStub.stubGetSessionData(ITSASessionKeys.UTR)(OK, JsString(testUtr))

When(s"GET ${controllers.agent.routes.NoSoftwareController.show()}")
val result = IncomeTaxSubscriptionFrontend.showNoSoftware()
Then("The result should be OK with page content")
Expand Down
16 changes: 15 additions & 1 deletion test/views/agent/NoSoftwareViewSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class NoSoftwareViewSpec extends ViewSpec {
private val noSoftware: NoSoftware = app.injector.instanceOf[NoSoftware]
private val fullName = "FirstName LastName"
private val nino = "ZZ 11 11 11 Z"
private val postAction: Call = controllers.agent.routes.NoSoftwareController.show()
private val postAction: Call = controllers.agent.routes.AddAnotherClientController.addAnother()
private val backUrl: String = controllers.agent.routes.UsingSoftwareController.show.url

"NoSoftware" must {
Expand Down Expand Up @@ -81,6 +81,19 @@ class NoSoftwareViewSpec extends ViewSpec {
"have the fifth paragraph" in {
document.mainContent.selectNth("p", 5).text mustBe NoSoftwareMessages.paraFive
}

"have a form" which {

"has the correct attributes" in {
document.mainContent.getForm.attr("method") mustBe postAction.method
document.mainContent.getForm.attr("action") mustBe postAction.url
}

"has an accept and continue button to submit the form" in {
document.mainContent.getForm.selectNth(".govuk-button", 1).text mustBe NoSoftwareMessages.buttonText
}
}

}

private object NoSoftwareMessages {
Expand All @@ -94,6 +107,7 @@ class NoSoftwareViewSpec extends ViewSpec {
val paraThreeLinkHref = "https://www.gov.uk/guidance/find-software-thats-compatible-with-making-tax-digital-for-income-tax"
val paraFour = "When you have compatible software, you can come back to sign up your client."
val paraFive = "Meanwhile, you’ll need to make sure your client submits their Self Assessment tax return as normal."
val buttonText = "Sign up another client"
}

private def page(clientName: String = fullName, clientNino: String = nino): Html = {
Expand Down

0 comments on commit 9be64f8

Please sign in to comment.