Skip to content

Commit

Permalink
Merge pull request #5 from hmrc/API-3473
Browse files Browse the repository at this point in the history
API-3473
  • Loading branch information
lburgos authored Oct 29, 2018
2 parents 4311279 + 56e22cc commit 2c853b3
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 10 deletions.
8 changes: 7 additions & 1 deletion app/uk/gov/hmrc/controllers/GatekeeperController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import play.api.libs.json.Json
import uk.gov.hmrc.connector.AuthConnector
import uk.gov.hmrc.controllers.ErrorCode._
import uk.gov.hmrc.models.JsonFormatters._
import uk.gov.hmrc.models.{AuthRole, Blocked, InvalidStateTransition}
import uk.gov.hmrc.models.{AuthRole, Blocked, InvalidStateTransition, Unblocked}
import uk.gov.hmrc.services.{ApplicationService, GatekeeperService}

import scala.concurrent.ExecutionContext.Implicits.global
Expand Down Expand Up @@ -79,6 +79,12 @@ class GatekeeperController @Inject()(val authConnector: AuthConnector, val appli
} recover recovery
}

def unblockApplication(id: UUID) = requiresRole(AuthRole.APIGatekeeper).async { implicit request =>
gatekeeperService.unblockApplication(id) map {
case Unblocked => Ok
} recover recovery
}

def fetchAppsForGatekeeper = requiresRole(AuthRole.APIGatekeeper).async {
gatekeeperService.fetchNonTestingAppsWithSubmittedDate() map {
apps => Ok(Json.toJson(apps))
Expand Down
3 changes: 2 additions & 1 deletion app/uk/gov/hmrc/models/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,5 @@ case object UpliftRejected extends ApplicationStateChange
case object UpliftVerified extends ApplicationStateChange
case object VerificationResent extends ApplicationStateChange
case object Deleted extends ApplicationStateChange
case object Blocked extends ApplicationStateChange
case object Blocked extends ApplicationStateChange
case object Unblocked extends ApplicationStateChange
11 changes: 11 additions & 0 deletions app/uk/gov/hmrc/services/GatekeeperService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ class GatekeeperService @Inject()(applicationRepository: ApplicationRepository,
} yield Blocked
}

def unblockApplication(applicationId: UUID)(implicit hc: HeaderCarrier): Future[ApplicationStateChange] = {
def unblock(application: ApplicationData): ApplicationData = {
application.copy(blocked = false)
}

for {
app <- fetchApp(applicationId)
_ <- applicationRepository.save(unblock(app))
} yield Unblocked
}


private def fetchApp(applicationId: UUID): Future[ApplicationData] = {
lazy val notFoundException = new NotFoundException(s"application not found for id: $applicationId")
Expand Down
1 change: 1 addition & 0 deletions conf/app.routes
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ POST /application/:id/reject-uplift @uk.gov.hmr
POST /application/:id/resend-verification @uk.gov.hmrc.controllers.GatekeeperController.resendVerification(id: java.util.UUID)
POST /application/:id/delete @uk.gov.hmrc.controllers.GatekeeperController.deleteApplication(id: java.util.UUID)
POST /application/:id/block @uk.gov.hmrc.controllers.GatekeeperController.blockApplication(id: java.util.UUID)
POST /application/:id/unblock @uk.gov.hmrc.controllers.GatekeeperController.unblockApplication(id: java.util.UUID)

POST /application/:id/rate-limit-tier @uk.gov.hmrc.controllers.ApplicationController.updateRateLimitTier(id: java.util.UUID)

Expand Down
25 changes: 19 additions & 6 deletions test/unit/controllers/GatekeeperControllerSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ package controllers

import java.util.UUID

import common.uk.gov.hmrc.common.LogSuppressing
import common.uk.gov.hmrc.testutils.ApplicationStateUtil
import org.apache.http.HttpStatus._
import org.joda.time.DateTime
import org.mockito.ArgumentCaptor
import org.mockito.Matchers.{any, anyString, eq => eqTo}
import org.mockito.Matchers.any
import org.mockito.Mockito._
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.mockito.MockitoSugar
Expand All @@ -32,20 +34,16 @@ import play.api.test.FakeRequest
import uk.gov.hmrc.connector.AuthConnector
import uk.gov.hmrc.controllers.ErrorCode._
import uk.gov.hmrc.controllers.{ErrorCode, _}
import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException}
import uk.gov.hmrc.models.ActorType._
import uk.gov.hmrc.models.JsonFormatters._
import uk.gov.hmrc.models.State._
import uk.gov.hmrc.models._
import uk.gov.hmrc.play.test.{UnitSpec, WithFakeApplication}
import uk.gov.hmrc.services.{ApplicationService, GatekeeperService}
import uk.gov.hmrc.time.DateTimeUtils
import common.uk.gov.hmrc.common.LogSuppressing
import common.uk.gov.hmrc.testutils.ApplicationStateUtil

import scala.concurrent.Future.{failed, successful}
import uk.gov.hmrc.http.{HeaderCarrier, NotFoundException}
import uk.gov.hmrc.models.AuthRole.APIGatekeeper
import uk.gov.hmrc.models.RateLimitTier.SILVER

class GatekeeperControllerSpec extends UnitSpec with ScalaFutures with MockitoSugar with WithFakeApplication
with ApplicationStateUtil with LogSuppressing {
Expand Down Expand Up @@ -353,6 +351,21 @@ class GatekeeperControllerSpec extends UnitSpec with ScalaFutures with MockitoSu
}
}

"unblockApplication" should {

val applicationId: UUID = UUID.randomUUID()

"unblock the application" in new Setup {

when(mockGatekeeperService.unblockApplication(any()) (any[HeaderCarrier]())).thenReturn(successful(Unblocked))

val result = await(underTest.unblockApplication(applicationId)(request))

status(result) shouldBe SC_OK
verify(mockGatekeeperService).unblockApplication(applicationId)
}
}

private def aHistory(appId: UUID, state: State = PENDING_GATEKEEPER_APPROVAL) = {
StateHistoryResponse(appId, state, Actor("anEmail", COLLABORATOR), None, DateTimeUtils.now)
}
Expand Down
21 changes: 19 additions & 2 deletions test/unit/services/GatekeeperServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@ import org.joda.time.DateTimeUtils
import org.mockito.ArgumentCaptor
import org.mockito.Matchers.{any, anyString, eq => eqTo}
import org.mockito.Mockito._
import org.apache.http.HttpStatus._
import org.mockito.invocation.InvocationOnMock
import org.mockito.stubbing.Answer
import org.scalatest.BeforeAndAfterAll
import org.scalatest.concurrent.ScalaFutures
import org.scalatest.mockito.MockitoSugar
import play.api.test.FakeRequest
import uk.gov.hmrc.config.AppContext
import uk.gov.hmrc.connector.{ApiSubscriptionFieldsConnector, EmailConnector, ThirdPartyDelegatedAuthorityConnector}
import uk.gov.hmrc.controllers.{DeleteApplicationRequest, RejectUpliftRequest}
Expand Down Expand Up @@ -485,4 +483,23 @@ class GatekeeperServiceSpec extends UnitSpec with ScalaFutures with MockitoSugar
verify(mockApplicationRepository).save(updatedApplication)
}
}

"unblockApplication" should {

val applicationId: UUID = UUID.randomUUID()
val applicationData = anApplicationData(applicationId).copy(blocked = true)
val updatedApplication = applicationData.copy(blocked = false)

"set the block flag to false for an application" in new Setup {

when(mockApplicationRepository.fetch(any())).thenReturn(successful(Option(applicationData)))
when(mockApplicationRepository.save(any())).thenReturn(successful(updatedApplication))

val result = await(underTest.unblockApplication(applicationId))
result shouldBe Unblocked

verify(mockApplicationRepository).fetch(applicationId)
verify(mockApplicationRepository).save(updatedApplication)
}
}
}

0 comments on commit 2c853b3

Please sign in to comment.