diff --git a/app/config/featureswitch/FeatureSwitch.scala b/app/config/featureswitch/FeatureSwitch.scala index ea17cbf8..61ef5295 100644 --- a/app/config/featureswitch/FeatureSwitch.scala +++ b/app/config/featureswitch/FeatureSwitch.scala @@ -29,7 +29,6 @@ object FeatureSwitch { val switches: Set[FeatureSwitch] = Set( StubDESFeature, - TaxYearSignup, NewGetBusinessDetails ) @@ -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" diff --git a/app/connectors/SignUpConnector.scala b/app/connectors/SignUpConnector.scala deleted file mode 100644 index 56ed0434..00000000 --- a/app/connectors/SignUpConnector.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2023 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 connectors - -import config.AppConfig -import parsers.SignUpParser.{PostSignUpResponse, signUpResponseHttpReads} -import play.api.libs.json.{JsObject, JsValue, Json} -import uk.gov.hmrc.http.{Authorization, HeaderCarrier, HeaderNames, HttpClient, HttpReads} - -import javax.inject.{Inject, Singleton} -import scala.concurrent.{ExecutionContext, Future} - -@Singleton -class SignUpConnector @Inject()(http: HttpClient, - appConfig: AppConfig)(implicit ec: ExecutionContext) { - - def signUpUrl(nino: String): String = s"${appConfig.desURL}/income-tax/sign-up/ITSA" - - def requestBody(nino: String): JsObject = Json.obj( - "idType" -> "NINO", - "idValue" -> nino - ) - - - def signUp(nino: String)(implicit hc: HeaderCarrier): Future[PostSignUpResponse] = { - - val headerCarrier: HeaderCarrier = hc - .copy(authorization = Some(Authorization(appConfig.desAuthorisationToken))) - .withExtraHeaders(appConfig.desEnvironmentHeader) - - val desHeaders: Seq[(String, String)] = Seq( - HeaderNames.authorisation -> appConfig.desAuthorisationToken, - appConfig.desEnvironmentHeader - ) - - http.POST[JsValue, PostSignUpResponse](signUpUrl(nino), requestBody(nino), headers = desHeaders)( - implicitly, implicitly[HttpReads[PostSignUpResponse]], headerCarrier, implicitly) - } -} diff --git a/app/controllers/SignUpController.scala b/app/controllers/SignUpController.scala index fa67db5a..d7c993fc 100644 --- a/app/controllers/SignUpController.scala +++ b/app/controllers/SignUpController.scala @@ -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 @@ -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)) diff --git a/app/models/DateModel.scala b/app/models/DateModel.scala index 32dc327d..41b66080 100644 --- a/app/models/DateModel.scala +++ b/app/models/DateModel.scala @@ -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) diff --git a/app/models/frontend/IncomeSourceType.scala b/app/models/frontend/IncomeSourceType.scala index a064f3c1..69064524 100644 --- a/app/models/frontend/IncomeSourceType.scala +++ b/app/models/frontend/IncomeSourceType.scala @@ -16,6 +16,8 @@ package models.frontend +import scala.language.implicitConversions + sealed trait IncomeSourceType case object Business extends IncomeSourceType diff --git a/app/models/subscription/business/AccountingMethodModel.scala b/app/models/subscription/business/AccountingMethodModel.scala index cd7da73d..bfd5ca67 100644 --- a/app/models/subscription/business/AccountingMethodModel.scala +++ b/app/models/subscription/business/AccountingMethodModel.scala @@ -18,6 +18,8 @@ package models.subscription.business import play.api.libs.json._ +import scala.language.implicitConversions + sealed trait AccountingMethod { val stringValue: String @@ -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) diff --git a/app/utils/JsonUtils.scala b/app/utils/JsonUtils.scala index db6050da..5ab82dab 100644 --- a/app/utils/JsonUtils.scala +++ b/app/utils/JsonUtils.scala @@ -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) diff --git a/build.sbt b/build.sbt index c2500e51..b94f1b25 100644 --- a/build.sbt +++ b/build.sbt @@ -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) diff --git a/it/test/connectors/SignUpConnectorISpec.scala b/it/test/connectors/SignUpConnectorISpec.scala deleted file mode 100644 index f95071dd..00000000 --- a/it/test/connectors/SignUpConnectorISpec.scala +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2020 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 connectors - -import config.MicroserviceAppConfig -import helpers.ComponentSpecBase -import helpers.IntegrationTestConstants._ -import helpers.servicemocks.SignUpStub -import models.{ErrorModel, SignUpResponse} -import play.api.http.Status._ -import play.api.mvc.Request -import play.api.test.FakeRequest - -class SignUpConnectorISpec extends ComponentSpecBase { - - private lazy val signUpConnector: SignUpConnector = app.injector.instanceOf[SignUpConnector] - private lazy val appConfig: MicroserviceAppConfig = app.injector.instanceOf[MicroserviceAppConfig] - implicit val request: Request[_] = FakeRequest() - - "The sign up connector" when { - - "receiving a 200 response" should { - - "return a valid MTDBSA number when valid json is found" in { - SignUpStub.stubSignUp(testNino, testSignUpSubmission(testNino), appConfig.desAuthorisationToken, appConfig.desEnvironment)( - OK, testSignUpSuccessBody - ) - - val result = signUpConnector.signUp(testNino) - - result.futureValue shouldBe Right(SignUpResponse("XQIT00000000001")) - } - - "return a Json parse failure when invalid json is found" in { - SignUpStub.stubSignUp(testNino, testSignUpSubmission(testNino), appConfig.desAuthorisationToken, appConfig.desEnvironment)( - OK, testSignUpInvalidBody - ) - - val result = signUpConnector.signUp(testNino) - - result.futureValue shouldBe Left(ErrorModel(status = 200, "Failed to read Json for MTD Sign Up Response")) - } - } - - "receiving a non-200 response" should { - - "return the status and error received" in { - SignUpStub.stubSignUp(testNino, testSignUpSubmission(testNino), appConfig.desAuthorisationToken, appConfig.desEnvironment)( - INTERNAL_SERVER_ERROR, failureResponse("code", "reason") - ) - - val result = signUpConnector.signUp(testNino) - - result.futureValue shouldBe Left(ErrorModel(INTERNAL_SERVER_ERROR, """{"code":"code","reason":"reason"}""")) - } - } - } -} diff --git a/it/test/controllers/SignUpControllerISpec.scala b/it/test/controllers/SignUpControllerISpec.scala index 986478c4..771cc39e 100644 --- a/it/test/controllers/SignUpControllerISpec.scala +++ b/it/test/controllers/SignUpControllerISpec.scala @@ -17,14 +17,13 @@ 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 { @@ -32,30 +31,9 @@ class SignUpControllerISpec extends ComponentSpecBase with FeatureSwitching { 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), @@ -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) @@ -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) diff --git a/it/test/helpers/IntegrationTestConstants.scala b/it/test/helpers/IntegrationTestConstants.scala index 85325177..e4ebe4e7 100644 --- a/it/test/helpers/IntegrationTestConstants.scala +++ b/it/test/helpers/IntegrationTestConstants.scala @@ -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 diff --git a/it/test/helpers/servicemocks/SignUpStub.scala b/it/test/helpers/servicemocks/SignUpStub.scala deleted file mode 100644 index 88ec5640..00000000 --- a/it/test/helpers/servicemocks/SignUpStub.scala +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2020 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 helpers.servicemocks - -import com.github.tomakehurst.wiremock.stubbing.StubMapping -import play.api.libs.json.JsValue - -object SignUpStub extends WireMockMethods { - - private def signUpUri(nino: String): String = s"/income-tax/sign-up/ITSA" - - def stubSignUp(nino: String, expectedBody: JsValue, authorizationHeader: String, environmentHeader: String) - (status: Int, body: JsValue): StubMapping = { - when( - method = POST, - uri = signUpUri(nino), - body = expectedBody, - headers = Map[String, String]( - "Authorization" -> authorizationHeader, - "Environment" -> environmentHeader - ) - ).thenReturn(status, body) - - } -} diff --git a/test/connectors/SignUpConnectorSpec.scala b/test/connectors/SignUpConnectorSpec.scala deleted file mode 100644 index 5489d96b..00000000 --- a/test/connectors/SignUpConnectorSpec.scala +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright 2023 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 connectors - -import common.CommonSpec -import config.AppConfig -import connectors.mocks.MockHttp -import models.{ErrorModel, SignUpResponse} -import org.mockito.ArgumentMatchers -import org.mockito.Mockito._ -import org.scalatestplus.play.guice.GuiceOneAppPerSuite -import parsers.SignUpParser._ -import play.api.http.Status._ -import play.api.libs.json.JsValue -import play.api.mvc.Request -import play.api.test.FakeRequest -import play.api.test.Helpers.{await, defaultAwaitTimeout} -import uk.gov.hmrc.http.{HeaderCarrier, HeaderNames} - -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.Future - -class SignUpConnectorSpec extends CommonSpec with MockHttp with GuiceOneAppPerSuite { - - class Test(nino: String, response: PostSignUpResponse) { - val appConfig: AppConfig = app.injector.instanceOf[AppConfig] - val connector = new SignUpConnector(mockHttpClient, appConfig) - val headers: Seq[(String, String)] = Seq( - HeaderNames.authorisation -> appConfig.desAuthorisationToken, - appConfig.desEnvironmentHeader - ) - - when(mockHttpClient.POST[JsValue, PostSignUpResponse]( - ArgumentMatchers.eq(s"${appConfig.desURL}/income-tax/sign-up/ITSA"), - ArgumentMatchers.eq(connector.requestBody(nino)), - ArgumentMatchers.eq(headers) - )(ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any(), ArgumentMatchers.any())) - .thenReturn(Future.successful(response)) - } - - implicit val hc: HeaderCarrier = HeaderCarrier() - implicit val request: Request[_] = FakeRequest() - - "Calling sign up" when { - - "a valid PostSignUpResponse is returned" should { - - "return a mtdbsa" in new Test("AA111111A", Right(SignUpResponse("XAIT000000"))) { - val result: PostSignUpResponse = await(connector.signUp("AA111111A")) - - result shouldBe Right(SignUpResponse("XAIT000000")) - } - } - - "a PostSignUpFailure is returned" should { - - "return a sign up failure with the correct status and message" in new Test("AA111111A", Left(ErrorModel(INTERNAL_SERVER_ERROR, "Failure"))) { - val result: PostSignUpResponse = await(connector.signUp("AA111111A")) - - result shouldBe Left(ErrorModel(INTERNAL_SERVER_ERROR, "Failure")) - } - } - } -} diff --git a/test/controllers/SignUpControllerSpec.scala b/test/controllers/SignUpControllerSpec.scala index 2ed959b9..0ea7ad5b 100644 --- a/test/controllers/SignUpControllerSpec.scala +++ b/test/controllers/SignUpControllerSpec.scala @@ -19,121 +19,83 @@ package controllers import common.CommonSpec import config.MicroserviceAppConfig -import config.featureswitch.{FeatureSwitching, TaxYearSignup} +import config.featureswitch.FeatureSwitching import models.monitoring.{RegistrationFailureAudit, RegistrationSuccessAudit} import models.{ErrorModel, SignUpResponse} import play.api.Configuration import play.api.http.Status.{INTERNAL_SERVER_ERROR, OK} import play.api.libs.json.Json +import play.api.mvc.{ControllerComponents, Result} import play.api.test.FakeRequest import play.api.test.Helpers.{contentAsJson, contentAsString, defaultAwaitTimeout, status, stubControllerComponents} import services.mocks.monitoring.MockAuditService -import services.mocks.{MockAuthService, MockSignUpConnector, MockSignUpTaxYearConnector} +import services.mocks.{MockAuthService, MockSignUpTaxYearConnector} import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier, Enrolments} import utils.MaterializerSupport -import utils.TestConstants.{hmrcAsAgent, testNino, testSignUpSubmission, testTaxYear, testTaxYearSignUpSubmission} +import utils.TestConstants.{hmrcAsAgent, testNino, testTaxYear, testTaxYearSignUpSubmission} import scala.concurrent.ExecutionContext.Implicits.global import scala.concurrent.Future -class SignUpControllerSpec extends CommonSpec with MockAuthService with MockSignUpConnector with MockSignUpTaxYearConnector with MaterializerSupport with MockAuditService with FeatureSwitching { - lazy val mockCC = stubControllerComponents() +class SignUpControllerSpec extends CommonSpec + with MockAuthService + with MockSignUpTaxYearConnector + with MaterializerSupport + with MockAuditService + with FeatureSwitching { + + lazy val mockCC: ControllerComponents = stubControllerComponents() private lazy val configuration: Configuration = app.injector.instanceOf[Configuration] - lazy val mockappConfig: MicroserviceAppConfig = app.injector.instanceOf[MicroserviceAppConfig] + lazy val mockAppConfig: MicroserviceAppConfig = app.injector.instanceOf[MicroserviceAppConfig] - object TestController extends SignUpController ( + object TestController extends SignUpController( mockAuthService, mockAuditService, configuration, - mockSignUpConnector, mockSignUpTaxYearConnector, mockCC, - mockappConfig + mockAppConfig ) - override def beforeEach(): Unit = { - disable(TaxYearSignup) - super.beforeEach() - } - + "SignUpController" should { + "return OK with the sign up successful response" when { + "sign up was successful" when { + "an individual signs themselves up" in { + val fakeRequest = FakeRequest().withJsonBody(Json.toJson(testTaxYearSignUpSubmission(testNino, testTaxYear))) - "Sign Up Controller" when { - "signup is submitted" should { - "return a 200 response" in { - val fakeRequest = FakeRequest().withJsonBody(Json.toJson(testSignUpSubmission(testNino))) - - mockRetrievalSuccess(Enrolments(Set(Enrolment(hmrcAsAgent, Seq(EnrolmentIdentifier("AgentReferenceNumber", "123456789")), "Activated")))) - signUp(testNino)(Future.successful(Right(SignUpResponse("XAIT000000"))))() + mockRetrievalSuccess(Enrolments(Set())) + signUpTaxYear(testNino, testTaxYear)(Future.successful(Right(SignUpResponse("XAIT000000")))) + val result: Future[Result] = TestController.signUp(testNino, testTaxYear)(fakeRequest) - val result = TestController.signUp(testNino, testTaxYear)(fakeRequest) - status(result) shouldBe OK - contentAsJson(result).as[SignUpResponse].mtdbsa shouldBe { - "XAIT000000" + status(result) shouldBe OK + contentAsJson(result) shouldBe Json.obj( + "mtdbsa" -> "XAIT000000" + ) + verifyAudit(RegistrationSuccessAudit(None, testNino, "XAIT000000", "Bearer dev", None)) } - verifyAudit(RegistrationSuccessAudit(Some("123456789"), testNino, "XAIT000000", "Bearer dev", None)) - } - - } - "feature switch TaxYearSignup is enabled" should { - "return a 200 response" in { - enable(TaxYearSignup) - val fakeRequest = FakeRequest().withJsonBody(Json.toJson(testTaxYearSignUpSubmission(testNino, testTaxYear))) + "an agent signs up their client" in { + val fakeRequest = FakeRequest().withJsonBody(Json.toJson(testTaxYearSignUpSubmission(testNino, testTaxYear))) - mockRetrievalSuccess(Enrolments(Set(Enrolment(hmrcAsAgent, Seq(EnrolmentIdentifier("AgentReferenceNumber", "123456789")), "Activated")))) - signUpTaxYear(testNino, testTaxYear)(Future.successful(Right(SignUpResponse("XAIT000000"))))() + mockRetrievalSuccess(Enrolments(Set(Enrolment(hmrcAsAgent, Seq(EnrolmentIdentifier("AgentReferenceNumber", "123456789")), "Activated")))) + signUpTaxYear(testNino, testTaxYear)(Future.successful(Right(SignUpResponse("XAIT000000")))) + val result: Future[Result] = TestController.signUp(testNino, testTaxYear)(fakeRequest) - val result = TestController.signUp(testNino, testTaxYear)(fakeRequest) - status(result) shouldBe OK - contentAsJson(result).as[SignUpResponse].mtdbsa shouldBe { - "XAIT000000" + status(result) shouldBe OK + contentAsJson(result) shouldBe Json.obj( + "mtdbsa" -> "XAIT000000" + ) + verifyAudit(RegistrationSuccessAudit(Some("123456789"), testNino, "XAIT000000", "Bearer dev", None)) } - verifyAudit(RegistrationSuccessAudit(Some("123456789"), testNino, "XAIT000000", "Bearer dev", None)) - } - - } - } - - "Sign Up Controller" when { - "signup is submitted" should { - "return a Json parse failure when invalid json is found" in { - val fakeRequest = FakeRequest().withJsonBody(Json.toJson(testSignUpSubmission(testNino))) - - mockRetrievalSuccess(Enrolments(Set(Enrolment(hmrcAsAgent, Seq(EnrolmentIdentifier("AgentReferenceNumber", "123456789")), "Activated")))) - - signUp(testNino)(Future.successful(Left(ErrorModel(OK, "Failed to read Json for MTD Sign Up Response"))))() - - val result = TestController.signUp(testNino, testTaxYear)(fakeRequest) - status(result) shouldBe INTERNAL_SERVER_ERROR - contentAsString(result) shouldBe "Failed Sign up" - verifyAudit(RegistrationFailureAudit(testNino, OK, "Failed to read Json for MTD Sign Up Response")) - } - } - } - - "return InternalServerError" when { - "signup is submitted" should { - "return an error" in { - val fakeRequest = FakeRequest().withJsonBody(Json.toJson(testSignUpSubmission(testNino))) - - mockRetrievalSuccess(Enrolments(Set(Enrolment(hmrcAsAgent, Seq(EnrolmentIdentifier("AgentReferenceNumber", "123456789")), "Activated")))) - signUp(testNino)(Future.successful(Left(ErrorModel(INTERNAL_SERVER_ERROR, "Failure"))))() - - val result = TestController.signUp(testNino, testTaxYear)(fakeRequest) - - status(result) shouldBe INTERNAL_SERVER_ERROR - contentAsString(result) shouldBe "Failed Sign up" - verifyAudit(RegistrationFailureAudit(testNino, INTERNAL_SERVER_ERROR, "Failure")) } } - "feature switch TaxYearSignup is enabled and signup is submitted" should { - "return an error" in { - enable(TaxYearSignup) + "return InternalServerError" when { + "sign up was unsuccessful and an error was returned" in { val fakeRequest = FakeRequest().withJsonBody(Json.toJson(testTaxYearSignUpSubmission(testNino, testTaxYear))) mockRetrievalSuccess(Enrolments(Set(Enrolment(hmrcAsAgent, Seq(EnrolmentIdentifier("AgentReferenceNumber", "123456789")), "Activated")))) - signUpTaxYear(testNino, testTaxYear)(Future.successful(Left(ErrorModel(INTERNAL_SERVER_ERROR, "Failure"))))() + signUpTaxYear(testNino, testTaxYear)(Future.successful(Left(ErrorModel(INTERNAL_SERVER_ERROR, "Failure")))) val result = TestController.signUp(testNino, testTaxYear)(fakeRequest) diff --git a/test/services/mocks/MockSignUpConnector.scala b/test/services/mocks/MockSignUpConnector.scala deleted file mode 100644 index f10e976f..00000000 --- a/test/services/mocks/MockSignUpConnector.scala +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2023 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 services.mocks - -import config.AppConfig -import connectors.SignUpConnector -import connectors.mocks.MockHttp -import org.mockito.ArgumentMatchers -import org.mockito.Mockito.{reset, when} -import org.scalatest.Suite -import org.scalatestplus.play.guice.GuiceOneAppPerSuite -import parsers.SignUpParser.PostSignUpResponse - -import scala.concurrent.ExecutionContext.Implicits.global -import scala.concurrent.Future - -trait MockSignUpConnector extends MockHttp with GuiceOneAppPerSuite { - this: Suite => - - override def beforeEach(): Unit = { - super.beforeEach() - reset(mockSignUpConnector) - } - - val mockSignUpConnector: SignUpConnector = mock[SignUpConnector] - val appConfig: AppConfig = app.injector.instanceOf[AppConfig] - val connector = new SignUpConnector(mockHttpClient, appConfig) - - - def signUp(nino: String)(response: Future[PostSignUpResponse])(): Unit = { - when(mockSignUpConnector.signUp(ArgumentMatchers.eq(nino))(ArgumentMatchers.any())).thenReturn(response) - } -} diff --git a/test/services/mocks/MockSignUpTaxYearConnector.scala b/test/services/mocks/MockSignUpTaxYearConnector.scala index 34050723..637c7556 100644 --- a/test/services/mocks/MockSignUpTaxYearConnector.scala +++ b/test/services/mocks/MockSignUpTaxYearConnector.scala @@ -37,11 +37,11 @@ trait MockSignUpTaxYearConnector extends MockHttp with GuiceOneAppPerSuite { } val mockSignUpTaxYearConnector: SignUpTaxYearConnector = mock[SignUpTaxYearConnector] - val appConfigTaxYear: AppConfig = app.injector.instanceOf[AppConfig] - val connectorTaxYear = new SignUpTaxYearConnector(mockHttpClient, appConfigTaxYear) + val appConfig: AppConfig = app.injector.instanceOf[AppConfig] + val connectorTaxYear = new SignUpTaxYearConnector(mockHttpClient, appConfig) - def signUpTaxYear(nino: String, taxYear: String)(response: Future[PostSignUpResponse])(): Unit = { - when(mockSignUpTaxYearConnector.signUp(ArgumentMatchers.eq(nino ),ArgumentMatchers.eq(taxYear))(ArgumentMatchers.any())).thenReturn(response) + def signUpTaxYear(nino: String, taxYear: String)(response: Future[PostSignUpResponse]): Unit = { + when(mockSignUpTaxYearConnector.signUp(ArgumentMatchers.eq(nino), ArgumentMatchers.eq(taxYear))(ArgumentMatchers.any())).thenReturn(response) } }