Skip to content

Commit

Permalink
PIN-5060: Fix update tenant on kind change
Browse files Browse the repository at this point in the history
  • Loading branch information
galales committed Jul 4, 2024
1 parent d74949c commit 7ee0ac9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
)
}
Expand Down Expand Up @@ -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
)
)
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
)
)
}
Expand Down Expand Up @@ -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
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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._
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7ee0ac9

Please sign in to comment.