Skip to content

Commit

Permalink
Merge pull request #15 from hmrc/BDOG-2839
Browse files Browse the repository at this point in the history
BDOG-2839: add test-only route for adding Team data
  • Loading branch information
peteanning authored Feb 22, 2024
2 parents 7cbbc4b + c7ec861 commit ed05acd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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"))
}

}
5 changes: 4 additions & 1 deletion conf/testOnlyDoNotUseInAppConf.routes
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit ed05acd

Please sign in to comment.