From 6117a3cc00121c34a06fd680b1a0b4df4b188f49 Mon Sep 17 00:00:00 2001 From: Bassam Date: Thu, 27 Jun 2024 10:52:44 -0400 Subject: [PATCH] fix: Verification Policy Error Handling (#1228) Signed-off-by: Bassam Riman --- .../VerificationPolicyControllerImpl.scala | 52 +++--------------- .../model/error/VerificationPolicyError.scala | 15 +++-- .../VerificationPolicyRepository.scala | 18 +++--- .../service/VerificationPolicyService.scala | 8 ++- .../VerificationPolicyServiceImpl.scala | 44 +++++++++------ .../sql/model/db/VerificationPolicy.scala | 6 +- .../JdbcVerificationPolicyRepository.scala | 55 ++++++++++--------- ...VerificationPolicySqlIntegrationSpec.scala | 46 +++++----------- 8 files changed, 104 insertions(+), 140 deletions(-) diff --git a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/pollux/credentialschema/controller/VerificationPolicyControllerImpl.scala b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/pollux/credentialschema/controller/VerificationPolicyControllerImpl.scala index b5ba41e023..d1b189266a 100644 --- a/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/pollux/credentialschema/controller/VerificationPolicyControllerImpl.scala +++ b/cloud-agent/service/server/src/main/scala/org/hyperledger/identus/pollux/credentialschema/controller/VerificationPolicyControllerImpl.scala @@ -3,8 +3,6 @@ package org.hyperledger.identus.pollux.credentialschema.controller import org.hyperledger.identus.api.http.* import org.hyperledger.identus.api.http.model.{CollectionStats, Order, Pagination} import org.hyperledger.identus.pollux.core.model -import org.hyperledger.identus.pollux.core.model.error.VerificationPolicyError -import org.hyperledger.identus.pollux.core.model.error.VerificationPolicyError.* import org.hyperledger.identus.pollux.core.model.CredentialSchemaAndTrustedIssuersConstraint import org.hyperledger.identus.pollux.core.service.VerificationPolicyService import org.hyperledger.identus.pollux.credentialschema.http.{ @@ -18,21 +16,10 @@ import zio.* import zio.ZIO.* import java.util.UUID +import scala.language.implicitConversions class VerificationPolicyControllerImpl(service: VerificationPolicyService) extends VerificationPolicyController { - def verificationPolicyError2FailureResponse( - vpe: VerificationPolicyError - ): ErrorResponse = { - vpe match { - case RepositoryError(cause) => - ErrorResponse.internalServerError(detail = Option(cause.getMessage)) - case NotFoundError(id) => - ErrorResponse.notFound(detail = Option(s"VerificationPolicy is not found by $id")) - case UnexpectedError(cause) => - ErrorResponse.internalServerError(detail = Option(cause.getMessage)) - } - } override def createVerificationPolicy( ctx: RequestContext, in: VerificationPolicyInput @@ -54,26 +41,21 @@ class VerificationPolicyControllerImpl(service: VerificationPolicyService) exten } yield createdVerificationPolicy .toSchema() .withBaseUri(ctx.request.uri) - - } mapError (e => verificationPolicyError2FailureResponse(e)) + } override def getVerificationPolicyById( ctx: RequestContext, id: UUID - ): ZIO[WalletAccessContext, ErrorResponse, VerificationPolicyResponse] = { - service.get(id).flatMap { - case Some(vp) => succeed(vp.toSchema().withUri(ctx.request.uri)) - case None => fail(NotFoundError(id)) - } - }.mapError(e => verificationPolicyError2FailureResponse(e)) + ): ZIO[WalletAccessContext, ErrorResponse, VerificationPolicyResponse] = + service.get(id).map(_.toSchema().withUri(ctx.request.uri)) override def updateVerificationPolicyById( ctx: RequestContext, id: UUID, nonce: Int, update: VerificationPolicyInput - ): ZIO[WalletAccessContext, ErrorResponse, VerificationPolicyResponse] = { - val updatedZIO = for { + ): ZIO[WalletAccessContext, ErrorResponse, VerificationPolicyResponse] = + for { constraints <- zio.ZIO.succeed( update.constraints.toVector // TODO: refactor to Seq .map(c => @@ -90,28 +72,15 @@ class VerificationPolicyControllerImpl(service: VerificationPolicyService) exten nonce = nonce + 1 ) updated <- service.update(id, nonce, vp) - } yield updated - - updatedZIO - .flatMap { - case Some(vp) => succeed(vp.toSchema().withUri(ctx.request.uri)) - case None => fail(NotFoundError(id)) - } - .mapError(e => verificationPolicyError2FailureResponse(e)) - } + } yield updated.toSchema().withUri(ctx.request.uri) override def deleteVerificationPolicyById( ctx: RequestContext, id: UUID - ): ZIO[WalletAccessContext, ErrorResponse, Unit] = { + ): ZIO[WalletAccessContext, ErrorResponse, Unit] = service .delete(id) - .flatMap { - case Some(_) => succeed(()) - case None => fail(NotFoundError(id)) - } - .mapError(e => verificationPolicyError2FailureResponse(e)) - } + .as(()) override def lookupVerificationPolicies( ctx: RequestContext, @@ -122,17 +91,14 @@ class VerificationPolicyControllerImpl(service: VerificationPolicyService) exten for { filteredDomainRecords <- service .lookup(filter.name, Some(pagination.offset), Some(pagination.limit)) - .mapError(verificationPolicyError2FailureResponse) filteredCount <- service .filteredCount(filter.name) - .mapError(verificationPolicyError2FailureResponse) baseUri = ctx.request.uri.copy(querySegments = Seq.empty) filteredRecords = filteredDomainRecords.map( _.toSchema().withBaseUri(baseUri) ) totalCount <- service .totalCount() - .mapError(verificationPolicyError2FailureResponse) response = VerificationPolicyPageRequestLogic( ctx, pagination, diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/error/VerificationPolicyError.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/error/VerificationPolicyError.scala index 4eceb217e8..ce55aaa209 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/error/VerificationPolicyError.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/model/error/VerificationPolicyError.scala @@ -1,10 +1,17 @@ package org.hyperledger.identus.pollux.core.model.error +import org.hyperledger.identus.shared.models.{Failure, StatusCode} + import java.util.UUID -sealed trait VerificationPolicyError +sealed trait VerificationPolicyError( + val statusCode: StatusCode, + val userFacingMessage: String +) extends Failure { + override val namespace = "CredentialSchema" +} + object VerificationPolicyError { - final case class RepositoryError(cause: Throwable) extends VerificationPolicyError - final case class NotFoundError(id: UUID) extends VerificationPolicyError - final case class UnexpectedError(cause: Throwable) extends VerificationPolicyError + final case class NotFoundError(id: UUID) + extends VerificationPolicyError(StatusCode.NotFound, s"VerificationPolicy is not found by $id") } diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/repository/VerificationPolicyRepository.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/repository/VerificationPolicyRepository.scala index cf8b9b0df8..5d7b06c070 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/repository/VerificationPolicyRepository.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/repository/VerificationPolicyRepository.scala @@ -8,29 +8,29 @@ import java.util.UUID trait VerificationPolicyRepository { - def create(verificationPolicy: VerificationPolicy): RIO[WalletAccessContext, VerificationPolicy] + def create(verificationPolicy: VerificationPolicy): URIO[WalletAccessContext, VerificationPolicy] - def get(id: UUID): RIO[WalletAccessContext, Option[VerificationPolicy]] + def findById(id: UUID): URIO[WalletAccessContext, Option[VerificationPolicy]] - def exists(id: UUID): RIO[WalletAccessContext, Boolean] + def exists(id: UUID): URIO[WalletAccessContext, Boolean] - def getHash(id: UUID): RIO[WalletAccessContext, Option[Int]] + def findHashById(id: UUID): URIO[WalletAccessContext, Option[Int]] def update( id: UUID, nonce: Int, verificationPolicy: VerificationPolicy - ): RIO[WalletAccessContext, Option[VerificationPolicy]] + ): URIO[WalletAccessContext, VerificationPolicy] - def delete(id: UUID): RIO[WalletAccessContext, Option[VerificationPolicy]] + def delete(id: UUID): URIO[WalletAccessContext, VerificationPolicy] - def totalCount(): RIO[WalletAccessContext, Long] + def totalCount(): URIO[WalletAccessContext, Long] - def filteredCount(nameOpt: Option[String]): RIO[WalletAccessContext, Long] + def filteredCount(nameOpt: Option[String]): URIO[WalletAccessContext, Long] def lookup( nameOpt: Option[String], offsetOpt: Option[Int], limitOpt: Option[Int] - ): RIO[WalletAccessContext, List[VerificationPolicy]] + ): URIO[WalletAccessContext, List[VerificationPolicy]] } diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/VerificationPolicyService.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/VerificationPolicyService.scala index b8df8aeb09..ab3a267052 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/VerificationPolicyService.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/VerificationPolicyService.scala @@ -15,15 +15,17 @@ trait VerificationPolicyService { constraints: Seq[VerificationPolicyConstraint] = Seq.empty ): ZIO[WalletAccessContext, VerificationPolicyError, VerificationPolicy] - def get(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, Option[VerificationPolicy]] + def find(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, Option[VerificationPolicy]] + + def get(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, VerificationPolicy] def update( id: UUID, nonce: Int, verificationPolicy: VerificationPolicy - ): ZIO[WalletAccessContext, VerificationPolicyError, Option[VerificationPolicy]] + ): ZIO[WalletAccessContext, VerificationPolicyError, VerificationPolicy] - def delete(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, Option[VerificationPolicy]] + def delete(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, VerificationPolicy] def totalCount(): ZIO[WalletAccessContext, VerificationPolicyError, Long] diff --git a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/VerificationPolicyServiceImpl.scala b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/VerificationPolicyServiceImpl.scala index e47f8ca734..ecc9d049a7 100644 --- a/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/VerificationPolicyServiceImpl.scala +++ b/pollux/core/src/main/scala/org/hyperledger/identus/pollux/core/service/VerificationPolicyServiceImpl.scala @@ -2,6 +2,7 @@ package org.hyperledger.identus.pollux.core.service import org.hyperledger.identus.pollux.core.model.{VerificationPolicy, VerificationPolicyConstraint} import org.hyperledger.identus.pollux.core.model.error.VerificationPolicyError +import org.hyperledger.identus.pollux.core.model.error.VerificationPolicyError.NotFoundError import org.hyperledger.identus.pollux.core.repository.VerificationPolicyRepository import org.hyperledger.identus.shared.models.WalletAccessContext import zio.* @@ -17,9 +18,6 @@ class VerificationPolicyServiceImpl( repository: VerificationPolicyRepository ) extends VerificationPolicyService { - private val throwableToVerificationPolicyError: Throwable => VerificationPolicyError = - VerificationPolicyError.RepositoryError.apply - override def create( name: String, description: String, @@ -29,34 +27,44 @@ class VerificationPolicyServiceImpl( verificationPolicy <- VerificationPolicy.make(name, description, constraints) createdVerificationPolicy <- repository.create(verificationPolicy) } yield createdVerificationPolicy - }.mapError(throwableToVerificationPolicyError) + } + + override def find(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, Option[VerificationPolicy]] = + repository + .findById(id) - override def get(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, Option[VerificationPolicy]] = + override def get(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, VerificationPolicy] = { repository - .get(id) - .mapError(throwableToVerificationPolicyError) + .findById(id) + .flatMap { + case None => ZIO.fail(NotFoundError(id)) + case Some(value) => ZIO.succeed(value) + } + } override def update( id: UUID, nonce: Int, verificationPolicy: VerificationPolicy - ): ZIO[WalletAccessContext, VerificationPolicyError, Option[VerificationPolicy]] = - repository - .update(id, nonce, verificationPolicy) - .mapError(throwableToVerificationPolicyError) + ): ZIO[WalletAccessContext, VerificationPolicyError, VerificationPolicy] = + for { + _ <- get(id) + result <- repository.update(id, nonce, verificationPolicy) + } yield result - override def delete(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, Option[VerificationPolicy]] = - repository - .delete(id) - .mapError(throwableToVerificationPolicyError) + override def delete(id: UUID): ZIO[WalletAccessContext, VerificationPolicyError, VerificationPolicy] = + for { + _ <- get(id) + result <- repository.delete(id) + } yield result override def totalCount(): ZIO[WalletAccessContext, VerificationPolicyError, Long] = - repository.totalCount().mapError(throwableToVerificationPolicyError) + repository.totalCount() override def filteredCount( name: Option[String] ): ZIO[WalletAccessContext, VerificationPolicyError, Long] = - repository.filteredCount(name).mapError(throwableToVerificationPolicyError) + repository.filteredCount(name) override def lookup( name: Option[String], @@ -65,5 +73,5 @@ class VerificationPolicyServiceImpl( ): ZIO[WalletAccessContext, VerificationPolicyError, List[VerificationPolicy]] = repository .lookup(name, offset, limit) - .mapError(throwableToVerificationPolicyError) + } diff --git a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/model/db/VerificationPolicy.scala b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/model/db/VerificationPolicy.scala index d4a7005f89..056406c446 100644 --- a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/model/db/VerificationPolicy.scala +++ b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/model/db/VerificationPolicy.scala @@ -42,7 +42,7 @@ object VerificationPolicySql extends DoobieContext.Postgres(SnakeCase) { run(quote(query[VerificationPolicyConstraint].filter(_.fk_id == lift(fk_id)).delete)) } - def getById(id: UUID) = + def findById(id: UUID) = run( quote( query[VerificationPolicy] @@ -50,7 +50,7 @@ object VerificationPolicySql extends DoobieContext.Postgres(SnakeCase) { ) ).map(_.headOption) - def getHashById(id: UUID) = + def findHashById(id: UUID) = run( quote( query[VerificationPolicy] @@ -72,7 +72,7 @@ object VerificationPolicySql extends DoobieContext.Postgres(SnakeCase) { ) ) - def getVerificationPolicyConstrains(fk_ids: Seq[UUID]) = + def getVerificationPolicyConstraints(fk_ids: Seq[UUID]) = run( quote( query[VerificationPolicyConstraint] diff --git a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcVerificationPolicyRepository.scala b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcVerificationPolicyRepository.scala index 86e9dfb025..6596e3e7f1 100644 --- a/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcVerificationPolicyRepository.scala +++ b/pollux/sql-doobie/src/main/scala/org/hyperledger/identus/pollux/sql/repository/JdbcVerificationPolicyRepository.scala @@ -74,7 +74,7 @@ class JdbcVerificationPolicyRepository(xa: Transactor[ContextAwareTask]) extends override def create( verificationPolicy: model.VerificationPolicy - ): RIO[WalletAccessContext, model.VerificationPolicy] = { + ): URIO[WalletAccessContext, VerificationPolicy] = { val program = (walletId: WalletId) => for { vp <- VerificationPolicySql.insert(verificationPolicy.toDto(walletId)) @@ -83,80 +83,81 @@ class JdbcVerificationPolicyRepository(xa: Transactor[ContextAwareTask]) extends for { walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId) - vp: model.VerificationPolicy <- program(walletId).transactWallet(xa) + vp: model.VerificationPolicy <- program(walletId).transactWallet(xa).orDie } yield vp } - override def get(id: UUID): RIO[WalletAccessContext, Option[model.VerificationPolicy]] = { + override def findById(id: UUID): URIO[WalletAccessContext, Option[VerificationPolicy]] = { val program = for { - vp <- VerificationPolicySql.getById(id) - vpc <- VerificationPolicySql.getVerificationPolicyConstrains(Seq(id)) + vp <- VerificationPolicySql.findById(id) + vpc <- VerificationPolicySql.getVerificationPolicyConstraints(Seq(id)) } yield vp.map(_.toDomain(vpc)) for { - vp: Option[model.VerificationPolicy] <- program.transactWallet(xa) + vp: Option[model.VerificationPolicy] <- program.transactWallet(xa).orDie } yield vp } - override def exists(id: UUID): RIO[WalletAccessContext, Boolean] = - VerificationPolicySql.exists(id).transactWallet(xa) + override def exists(id: UUID): URIO[WalletAccessContext, Boolean] = + VerificationPolicySql.exists(id).transactWallet(xa).orDie - override def getHash(id: UUID): RIO[WalletAccessContext, Option[Int]] = - VerificationPolicySql.getHashById(id).transactWallet(xa) + override def findHashById(id: UUID): URIO[WalletAccessContext, Option[Int]] = + VerificationPolicySql.findHashById(id).transactWallet(xa).orDie override def update( id: UUID, nonce: Int, verificationPolicy: model.VerificationPolicy - ): RIO[WalletAccessContext, Option[model.VerificationPolicy]] = { + ): URIO[WalletAccessContext, VerificationPolicy] = { val preparedVP = verificationPolicy.copy(id = id, updatedAt = OffsetDateTime.now(ZoneOffset.UTC)) val program = (walletId: WalletId) => for { - _ <- VerificationPolicySql.update(preparedVP.toDto(walletId), nonce) + updateVp <- VerificationPolicySql.update(preparedVP.toDto(walletId), nonce) _ <- VerificationPolicySql.dropConstraintsByVerificationPolicyId(id) - vp: Option[db.VerificationPolicy] <- VerificationPolicySql.getById(id) vpc: Seq[db.VerificationPolicyConstraint] <- VerificationPolicySql.insertConstraints( preparedVP.toDtoConstraints ) - } yield vp.map(_.toDomain(vpc)) + } yield updateVp.toDomain(vpc) for { walletId <- ZIO.serviceWith[WalletAccessContext](_.walletId) - vp <- program(walletId).transactWallet(xa) + vp <- program(walletId).transactWallet(xa).orDie } yield vp } - override def delete(id: UUID): RIO[WalletAccessContext, Option[model.VerificationPolicy]] = { + override def delete(id: UUID): URIO[WalletAccessContext, VerificationPolicy] = { val program = for { - vp <- VerificationPolicySql.getById(id) - vpc <- VerificationPolicySql.getVerificationPolicyConstrains(Seq(id)) - _ <- VerificationPolicySql.delete(id) - } yield vp.map(_.toDomain(vpc)) + maybeVp <- VerificationPolicySql.findById(id) + vpc <- VerificationPolicySql.getVerificationPolicyConstraints(Seq(id)) + vp <- VerificationPolicySql.delete(id) + } yield vp.toDomain(vpc) - program.transactWallet(xa) + program.transactWallet(xa).orDie } - override def totalCount(): RIO[WalletAccessContext, Long] = { - VerificationPolicySql.count().transactWallet(xa) + override def totalCount(): URIO[WalletAccessContext, Long] = { + VerificationPolicySql.count().transactWallet(xa).orDie } - override def filteredCount(nameOpt: Option[String]): RIO[WalletAccessContext, Long] = - VerificationPolicySql.countFiltered(nameOpt).transactWallet(xa) + override def filteredCount(nameOpt: Option[String]): URIO[WalletAccessContext, Long] = + VerificationPolicySql.countFiltered(nameOpt).transactWallet(xa).orDie override def lookup( nameOpt: Option[String], offsetOpt: Option[Int], limitOpt: Option[Int] - ): RIO[WalletAccessContext, List[model.VerificationPolicy]] = { + ): URIO[WalletAccessContext, List[VerificationPolicy]] = { for { policies: List[db.VerificationPolicy] <- VerificationPolicySql .filteredVerificationPolicies(nameOpt, offsetOpt, limitOpt) .transactWallet(xa) + .orDie ids = policies.map(_.id) constrains <- VerificationPolicySql - .getVerificationPolicyConstrains(ids) + .getVerificationPolicyConstraints(ids) .transactWallet(xa) + .orDie constraintsById = constrains.groupBy(_.fk_id) diff --git a/pollux/sql-doobie/src/test/scala/org/hyperledger/identus/pollux/sql/VerificationPolicySqlIntegrationSpec.scala b/pollux/sql-doobie/src/test/scala/org/hyperledger/identus/pollux/sql/VerificationPolicySqlIntegrationSpec.scala index 0f7b867855..c525381945 100644 --- a/pollux/sql-doobie/src/test/scala/org/hyperledger/identus/pollux/sql/VerificationPolicySqlIntegrationSpec.scala +++ b/pollux/sql-doobie/src/test/scala/org/hyperledger/identus/pollux/sql/VerificationPolicySqlIntegrationSpec.scala @@ -59,8 +59,8 @@ object VerificationPolicySqlIntegrationSpec extends ZIOSpecDefault, PostgresTest .runCollectN(1) .flatMap(_.head) _ <- repo.create(record).provide(wallet1) - ownRecord <- repo.get(record.id).provide(wallet1) - crossRecord <- repo.get(record.id).provide(wallet2) + ownRecord <- repo.findById(record.id).provide(wallet1) + crossRecord <- repo.findById(record.id).provide(wallet2) } yield assert(ownRecord)(isSome(equalTo(record))) && assert(crossRecord)(isNone) }, test("total count do not consider records outside of the wallet") { @@ -90,7 +90,7 @@ object VerificationPolicySqlIntegrationSpec extends ZIOSpecDefault, PostgresTest .flatMap(_.head) _ <- repo.create(record1).provide(wallet1) deleteResult <- repo.delete(record1.id).provide(wallet2).exit - actualRecord <- repo.get(record1.id).provide(wallet1) + actualRecord <- repo.findById(record1.id).provide(wallet1) } yield assert(deleteResult)(failsCause(anything)) && assert(actualRecord)(isSome(equalTo(record1))) } @@ -107,7 +107,7 @@ object VerificationPolicySqlIntegrationSpec extends ZIOSpecDefault, PostgresTest .runCollectN(1) .flatMap(_.head) actualCreated <- repo.create(expectedCreated) - getByIdCreated <- repo.get(expectedCreated.id) + getByIdCreated <- repo.findById(expectedCreated.id) allRecordsAreSimilar = assert(expectedCreated)( equalTo(actualCreated) @@ -122,13 +122,8 @@ object VerificationPolicySqlIntegrationSpec extends ZIOSpecDefault, PostgresTest description = "new description" ) actualUpdated <- repo - .update( - actualCreated.id, - actualCreated.nonce, - expectedUpdated - ) - .map(_.get) - getByIdUpdated <- repo.get(expectedUpdated.id).map(_.get) + .update(actualCreated.id, actualCreated.nonce, expectedUpdated) + getByIdUpdated <- repo.findById(expectedUpdated.id).map(_.get) isUpdated = assert(actualUpdated)(equalTo(expectedUpdated.copy(updatedAt = actualUpdated.updatedAt))) && assert(getByIdUpdated)(equalTo(expectedUpdated.copy(updatedAt = actualUpdated.updatedAt))) @@ -140,27 +135,20 @@ object VerificationPolicySqlIntegrationSpec extends ZIOSpecDefault, PostgresTest description = "new description 2" ) actualUpdated2 <- repo - .update( - actualUpdated.id, - actualUpdated.nonce, - expectedUpdated2 - ) - .map(_.get) - getByIdUpdated2 <- repo.get(expectedUpdated2.id).map(_.get) + .update(actualUpdated.id, actualUpdated.nonce, expectedUpdated2) + getByIdUpdated2 <- repo.findById(expectedUpdated2.id).map(_.get) isUpdated2 = assert(actualUpdated2)(equalTo(expectedUpdated2.copy(updatedAt = actualUpdated.updatedAt))) && assert(getByIdUpdated2)(equalTo(expectedUpdated2.copy(updatedAt = actualUpdated.updatedAt))) // - actualDeleted <- repo.delete( - expectedUpdated.id - ) + actualDeleted <- repo.delete(expectedUpdated.id) isDeletedReturnedBack = assert(actualDeleted)( - isSome(equalTo(actualUpdated2)) + equalTo(actualUpdated2) ) - getByIdDeleted <- repo.get(actualUpdated.id) + getByIdDeleted <- repo.findById(actualUpdated.id) isDeleted = assert(getByIdDeleted)(isNone) @@ -218,11 +206,7 @@ object VerificationPolicySqlIntegrationSpec extends ZIOSpecDefault, PostgresTest for { repo <- ZIO.service[VerificationPolicyRepository] first <- repo.lookup(None, offsetOpt = Some(0), limitOpt = Some(N / 2)) - second <- repo.lookup( - None, - offsetOpt = Some(N / 2), - limitOpt = Some(N / 2) - ) + second <- repo.lookup(None, offsetOpt = Some(N / 2), limitOpt = Some(N / 2)) firstPageContainsAHalfOfTheRecords = assert(first.length)( equalTo(N / 2) ) @@ -241,11 +225,7 @@ object VerificationPolicySqlIntegrationSpec extends ZIOSpecDefault, PostgresTest repo <- ZIO.service[VerificationPolicyRepository] paginator = new Paginator(skipLimit => - repo.lookup( - nameOpt = None, - offsetOpt = Some(skipLimit.skip), - limitOpt = Some(skipLimit.limit) - ) + repo.lookup(nameOpt = None, offsetOpt = Some(skipLimit.skip), limitOpt = Some(skipLimit.limit)) ) allItems1 <- paginator.fetchAll(SkipLimit(0, 1))