Skip to content

Commit

Permalink
APIS-7042 Also decline submission when setting application back to TE…
Browse files Browse the repository at this point in the history
…STING (#491)

* APIS-7042 Also decline submission when setting application back to TESTING

* APIS-7042 Also decline submission when setting application back to TESTING
  • Loading branch information
petekirby-ee authored May 10, 2024
1 parent 4a1582d commit 084205f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import uk.gov.hmrc.mongo.lock.{LockRepository, LockService}
import uk.gov.hmrc.apiplatform.modules.common.domain.models.Actors
import uk.gov.hmrc.apiplatform.modules.common.services.{ApplicationLogger, ClockNow}
import uk.gov.hmrc.apiplatform.modules.applications.core.domain.models.{State, StateHistory}
import uk.gov.hmrc.apiplatform.modules.submissions.services.SubmissionsService
import uk.gov.hmrc.thirdpartyapplication.models.db.StoredApplication
import uk.gov.hmrc.thirdpartyapplication.repository.{ApplicationRepository, StateHistoryRepository}

Expand All @@ -36,6 +37,7 @@ class UpliftVerificationExpiryJob @Inject() (
upliftVerificationExpiryJobLockService: UpliftVerificationExpiryJobLockService,
applicationRepository: ApplicationRepository,
stateHistoryRepository: StateHistoryRepository,
submissionService: SubmissionsService,
val clock: Clock,
jobConfig: UpliftVerificationExpiryJobConfig
)(implicit val ec: ExecutionContext
Expand All @@ -61,6 +63,7 @@ class UpliftVerificationExpiryJob @Inject() (
Some(State.PENDING_REQUESTER_VERIFICATION),
changedAt = instant()
))
_ <- submissionService.declineSubmission(app.id, app.state.requestedByEmailAddress.getOrElse(""), "Automatically declined because requester did not verify")
} yield updatedApp
}

Expand Down
2 changes: 1 addition & 1 deletion project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object AppDependencies {
lazy val bootstrapVersion = "8.4.0"
lazy val hmrcMongoVersion = "1.7.0"
lazy val commonDomainVersion = "0.13.0"
lazy val applicationEventVersion = "0.49.0"
lazy val applicationEventVersion = "0.51.0"

private lazy val compileDeps = Seq(
"uk.gov.hmrc" %% "bootstrap-backend-play-30" % bootstrapVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import uk.gov.hmrc.mongo.test.MongoSupport
import uk.gov.hmrc.apiplatform.modules.common.domain.models.{Actors, ApplicationId, ClientId}
import uk.gov.hmrc.apiplatform.modules.applications.access.domain.models.Access
import uk.gov.hmrc.apiplatform.modules.applications.core.domain.models.{ApplicationState, State, StateHistory}
import uk.gov.hmrc.apiplatform.modules.submissions.SubmissionsTestData
import uk.gov.hmrc.apiplatform.modules.submissions.services.SubmissionsService
import uk.gov.hmrc.thirdpartyapplication.ApplicationStateUtil
import uk.gov.hmrc.thirdpartyapplication.models.db.{ApplicationTokens, StoredApplication, StoredToken}
import uk.gov.hmrc.thirdpartyapplication.repository.{ApplicationRepository, StateHistoryRepository}
Expand All @@ -49,9 +51,10 @@ class UpliftVerificationExpiryJobSpec
final val sixty = 60
final val twentyFour = 24

trait Setup {
trait Setup extends SubmissionsTestData {
val mockApplicationRepository: ApplicationRepository = mock[ApplicationRepository]
val mockStateHistoryRepository: StateHistoryRepository = mock[StateHistoryRepository]
val mockSubmissionsService: SubmissionsService = mock[SubmissionsService]
val mongoLockRepository: MongoLockRepository = app.injector.instanceOf[MongoLockRepository]
val lockKeeperSuccess: () => Boolean = () => true

Expand All @@ -69,20 +72,24 @@ class UpliftVerificationExpiryJobSpec
val config: UpliftVerificationExpiryJobConfig = UpliftVerificationExpiryJobConfig(initialDelay, interval, enabled = true, upliftVerificationValidity)

val underTest =
new UpliftVerificationExpiryJob(mockUpliftVerificationExpiryJobLockService, mockApplicationRepository, mockStateHistoryRepository, clock, config)
new UpliftVerificationExpiryJob(mockUpliftVerificationExpiryJobLockService, mockApplicationRepository, mockStateHistoryRepository, mockSubmissionsService, clock, config)
}

"uplift verification expiry job execution" should {

"expire all application uplifts having expiry date before the expiry time" in new Setup {
val app1: StoredApplication = anApplicationData(ApplicationId.random, ClientId("aaa"))
val app2: StoredApplication = anApplicationData(ApplicationId.random, ClientId("aaa"))
val app1: StoredApplication = anApplicationData(ApplicationId.random, ClientId("aaa"), pendingRequesterVerificationState("[email protected]"))
val app2: StoredApplication = anApplicationData(ApplicationId.random, ClientId("aaa"), pendingRequesterVerificationState("[email protected]"))

when(mockApplicationRepository.fetchAllByStatusDetails(refEq(State.PENDING_REQUESTER_VERIFICATION), any[Instant]))
.thenReturn(successful(List(app1, app2)))

when(mockApplicationRepository.save(*[StoredApplication]))
.thenAnswer((a: StoredApplication) => successful(a))
when(mockStateHistoryRepository.insert(*))
.thenAnswer((h: StateHistory) => successful(h))
when(mockSubmissionsService.declineSubmission(*[ApplicationId], *, *))
.thenReturn(successful(Some(aSubmission)))

await(underTest.execute)
verify(mockApplicationRepository).fetchAllByStatusDetails(State.PENDING_REQUESTER_VERIFICATION, instant.minus(JavaTimeDuration.ofDays(expiryTimeInDays)))
Expand All @@ -102,6 +109,16 @@ class UpliftVerificationExpiryJobSpec
Some(State.PENDING_REQUESTER_VERIFICATION),
changedAt = instant
))
verify(mockSubmissionsService).declineSubmission(
app1.id,
"[email protected]",
"Automatically declined because requester did not verify"
)
verify(mockSubmissionsService).declineSubmission(
app2.id,
"[email protected]",
"Automatically declined because requester did not verify"
)
}

"not execute if the job is already running" in new Setup {
Expand Down

0 comments on commit 084205f

Please sign in to comment.