From 7ee0ac9b81d48baf756bd5bb0baa5f93ced8fcc4 Mon Sep 17 00:00:00 2001 From: Alessio Gallitano <25105748+galales@users.noreply.github.com> Date: Thu, 4 Jul 2024 14:48:35 +0200 Subject: [PATCH] PIN-5060: Fix update tenant on kind change --- .../api/impl/TenantApiServiceImpl.scala | 24 +++++++++++--- .../provider/CertifiedAttributeSpec.scala | 23 ++++++------- .../provider/TenantCreationSpec.scala | 33 ++++++++++++++++--- .../utils/FakeDependencies.scala | 7 ++++ 4 files changed, 67 insertions(+), 20 deletions(-) diff --git a/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiServiceImpl.scala b/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiServiceImpl.scala index cafa506..fdbd7b8 100644 --- a/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiServiceImpl.scala +++ b/src/main/scala/it/pagopa/interop/tenantprocess/api/impl/TenantApiServiceImpl.scala @@ -445,8 +445,10 @@ final case class TenantApiServiceImpl( updatedTenant.id, DependencyTenantDelta( selfcareId = updatedTenant.selfcareId, + onboardedAt = updatedTenant.onboardedAt, features = updatedTenant.features, - kind = tenantKind + kind = tenantKind, + subUnitType = updatedTenant.subUnitType ) ) } @@ -527,8 +529,10 @@ final case class TenantApiServiceImpl( updatedTenant.id, DependencyTenantDelta( selfcareId = updatedTenant.selfcareId, + onboardedAt = updatedTenant.onboardedAt, features = updatedTenant.features, - kind = tenantKind + kind = tenantKind, + subUnitType = updatedTenant.subUnitType ) ) } @@ -704,7 +708,13 @@ final case class TenantApiServiceImpl( tenantManagementService .updateTenant( tenant.id, - DependencyTenantDelta(selfcareId = tenant.selfcareId, features = tenant.features, kind = kind) + DependencyTenantDelta( + selfcareId = tenant.selfcareId, + onboardedAt = tenant.onboardedAt, + features = tenant.features, + kind = kind, + subUnitType = tenant.subUnitType + ) ) for { @@ -858,8 +868,10 @@ final case class TenantApiServiceImpl( updatedTenant.id, DependencyTenantDelta( selfcareId = updatedTenant.selfcareId, + onboardedAt = updatedTenant.onboardedAt, features = updatedTenant.features, - kind = tenantKind + kind = tenantKind, + subUnitType = updatedTenant.subUnitType ) ) } @@ -902,8 +914,10 @@ final case class TenantApiServiceImpl( updatedTenant.id, DependencyTenantDelta( selfcareId = updatedTenant.selfcareId, + onboardedAt = updatedTenant.onboardedAt, features = updatedTenant.features, - kind = tenantKind + kind = tenantKind, + subUnitType = updatedTenant.subUnitType ) ) } diff --git a/src/test/scala/it/pagopa/interop/tenantprocess/provider/CertifiedAttributeSpec.scala b/src/test/scala/it/pagopa/interop/tenantprocess/provider/CertifiedAttributeSpec.scala index 368252d..d701c7c 100644 --- a/src/test/scala/it/pagopa/interop/tenantprocess/provider/CertifiedAttributeSpec.scala +++ b/src/test/scala/it/pagopa/interop/tenantprocess/provider/CertifiedAttributeSpec.scala @@ -3,11 +3,12 @@ package it.pagopa.interop.tenantprocess.provider import akka.http.scaladsl.model.StatusCodes import akka.http.scaladsl.testkit.ScalatestRouteTest import it.pagopa.interop.agreementprocess.client.model.CompactTenant +import it.pagopa.interop.attributeregistrymanagement.model.persistence.attribute.Declared import it.pagopa.interop.tenantmanagement.client.{model => Dependency} import it.pagopa.interop.tenantmanagement.model.tenant.{PersistentTenantFeature, PersistentTenantKind} -import it.pagopa.interop.attributeregistrymanagement.model.persistence.attribute.Declared -import it.pagopa.interop.tenantprocess.model.CertifiedTenantAttributeSeed +import it.pagopa.interop.tenantprocess.api.adapters.ReadModelTenantAdapters.PersistentTenantUnitTypeWrapper import it.pagopa.interop.tenantprocess.api.impl.TenantApiMarshallerImpl._ +import it.pagopa.interop.tenantprocess.model.CertifiedTenantAttributeSeed import it.pagopa.interop.tenantprocess.utils.SpecHelper import org.scalatest.wordspec.AnyWordSpecLike @@ -87,11 +88,11 @@ class CertifiedAttributeSpec extends AnyWordSpecLike with SpecHelper with Scalat mockUpdateTenant( tenantId, Dependency.TenantDelta( - selfcareId = None, + selfcareId = tenant.selfcareId, features = Nil, kind = Dependency.TenantKind.PA, - onboardedAt = None, - subUnitType = None + onboardedAt = tenant.onboardedAt, + subUnitType = tenant.subUnitType.map(_.toManagement) ) ) mockComputeAgreementState(attributeId, CompactTenant(tenantId, Nil)) @@ -132,11 +133,11 @@ class CertifiedAttributeSpec extends AnyWordSpecLike with SpecHelper with Scalat mockUpdateTenant( tenantId, Dependency.TenantDelta( - selfcareId = None, + selfcareId = tenant.selfcareId, features = Nil, kind = Dependency.TenantKind.PA, - onboardedAt = None, - subUnitType = None + onboardedAt = tenant.onboardedAt, + subUnitType = tenant.subUnitType.map(_.toManagement) ) ) mockComputeAgreementState(attributeId, CompactTenant(tenantId, Nil)) @@ -337,11 +338,11 @@ class CertifiedAttributeSpec extends AnyWordSpecLike with SpecHelper with Scalat mockUpdateTenant( tenantId, Dependency.TenantDelta( - selfcareId = None, + selfcareId = tenant.selfcareId, features = Nil, kind = Dependency.TenantKind.PA, - onboardedAt = None, - subUnitType = None + onboardedAt = tenant.onboardedAt, + subUnitType = tenant.subUnitType.map(_.toManagement) ) ) diff --git a/src/test/scala/it/pagopa/interop/tenantprocess/provider/TenantCreationSpec.scala b/src/test/scala/it/pagopa/interop/tenantprocess/provider/TenantCreationSpec.scala index 7bf1447..0c18399 100644 --- a/src/test/scala/it/pagopa/interop/tenantprocess/provider/TenantCreationSpec.scala +++ b/src/test/scala/it/pagopa/interop/tenantprocess/provider/TenantCreationSpec.scala @@ -11,6 +11,7 @@ import it.pagopa.interop.tenantmanagement.model.tenant.{ PersistentTenantKind } import it.pagopa.interop.tenantprocess.api.adapters.ApiAdapters.TenantUnitTypeWrapper +import it.pagopa.interop.tenantprocess.api.adapters.ReadModelTenantAdapters._ import it.pagopa.interop.tenantprocess.api.impl.TenantApiMarshallerImpl._ import it.pagopa.interop.tenantprocess.model.{InternalAttributeSeed, M2MAttributeSeed} import it.pagopa.interop.tenantprocess.provider.TenantCreationSpec._ @@ -364,7 +365,13 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR mockGetAttributeById(updatedExistingAttributeId, updatedExistingAttribute) val expectedTenantUpdate = - TenantDelta(selfcareId = None, features = Nil, kind = TenantKind.PA) + TenantDelta( + selfcareId = existingTenant.selfcareId, + features = existingTenant.features.map(_.toManagement), + kind = TenantKind.PA, + onboardedAt = existingTenant.onboardedAt, + subUnitType = existingTenant.subUnitType.map(_.toManagement) + ) mockUpdateTenant(existingTenant.id, expectedTenantUpdate) @@ -473,7 +480,13 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR mockGetAttributeById(updatedExistingAttributeId, updatedExistingAttribute) val expectedTenantUpdate = - TenantDelta(selfcareId = None, features = Nil, kind = TenantKind.GSP) + TenantDelta( + selfcareId = existingTenant.selfcareId, + features = existingTenant.features.map(_.toManagement), + kind = TenantKind.GSP, + onboardedAt = existingTenant.onboardedAt, + subUnitType = existingTenant.subUnitType.map(_.toManagement) + ) mockUpdateTenant(existingTenant.id, expectedTenantUpdate) @@ -700,7 +713,13 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR mockUpdateTenantAttribute(tenantToModify.id, attributeId, dependencyAttribute) val expectedTenantUpdate = - TenantDelta(selfcareId = None, features = Nil, kind = TenantKind.PA) + TenantDelta( + selfcareId = tenantToModify.selfcareId, + features = tenantToModify.features.map(_.toManagement), + kind = TenantKind.PA, + onboardedAt = tenantToModify.onboardedAt, + subUnitType = tenantToModify.subUnitType.map(_.toManagement) + ) mockComputeAgreementState(attributeId, CompactTenant(tenantId, Nil)) @@ -886,7 +905,13 @@ class TenantCreationSpec extends AnyWordSpecLike with SpecHelper with ScalatestR mockGetAttributeById(updatedExistingAttributeId, updatedExistingAttribute) val expectedTenantUpdate = - TenantDelta(selfcareId = None, features = Nil, kind = TenantKind.PA) + TenantDelta( + selfcareId = existingTenant.selfcareId, + features = existingTenant.features.map(_.toManagement), + kind = TenantKind.PA, + onboardedAt = existingTenant.onboardedAt, + subUnitType = existingTenant.subUnitType.map(_.toManagement) + ) mockUpdateTenant(existingTenant.id, expectedTenantUpdate) diff --git a/src/test/scala/it/pagopa/interop/tenantprocess/utils/FakeDependencies.scala b/src/test/scala/it/pagopa/interop/tenantprocess/utils/FakeDependencies.scala index 326fc6e..cffe78d 100644 --- a/src/test/scala/it/pagopa/interop/tenantprocess/utils/FakeDependencies.scala +++ b/src/test/scala/it/pagopa/interop/tenantprocess/utils/FakeDependencies.scala @@ -25,6 +25,8 @@ import java.util.UUID import scala.concurrent.{ExecutionContext, Future} import it.pagopa.interop.tenantprocess.common.readmodel.CertifiedAttribute +import scala.reflect.ClassTag + object FakeDependencies extends SpecData { val verifiedAttributeId: UUID = UUID.randomUUID() val (agreement, eService) = matchingAgreementAndEService(verifiedAttributeId) @@ -179,6 +181,11 @@ object FakeDependencies extends SpecData { )(implicit ec: ExecutionContext): Future[Seq[T]] = Future.successful(Nil) override def close(): Unit = () + + override def distinct[T](collectionName: String, fieldName: String, filter: Bson)(implicit + evidence$6: ClassTag[T], + ec: ExecutionContext + ): Future[Seq[T]] = Future.successful(Nil) } val fakeTenant: Tenant = Tenant(