diff --git a/src/main/scala/it/pagopa/interop/catalogprocess/api/impl/ProcessApiServiceImpl.scala b/src/main/scala/it/pagopa/interop/catalogprocess/api/impl/ProcessApiServiceImpl.scala index 00d6a414..50674fe9 100644 --- a/src/main/scala/it/pagopa/interop/catalogprocess/api/impl/ProcessApiServiceImpl.scala +++ b/src/main/scala/it/pagopa/interop/catalogprocess/api/impl/ProcessApiServiceImpl.scala @@ -734,6 +734,7 @@ final case class ProcessApiServiceImpl( riskAnalysisUuid <- riskAnalysisId.toFutureUUID catalogItem <- catalogManagementService.getEServiceById(eServiceUuid) _ <- isDraftEService(catalogItem) + _ <- isReceiveEService(catalogItem) _ <- catalogManagementService.deleteRiskAnalysis(eServiceUuid, riskAnalysisUuid) } yield () diff --git a/src/main/scala/it/pagopa/interop/catalogprocess/api/impl/ResponseHandlers.scala b/src/main/scala/it/pagopa/interop/catalogprocess/api/impl/ResponseHandlers.scala index 05eeb512..e465e150 100644 --- a/src/main/scala/it/pagopa/interop/catalogprocess/api/impl/ResponseHandlers.scala +++ b/src/main/scala/it/pagopa/interop/catalogprocess/api/impl/ResponseHandlers.scala @@ -87,6 +87,7 @@ object ResponseHandlers extends AkkaResponses { case Failure(ex: EServiceNotFound) => notFound(ex, logMessage) case Failure(ex: EServiceRiskAnalysisNotFound) => notFound(ex, logMessage) case Failure(ex: EServiceNotInDraftState) => badRequest(ex, logMessage) + case Failure(ex: EServiceNotInReceiveMode) => badRequest(ex, logMessage) case Failure(ex) => internalServerError(ex, logMessage) } diff --git a/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala b/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala index 8a5f1bb3..3a1484e8 100644 --- a/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala +++ b/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala @@ -3129,5 +3129,29 @@ class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestR problem.errors.head.code shouldBe "009-0012" } } + "fail if EService is not Receive" in { + val requesterId = UUID.randomUUID() + + implicit val context: Seq[(String, String)] = + Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + + val descriptor = + SpecData.catalogDescriptor.copy(state = Draft) + + val eService = SpecData.catalogItem.copy(descriptors = Seq(descriptor), producerId = requesterId, mode = Deliver) + + (mockCatalogManagementService + .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) + .expects(eService.id, *, *) + .once() + .returns(Future.successful(eService)) + + Post() ~> service.deleteRiskAnalysis(eService.id.toString, UUID.randomUUID().toString) ~> check { + status shouldEqual StatusCodes.BadRequest + val problem = responseAs[Problem] + problem.status shouldBe StatusCodes.BadRequest.intValue + problem.errors.head.code shouldBe "009-0013" + } + } } }