-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PIN-4370 BKE - Tenant process Added route for addition certified attr…
…ibute
- Loading branch information
nttdata-rtorsoli
committed
Jan 15, 2024
1 parent
c18763e
commit 5a62d6b
Showing
12 changed files
with
284 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,6 +164,13 @@ | |
"admin", | ||
"api" | ||
] | ||
}, | ||
{ | ||
"route": "addCertifiedAttribute", | ||
"verb": "POST", | ||
"roles": [ | ||
"admin" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
src/test/scala/it/pagopa/interop/tenantprocess/provider/CertifiedAttributeSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
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.tenantmanagement.client.{model => Dependency} | ||
import it.pagopa.interop.tenantmanagement.model.tenant.{PersistentTenantFeature} | ||
import it.pagopa.interop.attributeregistrymanagement.model.persistence.attribute.Declared | ||
import it.pagopa.interop.tenantprocess.model.CertifiedTenantAttributeSeed | ||
import it.pagopa.interop.tenantprocess.api.impl.TenantApiMarshallerImpl._ | ||
import it.pagopa.interop.tenantprocess.utils.SpecHelper | ||
import org.scalatest.wordspec.AnyWordSpecLike | ||
|
||
import java.util.UUID | ||
|
||
class CertifiedAttributeSpec extends AnyWordSpecLike with SpecHelper with ScalatestRouteTest { | ||
|
||
"Certified attribute addition" should { | ||
"succeed" in { | ||
implicit val context: Seq[(String, String)] = adminContext | ||
|
||
val tenantUuid = UUID.randomUUID() | ||
val attributeId = UUID.randomUUID() | ||
val seed = CertifiedTenantAttributeSeed(attributeId) | ||
val managementSeed = Dependency.TenantAttribute( | ||
declared = None, | ||
certified = Some( | ||
Dependency.CertifiedTenantAttribute(seed.id, assignmentTimestamp = timestamp, revocationTimestamp = None) | ||
), | ||
verified = None | ||
) | ||
|
||
val requester = persistentTenant.copy( | ||
id = organizationId, | ||
features = List(PersistentTenantFeature.PersistentCertifier("certifier")) | ||
) | ||
|
||
val tenant = persistentTenant.copy( | ||
id = tenantUuid, | ||
attributes = List(persistentCertifiedAttribute, persistentDeclaredAttribute, persistentVerifiedAttribute) | ||
) | ||
|
||
mockDateTimeGet() | ||
mockGetTenantById(organizationId, requester) | ||
mockGetTenantById(tenantUuid, tenant) | ||
mockGetAttributeById(seed.id, persistentAttribute.copy(id = seed.id)) | ||
mockAddTenantAttribute(tenantUuid, managementSeed) | ||
mockComputeAgreementState(attributeId, CompactTenant(tenantUuid, Nil)) | ||
|
||
Post() ~> tenantService.addCertifiedAttribute(tenantUuid.toString, seed) ~> check { | ||
assert(status == StatusCodes.OK) | ||
} | ||
} | ||
} | ||
"fail if requester is not a certifier" in { | ||
implicit val context: Seq[(String, String)] = adminContext | ||
|
||
val tenantUuid = UUID.randomUUID() | ||
val attributeId = UUID.randomUUID() | ||
val seed = CertifiedTenantAttributeSeed(attributeId) | ||
|
||
val requester = persistentTenant.copy(id = organizationId) | ||
|
||
mockDateTimeGet() | ||
mockGetTenantById(organizationId, requester) | ||
|
||
Post() ~> tenantService.addCertifiedAttribute(tenantUuid.toString, seed) ~> check { | ||
assert(status == StatusCodes.Forbidden) | ||
} | ||
} | ||
|
||
"fail if attribute does not exists" in { | ||
implicit val context: Seq[(String, String)] = adminContext | ||
|
||
val tenantUuid = UUID.randomUUID() | ||
val attributeId = UUID.randomUUID() | ||
val seed = CertifiedTenantAttributeSeed(attributeId) | ||
|
||
val requester = persistentTenant.copy( | ||
id = organizationId, | ||
features = List(PersistentTenantFeature.PersistentCertifier("certifier")) | ||
) | ||
|
||
mockDateTimeGet() | ||
mockGetTenantById(organizationId, requester) | ||
mockGetAttributeByIdNotFound(seed.id) | ||
|
||
Post() ~> tenantService.addCertifiedAttribute(tenantUuid.toString, seed) ~> check { | ||
assert(status == StatusCodes.InternalServerError) | ||
} | ||
} | ||
|
||
"fail if attribute exists but is not certified" in { | ||
implicit val context: Seq[(String, String)] = adminContext | ||
|
||
val tenantUuid = UUID.randomUUID() | ||
val attributeId = UUID.randomUUID() | ||
val seed = CertifiedTenantAttributeSeed(attributeId) | ||
|
||
val requester = persistentTenant.copy( | ||
id = organizationId, | ||
features = List(PersistentTenantFeature.PersistentCertifier("certifier")) | ||
) | ||
|
||
mockDateTimeGet() | ||
mockGetTenantById(organizationId, requester) | ||
mockGetAttributeById(seed.id, persistentAttribute.copy(id = seed.id, kind = Declared)) | ||
|
||
Post() ~> tenantService.addCertifiedAttribute(tenantUuid.toString, seed) ~> check { | ||
assert(status == StatusCodes.InternalServerError) | ||
} | ||
} | ||
|
||
"fail if certified tenant attribute already exists" in { | ||
implicit val context: Seq[(String, String)] = adminContext | ||
|
||
val tenantUuid = UUID.randomUUID() | ||
val attributeId = UUID.randomUUID() | ||
val seed = CertifiedTenantAttributeSeed(attributeId) | ||
|
||
val requester = persistentTenant.copy( | ||
id = organizationId, | ||
features = List(PersistentTenantFeature.PersistentCertifier("certifier")) | ||
) | ||
|
||
val tenant = persistentTenant.copy( | ||
id = tenantUuid, | ||
attributes = | ||
List(persistentCertifiedAttribute.copy(id = seed.id), persistentDeclaredAttribute, persistentVerifiedAttribute) | ||
) | ||
|
||
mockDateTimeGet() | ||
mockGetTenantById(organizationId, requester) | ||
mockGetTenantById(tenantUuid, tenant) | ||
mockGetAttributeById(seed.id, persistentAttribute.copy(id = seed.id)) | ||
|
||
Post() ~> tenantService.addCertifiedAttribute(tenantUuid.toString, seed) ~> check { | ||
assert(status == StatusCodes.Conflict) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters