Skip to content

Commit

Permalink
Merge pull request #262 from hmrc/ITSASU-2821
Browse files Browse the repository at this point in the history
ITSASU-2821 - Removed the tax year sign up feature switch and related…
  • Loading branch information
srikanthsunkara79 authored Jan 22, 2024
2 parents 7ea7c32 + 8c4ee7b commit f092700
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 453 deletions.
6 changes: 0 additions & 6 deletions app/config/featureswitch/FeatureSwitch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ object FeatureSwitch {

val switches: Set[FeatureSwitch] = Set(
StubDESFeature,
TaxYearSignup,
NewGetBusinessDetails
)

Expand All @@ -51,11 +50,6 @@ object StubDESFeature extends FeatureSwitch {
val name = s"$prefix.stub-des"
}

object TaxYearSignup extends FeatureSwitch {
val displayName = s"Provide API with tax year"
val name = s"$prefix.taxyear-signup"
}

object NewGetBusinessDetails extends FeatureSwitch {
val displayName = s"Use the new get business details API"
val name = s"$prefix.new-get-business-details"
Expand Down
53 changes: 0 additions & 53 deletions app/connectors/SignUpConnector.scala

This file was deleted.

40 changes: 9 additions & 31 deletions app/controllers/SignUpController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ package controllers

import common.Extractors
import config.AppConfig
import config.featureswitch.FeatureSwitching.isEnabled
import config.featureswitch.TaxYearSignup
import connectors.{SignUpConnector, SignUpTaxYearConnector}
import connectors.SignUpTaxYearConnector
import models.monitoring.{RegistrationFailureAudit, RegistrationSuccessAudit}
import play.api.libs.json.Json
import play.api.mvc._
import play.api.{Configuration, Logger}
import services.AuthService
import services.monitoring.AuditService
import uk.gov.hmrc.auth.core.Enrolments
import uk.gov.hmrc.auth.core.retrieve.v2.Retrievals
import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController

Expand All @@ -39,48 +36,29 @@ import scala.concurrent.ExecutionContext
class SignUpController @Inject()(authService: AuthService,
auditService: AuditService,
configuration: Configuration,
signUpConnector: SignUpConnector,
signUpTaxYearConnector: SignUpTaxYearConnector,
cc: ControllerComponents, appConfig: AppConfig)(implicit ec: ExecutionContext) extends BackendController(cc) with Extractors {

val logger: Logger = Logger(this.getClass)


def signUp(nino: String, taxYear: String): Action[AnyContent] = Action.async { implicit request =>
authService.authorised().retrieve(Retrievals.allEnrolments) { enrolments =>
if (isEnabled(TaxYearSignup, configuration))
taxYearSignUp(nino, taxYear, enrolments)
else
desSignUp(nino, enrolments)
signUp(
nino = nino,
taxYear = taxYear,
agentReferenceNumber = getArnFromEnrolments(enrolments)
)
}
}

private def desSignUp(nino: String, enrolments: Enrolments)(implicit request: Request[AnyContent]) =

signUpConnector.signUp(nino).map {
case Right(response) => {
val path: Option[String] = request.headers.get(ITSASessionKeys.RequestURI)
auditService.audit(RegistrationSuccessAudit(
getArnFromEnrolments(enrolments), nino, response.mtdbsa, appConfig.desAuthorisationToken, path
))
Ok(Json.toJson(response))
}
case Left(error) =>
logger.error(s"Error processing Sign up request with status ${error.status} and message ${error.reason}")
auditService.audit(RegistrationFailureAudit(nino, error.status, error.reason))
InternalServerError("Failed Sign up")
}


private def taxYearSignUp(nino: String, taxYear: String, enrolments: Enrolments)(implicit request: Request[AnyContent]) =
private def signUp(nino: String, taxYear: String, agentReferenceNumber: Option[String])(implicit request: Request[AnyContent]) =
signUpTaxYearConnector.signUp(nino, taxYear).map {
case Right(response) => {
case Right(response) =>
val path: Option[String] = request.headers.get(ITSASessionKeys.RequestURI)
auditService.audit(RegistrationSuccessAudit(
getArnFromEnrolments(enrolments), nino, response.mtdbsa, appConfig.signUpServiceAuthorisationToken, path
agentReferenceNumber, nino, response.mtdbsa, appConfig.signUpServiceAuthorisationToken, path
))
Ok(Json.toJson(response))
}
case Left(error) =>
logger.error(s"Error processing Sign up request with status ${error.status} and message ${error.reason}")
auditService.audit(RegistrationFailureAudit(nino, error.status, error.reason))
Expand Down
5 changes: 3 additions & 2 deletions app/models/DateModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import play.api.libs.json.{Json, OFormat}

import java.time.LocalDate
import java.time.format.{DateTimeFormatter, ResolverStyle}
import scala.language.implicitConversions

case class DateModel(day: String, month: String, year: String) {

val outputFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("d MMMM uuuu").withResolverStyle(ResolverStyle.STRICT)
val desFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("uuuu-MM-dd").withResolverStyle(ResolverStyle.STRICT)
private val outputFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("d MMMM uuuu").withResolverStyle(ResolverStyle.STRICT)
private val desFormat: DateTimeFormatter = DateTimeFormatter.ofPattern("uuuu-MM-dd").withResolverStyle(ResolverStyle.STRICT)

def toLocalDate: LocalDate = LocalDate.of(year.toInt, month.toInt, day.toInt)

Expand Down
2 changes: 2 additions & 0 deletions app/models/frontend/IncomeSourceType.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package models.frontend

import scala.language.implicitConversions

sealed trait IncomeSourceType

case object Business extends IncomeSourceType
Expand Down
4 changes: 3 additions & 1 deletion app/models/subscription/business/AccountingMethodModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package models.subscription.business

import play.api.libs.json._

import scala.language.implicitConversions


sealed trait AccountingMethod {
val stringValue: String
Expand All @@ -35,7 +37,7 @@ object AccountingMethod {
val feCash = "Cash"
val feAccruals = "Accruals"

private val reader: Reads[AccountingMethod] = __.read[String].map (convert)
private val reader: Reads[AccountingMethod] = __.read[String].map(convert)

private val writer: Writes[AccountingMethod] = Writes[AccountingMethod](cashOrAccruals =>
JsString(cashOrAccruals.stringValue)
Expand Down
2 changes: 2 additions & 0 deletions app/utils/JsonUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package utils
import play.api.libs.json._
import uk.gov.hmrc.http.HttpResponse

import scala.language.implicitConversions

trait JsonUtils {

implicit def toJsValue[T](data: T)(implicit writer: Writes[T]): JsValue = Json.toJson(data)
Expand Down
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ lazy val microservice = Project(appName, file("."))
.enablePlugins(play.sbt.PlayScala, SbtDistributablesPlugin)
.settings(
libraryDependencies ++= AppDependencies.compile ++ AppDependencies.test,
scalacOptions += "-Wconf:src=.*/views/.*:s",
scalacOptions += "-feature",
scalacOptions += "-Wconf:src=routes/.*:s",
)
.settings(PlayKeys.playDefaultPort := 9560)
.settings(CodeCoverageSettings.settings: _*)
.settings(CodeCoverageSettings.settings *)

lazy val it = project
.enablePlugins(PlayScala)
Expand Down
72 changes: 0 additions & 72 deletions it/test/connectors/SignUpConnectorISpec.scala

This file was deleted.

44 changes: 13 additions & 31 deletions it/test/controllers/SignUpControllerISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,23 @@
package controllers

import config.MicroserviceAppConfig
import config.featureswitch.{FeatureSwitching, TaxYearSignup}
import config.featureswitch.FeatureSwitching
import helpers.ComponentSpecBase
import helpers.IntegrationTestConstants._
import helpers.servicemocks.{AuthStub, SignUpStub, SignUpTaxYearStub}
import helpers.servicemocks.{AuthStub, SignUpTaxYearStub}
import models.SignUpResponse
import play.api.Configuration
import play.api.http.Status._
import play.api.libs.json.Json

class SignUpControllerISpec extends ComponentSpecBase with FeatureSwitching {

val appConfig: MicroserviceAppConfig = app.injector.instanceOf[MicroserviceAppConfig]
val signUpController: SignUpController = app.injector.instanceOf[SignUpController]
val configuration: Configuration = app.injector.instanceOf[Configuration]

override def beforeEach(): Unit = {
super.beforeEach()
disable(TaxYearSignup)
}

"signUp" should {
"call sign up connector successfully when auth succeeds for a sign up submission 200" in {
AuthStub.stubAuth(OK)
SignUpStub.stubSignUp(testNino, testSignUpSubmission(testNino), appConfig.desAuthorisationToken, appConfig.desEnvironment)(
OK, testSignUpSuccessBody
)

val res = IncomeTaxSubscription.signUp(testNino, testTaxYear)

res should have(
httpStatus(OK)
)
res should have(
jsonBodyAs[SignUpResponse](SignUpResponse("XQIT00000000001"))
)
}

"feature switch is enabled call sign up connector successfully when auth succeeds for a sign up submission 200" in {
enable(TaxYearSignup)
"call sign up connector successfully when auth succeeds for a sign up submission 200" in {
AuthStub.stubAuth(OK)
SignUpTaxYearStub.stubSignUp(
testTaxYearSignUpSubmission(testNino, testTaxYear),
Expand All @@ -75,9 +53,11 @@ class SignUpControllerISpec extends ComponentSpecBase with FeatureSwitching {

"return a Json parse failure when invalid json is found" in {
AuthStub.stubAuthSuccess()
SignUpStub.stubSignUp(testNino, testSignUpSubmission(testNino), appConfig.desAuthorisationToken, appConfig.desEnvironment)(
OK, testSignUpInvalidBody
)
SignUpTaxYearStub.stubSignUp(
testTaxYearSignUpSubmission(testNino, testTaxYear),
appConfig.signUpServiceAuthorisationToken,
appConfig.signUpServiceEnvironment
)(OK, testSignUpInvalidBody)

val res = IncomeTaxSubscription.signUp(testNino, testTaxYear)

Expand All @@ -88,9 +68,11 @@ class SignUpControllerISpec extends ComponentSpecBase with FeatureSwitching {

"Show error processing Sign up request with status Internal Server Error" in {
AuthStub.stubAuthSuccess()
SignUpStub.stubSignUp(testNino, testSignUpSubmission(testNino), appConfig.desAuthorisationToken, appConfig.desEnvironment)(
INTERNAL_SERVER_ERROR, failureResponse("code", "reason")
)
SignUpTaxYearStub.stubSignUp(
testTaxYearSignUpSubmission(testNino, testTaxYear),
appConfig.signUpServiceAuthorisationToken,
appConfig.signUpServiceEnvironment
)(INTERNAL_SERVER_ERROR, failureResponse("code", "reason"))

val res = IncomeTaxSubscription.signUp(testNino, testTaxYear)

Expand Down
8 changes: 0 additions & 8 deletions it/test/helpers/IntegrationTestConstants.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,6 @@ object IntegrationTestConstants extends JsonUtils {
|}
""".stripMargin

def testSignUpSubmission(nino: String): JsValue = Json.parse(
s"""
|{
| "idType" : "NINO",
| "idValue" : "$nino"
|}
""".stripMargin)

def testTaxYearSignUpSubmission(nino: String, taxYear:String): JsValue = Json.obj(
"nino" -> nino,
"signupTaxYear" -> taxYear
Expand Down
Loading

0 comments on commit f092700

Please sign in to comment.