diff --git a/app/uk/gov/hmrc/usermanagement/testonly/IntegrationTestSupportController.scala b/app/uk/gov/hmrc/usermanagement/testonly/IntegrationTestSupportController.scala new file mode 100644 index 0000000..b8b8022 --- /dev/null +++ b/app/uk/gov/hmrc/usermanagement/testonly/IntegrationTestSupportController.scala @@ -0,0 +1,46 @@ +/* + * Copyright 2024 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 uk.gov.hmrc.usermanagement.testonly + +import play.api.libs.json.{JsError, OFormat, Reads} +import play.api.mvc.{Action, AnyContent, BodyParser, ControllerComponents} +import uk.gov.hmrc.play.bootstrap.backend.controller.BackendController +import uk.gov.hmrc.usermanagement.model.Team +import uk.gov.hmrc.usermanagement.persistence.TeamsRepository +import org.mongodb.scala.bson.Document + +import javax.inject.Inject +import scala.concurrent.ExecutionContext + +class IntegrationTestSupportController @Inject()( + teamsRepository: TeamsRepository, + cc : ControllerComponents)(implicit + ec : ExecutionContext) extends BackendController(cc) { + + private def validateJson[A: Reads]: BodyParser[A] = + parse.json.validate(_.validate[A].asEither.left.map(e => BadRequest(JsError.toJson(e)))) + + implicit val tf: OFormat[Team] = Team.format + def addTeams(): Action[Seq[Team]] = Action.async(validateJson[Seq[Team]]) { implicit request => + teamsRepository.putAll(request.body).map(_ => Ok("Ok")) + } + + def deleteTeams(): Action[AnyContent] = Action.async { + teamsRepository.collection.deleteMany(Document()).toFuture().map(_ => Ok("Ok")) + } + +} diff --git a/conf/testOnlyDoNotUseInAppConf.routes b/conf/testOnlyDoNotUseInAppConf.routes index b98c783..c2a0ec1 100755 --- a/conf/testOnlyDoNotUseInAppConf.routes +++ b/conf/testOnlyDoNotUseInAppConf.routes @@ -10,4 +10,7 @@ # Failing to follow this rule may result in test routes deployed in production. # Add all the application routes to the prod.routes file --> / prod.Routes + +POST /test-only/teams @uk.gov.hmrc.usermanagement.testonly.IntegrationTestSupportController.addTeams() +DELETE /test-only/teams @uk.gov.hmrc.usermanagement.testonly.IntegrationTestSupportController.deleteTeams() +-> / prod.Routes diff --git a/project/plugins.sbt b/project/plugins.sbt index 78ce7f1..c5ed76a 100755 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -2,7 +2,7 @@ resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefac resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns) resolvers += Resolver.typesafeRepo("releases") -addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.17.0") -addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.4.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.20.0") +addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0") addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.0") addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")