From a0e9af2576caf877aae60f918951c9a78e85413d Mon Sep 17 00:00:00 2001 From: Luke Jones <47660116+BetaDraconis@users.noreply.github.com> Date: Thu, 12 Aug 2021 09:37:30 +0100 Subject: [PATCH] MTDSA-9603: Marriage Allowance feature switching (#68) * MTDSA-9603: Add feature switching for marriage allowance. * Delete sbt.json --- .gitignore | 3 +- app/config/FeatureSwitch.scala | 5 ++ app/routing/VersionRoutingMap.scala | 15 +++- .../CreateMarriageAllowanceController.scala | 1 - conf/application.conf | 4 + conf/v1.routes | 5 +- conf/v1WithMarriageAllowance.routes | 5 ++ it/routing/LiveRoutesISpec.scala | 85 +++++++++++++++++++ it/support/IntegrationBaseSpec.scala | 2 +- 9 files changed, 116 insertions(+), 9 deletions(-) create mode 100644 conf/v1WithMarriageAllowance.routes create mode 100644 it/routing/LiveRoutesISpec.scala diff --git a/.gitignore b/.gitignore index b897afb..ddfbccd 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,5 @@ npm-debug.log yarn-debug.log yarn-error.log ./bsp -./bsp/sbt.json \ No newline at end of file +./bsp/sbt.json +/.bsp/ diff --git a/app/config/FeatureSwitch.scala b/app/config/FeatureSwitch.scala index 0273c20..e14c018 100644 --- a/app/config/FeatureSwitch.scala +++ b/app/config/FeatureSwitch.scala @@ -37,4 +37,9 @@ case class FeatureSwitch(value: Option[Configuration]) { enabled.getOrElse(false) } + + def isMarriageAllowanceRoutingEnabled: Boolean = value match { + case Some(config) => config.getOptional[Boolean] ("marriage-allowance.enabled").getOrElse(true) + case None => true + } } diff --git a/app/routing/VersionRoutingMap.scala b/app/routing/VersionRoutingMap.scala index dc18bb2..0d9c241 100644 --- a/app/routing/VersionRoutingMap.scala +++ b/app/routing/VersionRoutingMap.scala @@ -17,9 +17,13 @@ package routing import com.google.inject.ImplementedBy +import config.{AppConfig, FeatureSwitch} import definition.Versions.VERSION_1 +import play.api.Logger + import javax.inject.Inject import play.api.routing.Router +import utils.Logging // So that we can have API-independent implementations of // VersionRoutingRequestHandler and VersionRoutingRequestHandlerSpec @@ -34,9 +38,16 @@ trait VersionRoutingMap { } // Add routes corresponding to available versions... -case class VersionRoutingMapImpl @Inject()(defaultRouter: Router, v1Router: v1.Routes) extends VersionRoutingMap { +case class VersionRoutingMapImpl @Inject()(appConfig: AppConfig, + defaultRouter: Router, + v1Router: v1.Routes, + v1RouterWithMarriageAllowance: v1WithMarriageAllowance.Routes) extends VersionRoutingMap with Logging{ + + val featureSwitch: FeatureSwitch = FeatureSwitch(appConfig.featureSwitch) val map: Map[String, Router] = Map( - VERSION_1 -> v1Router + VERSION_1 -> { + if (featureSwitch.isMarriageAllowanceRoutingEnabled) v1RouterWithMarriageAllowance else v1Router + } ) } diff --git a/app/v1/controllers/CreateMarriageAllowanceController.scala b/app/v1/controllers/CreateMarriageAllowanceController.scala index 03cb023..eff938e 100644 --- a/app/v1/controllers/CreateMarriageAllowanceController.scala +++ b/app/v1/controllers/CreateMarriageAllowanceController.scala @@ -18,7 +18,6 @@ package v1.controllers import cats.data.EitherT import cats.implicits._ -import config.AppConfig import javax.inject.Inject import play.api.libs.json.{JsValue, Json} import play.api.mvc.{Action, AnyContentAsJson, ControllerComponents} diff --git a/conf/application.conf b/conf/application.conf index 9935f52..5c92ef3 100644 --- a/conf/application.conf +++ b/conf/application.conf @@ -140,6 +140,10 @@ feature-switch { version-1 { enabled = true } + + marriage-allowance { + enabled = true + } } microservice { diff --git a/conf/v1.routes b/conf/v1.routes index 80220bc..eb26aae 100644 --- a/conf/v1.routes +++ b/conf/v1.routes @@ -1,6 +1,3 @@ -POST /marriage-allowance/:nino v1.controllers.CreateMarriageAllowanceController.createMarriageAllowance(nino: String) - PUT /:nino/:taxYear v1.controllers.AmendDisclosuresController.amendDisclosures(nino: String, taxYear: String) - -DELETE /:nino/:taxYear v1.controllers.DeleteDisclosuresController.deleteDisclosures(nino: String, taxYear: String) GET /:nino/:taxYear v1.controllers.RetrieveDisclosuresController.retrieveDisclosures(nino: String, taxYear: String) +DELETE /:nino/:taxYear v1.controllers.DeleteDisclosuresController.deleteDisclosures(nino: String, taxYear: String) \ No newline at end of file diff --git a/conf/v1WithMarriageAllowance.routes b/conf/v1WithMarriageAllowance.routes new file mode 100644 index 0000000..f8f71ef --- /dev/null +++ b/conf/v1WithMarriageAllowance.routes @@ -0,0 +1,5 @@ +POST /marriage-allowance/:nino v1.controllers.CreateMarriageAllowanceController.createMarriageAllowance(nino: String) + +PUT /:nino/:taxYear v1.controllers.AmendDisclosuresController.amendDisclosures(nino: String, taxYear: String) +GET /:nino/:taxYear v1.controllers.RetrieveDisclosuresController.retrieveDisclosures(nino: String, taxYear: String) +DELETE /:nino/:taxYear v1.controllers.DeleteDisclosuresController.deleteDisclosures(nino: String, taxYear: String) \ No newline at end of file diff --git a/it/routing/LiveRoutesISpec.scala b/it/routing/LiveRoutesISpec.scala new file mode 100644 index 0000000..1527dac --- /dev/null +++ b/it/routing/LiveRoutesISpec.scala @@ -0,0 +1,85 @@ +/* + * Copyright 2021 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 routing + +import com.github.tomakehurst.wiremock.stubbing.StubMapping +import play.api.http.HeaderNames.ACCEPT +import play.api.http.Status._ +import play.api.libs.json.{JsValue, Json} +import play.api.libs.ws.{WSRequest, WSResponse} +import support.IntegrationBaseSpec +import v1.models.errors.NotFoundError +import v1.stubs.{AuditStub, AuthStub, MtdIdLookupStub} + +class LiveRoutesISpec extends IntegrationBaseSpec { + + override def servicesConfig: Map[String, Any] = Map( + "microservice.services.des.host" -> mockHost, + "microservice.services.des.port" -> mockPort, + "microservice.services.ifs.host" -> mockHost, + "microservice.services.ifs.port" -> mockPort, + "microservice.services.mtd-id-lookup.host" -> mockHost, + "microservice.services.mtd-id-lookup.port" -> mockPort, + "microservice.services.auth.host" -> mockHost, + "microservice.services.auth.port" -> mockPort, + "auditing.consumer.baseUri.port" -> mockPort, + "minimumPermittedTaxYear" -> 2020, + "feature-switch.marriage-allowance.enabled" -> false, + ) + + private trait Test { + val nino: String = "AA111111A" + + val requestBodyJson: JsValue = Json.parse( + s""" + |{ + | "spouseOrCivilPartnerNino": "AA123456A", + | "spouseOrCivilPartnerFirstName": "John", + | "spouseOrCivilPartnerSurname": "Smith", + | "spouseOrCivilPartnerDateOfBirth": "1986-04-06" + |} + """.stripMargin + ) + + def uri: String = s"/marriage-allowance/$nino" + + def setupStubs(): StubMapping + + def request(uri: String): WSRequest = { + setupStubs() + buildRequest(uri) + .withHttpHeaders((ACCEPT, "application/vnd.hmrc.1.0+json")) + } + } + + "Calling the 'create marriage allowance' endpoint (switched on in production)" should { + "return a 404 status code" when { + "the feature switch is turned off to point to live routes only" in new Test { + + override def setupStubs(): StubMapping = { + AuditStub.audit() + AuthStub.authorised() + MtdIdLookupStub.ninoFound(nino) + } + + val response: WSResponse = await(request(uri).post(requestBodyJson)) + response.body shouldBe Json.toJson(NotFoundError).toString() + response.status shouldBe NOT_FOUND + } + } + } +} \ No newline at end of file diff --git a/it/support/IntegrationBaseSpec.scala b/it/support/IntegrationBaseSpec.scala index b830b89..bbc9c4c 100644 --- a/it/support/IntegrationBaseSpec.scala +++ b/it/support/IntegrationBaseSpec.scala @@ -31,7 +31,7 @@ trait IntegrationBaseSpec extends UnitSpec with WireMockHelper with GuiceOneServ lazy val client: WSClient = app.injector.instanceOf[WSClient] - def servicesConfig: Map[String, String] = Map( + def servicesConfig: Map[String, Any] = Map( "microservice.services.des.host" -> mockHost, "microservice.services.des.port" -> mockPort, "microservice.services.mtd-id-lookup.host" -> mockHost,