Skip to content

Commit

Permalink
MTDSA-9603: Marriage Allowance feature switching (#68)
Browse files Browse the repository at this point in the history
* MTDSA-9603: Add feature switching for marriage allowance.

* Delete sbt.json
  • Loading branch information
BetaDraconis authored Aug 12, 2021
1 parent ddfa366 commit a0e9af2
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ npm-debug.log
yarn-debug.log
yarn-error.log
./bsp
./bsp/sbt.json
./bsp/sbt.json
/.bsp/
5 changes: 5 additions & 0 deletions app/config/FeatureSwitch.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
15 changes: 13 additions & 2 deletions app/routing/VersionRoutingMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
)
}
1 change: 0 additions & 1 deletion app/v1/controllers/CreateMarriageAllowanceController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ feature-switch {
version-1 {
enabled = true
}

marriage-allowance {
enabled = true
}
}

microservice {
Expand Down
5 changes: 1 addition & 4 deletions conf/v1.routes
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions conf/v1WithMarriageAllowance.routes
Original file line number Diff line number Diff line change
@@ -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)
85 changes: 85 additions & 0 deletions it/routing/LiveRoutesISpec.scala
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
2 changes: 1 addition & 1 deletion it/support/IntegrationBaseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a0e9af2

Please sign in to comment.