Skip to content

Commit

Permalink
PIN-4667 BKE - Allowed to archive agreement only if it is in Active o…
Browse files Browse the repository at this point in the history
…r Suspended state
  • Loading branch information
nttdata-rtorsoli committed Mar 6, 2024
1 parent 84f1d66 commit 025ab9f
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1347,6 +1347,7 @@ final case class AgreementApiServiceImpl(
agreementUUID <- agreementId.toFutureUUID
agreement <- agreementManagementService.getAgreementById(agreementUUID)
_ <- assertRequesterIsConsumer(requesterOrgId, agreement)
_ <- agreement.assertArchivableState.toFuture
updated <- archive(agreement.toManagement)
_ <- archivingPurposesQueueService.send[ArchiveEvent](ArchiveEvent(updated.id, offsetDateTimeSupplier.get()))
_ <- archivingEservicesQueueService.send[ArchiveEvent](ArchiveEvent(updated.id, offsetDateTimeSupplier.get()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ object ResponseHandlers extends AkkaResponses {
success: T => Route
)(result: Try[T])(implicit contexts: Seq[(String, String)], logger: LoggerTakingImplicit[ContextFieldsToLog]): Route =
result match {
case Success(s) => success(s)
case Failure(ex: AgreementNotFound) => notFound(ex, logMessage)
case Failure(ex: OperationNotAllowed) => forbidden(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
case Success(s) => success(s)
case Failure(ex: AgreementNotFound) => notFound(ex, logMessage)
case Failure(ex: AgreementNotInExpectedState) => badRequest(ex, logMessage)
case Failure(ex: OperationNotAllowed) => forbidden(ex, logMessage)
case Failure(ex) => internalServerError(ex, logMessage)
}

def suspendAgreementResponse[T](logMessage: String)(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,53 @@ class AgreementArchiviationSpec extends AnyWordSpecLike with SpecHelper with Sca
status shouldEqual StatusCodes.NotFound
}
}
// case object Draft
// case object Pending
// case object Archived
// case object MissingCertifiedAttributes
// case object Rejected
"fail if agreement is in Pending state" in {
val agreement =
SpecData.agreement.copy(state = AgreementManagement.AgreementState.PENDING, consumerId = requesterOrgId)

mockAgreementRetrieve(agreement.toPersistent)

Get() ~> service.archiveAgreement(agreement.id.toString) ~> check {
status shouldEqual StatusCodes.BadRequest
}
}
"fail if agreement is in Draft state" in {
val agreement =
SpecData.agreement.copy(state = AgreementManagement.AgreementState.DRAFT, consumerId = requesterOrgId)

mockAgreementRetrieve(agreement.toPersistent)

Get() ~> service.archiveAgreement(agreement.id.toString) ~> check {
status shouldEqual StatusCodes.BadRequest
}
}
"fail if agreement is in MissingCertifiedAttributes state" in {
val agreement =
SpecData.agreement.copy(
state = AgreementManagement.AgreementState.MISSING_CERTIFIED_ATTRIBUTES,
consumerId = requesterOrgId
)

mockAgreementRetrieve(agreement.toPersistent)

Get() ~> service.archiveAgreement(agreement.id.toString) ~> check {
status shouldEqual StatusCodes.BadRequest
}
}
"fail if agreement is in Rejected state" in {
val agreement =
SpecData.agreement.copy(state = AgreementManagement.AgreementState.REJECTED, consumerId = requesterOrgId)

mockAgreementRetrieve(agreement.toPersistent)

Get() ~> service.archiveAgreement(agreement.id.toString) ~> check {
status shouldEqual StatusCodes.BadRequest
}
}
}
}

0 comments on commit 025ab9f

Please sign in to comment.