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 eef4265a..8b2e8dd2 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 @@ -293,7 +293,7 @@ final case class ProcessApiServiceImpl( } yield eServiceDoc.toApi onComplete(result) { - getEServiceByIdResponse[EServiceDoc](operationLabel)(getEServiceDocumentById200) + getEServiceDocumentByIdResponse[EServiceDoc](operationLabel)(getEServiceDocumentById200) } } 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 a6dc5bdf..5839eb8e 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 @@ -17,9 +17,9 @@ 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: DescriptorDocumentNotFound) => notFound(ex, logMessage) - case Failure(ex) => internalServerError(ex, logMessage) + case Success(s) => success(s) + case Failure(ex: EServiceNotFound) => notFound(ex, logMessage) + case Failure(ex) => internalServerError(ex, logMessage) } def getEServiceConsumersResponse[T](logMessage: String)( diff --git a/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala b/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala index 6752f13b..613f6e8a 100644 --- a/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala +++ b/src/test/scala/it/pagopa/interop/catalogprocess/CatalogProcessSpec.scala @@ -30,7 +30,45 @@ import scala.concurrent.{Future, ExecutionContext} class CatalogProcessSpec extends SpecHelper with AnyWordSpecLike with ScalatestRouteTest { - "EService retrieve" should { + "Eservice retrieve" should { + "succeed when found" in { + val eServiceId = UUID.randomUUID() + val requesterId = UUID.randomUUID() + + implicit val context: Seq[(String, String)] = + Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + + (mockCatalogManagementService + .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) + .expects(eServiceId, *, *) + .once() + .returns(Future.successful(SpecData.catalogItem)) + + Get() ~> service.getEServiceById(eServiceId.toString) ~> check { + status shouldEqual StatusCodes.OK + } + } + + "fail with 404 when not found" in { + val eServiceId = UUID.randomUUID() + val requesterId = UUID.randomUUID() + + implicit val context: Seq[(String, String)] = + Seq("bearer" -> bearerToken, USER_ROLES -> "admin", ORGANIZATION_ID_CLAIM -> requesterId.toString) + + (mockCatalogManagementService + .getEServiceById(_: UUID)(_: ExecutionContext, _: ReadModelService)) + .expects(eServiceId, *, *) + .once() + .returns(Future.failed(EServiceNotFound(eServiceId.toString))) + + Get() ~> service.getEServiceById(eServiceId.toString) ~> check { + status shouldEqual StatusCodes.NotFound + } + } + } + + "EServices retrieve" should { "succeed when Agreement States are empty" in {