Skip to content

Commit

Permalink
chore: regression test for local context delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitFicus committed Jun 14, 2024
1 parent d5c8b0a commit 36ea22a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/fr/maif/izanami/datastores/FeatureContextDatastore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,13 @@ class FeatureContextDatastore(val env: Env) extends Datastore {
case Right(value) => {
env.postgresql
.queryRaw(
s"""DELETE FROM feature_context_name_unicity_check_table WHERE parent = $$1 AND context=$$2""",
List(if (parentPart.isEmpty) "" else generateSubContextId(project, parentPart), ctxName),
s"""DELETE FROM feature_context_name_unicity_check_table
|WHERE (parent = $$1 AND context=$$2)
|""".stripMargin,
List(
if (parentPart.isEmpty) "" else generateSubContextId(project, parentPart),
ctxName
),
conn = Some(conn)
) { _ => Some(()) }
.map(_ => Right(()))
Expand Down
32 changes: 32 additions & 0 deletions test/fr/maif/izanami/api/FeatureContextAPISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,38 @@ class FeatureContextAPISpec extends BaseAPISpec {
}

"Context POST endpoint" should {
"Allow to recreate deleted local context" in {
val situation = TestSituationBuilder()
.withTenants(
TestTenant("tenant")
.withGlobalContext(TestFeatureContext(
"prod",
subContext = Set(
TestFeatureContext(
"mobile")))
)
.withProjects(TestProject("project"))
)
.loggedInWithAdminRights()
.build()
val response = situation.createContext("tenant", "project", name="localsubmobile", parents = "prod/mobile")
val response2 = situation.createContext("tenant", "project", name="localsubprod", parents = "prod")
response.status mustBe CREATED
response2.status mustBe CREATED

val deleteResponse = situation.deleteGlobalContext("tenant", "prod")
deleteResponse.status mustBe NO_CONTENT

val response3 = situation.createGlobalContext("tenant", name = "prod")
val response4 = situation.createGlobalContext("tenant", name = "mobile", parents = "prod")
val response5 = situation.createContext("tenant", "project", "localsubmobile", parents = "prod/mobile")
val response6 = situation.createContext("tenant", "project", "localsubprod", parents = "prod")

response3.status mustEqual CREATED
response4.status mustEqual CREATED
response5.status mustEqual CREATED
response6.status mustEqual CREATED
}
"allow context creation" in {
val tenant = "context-tenant"
val project = "context-project"
Expand Down

0 comments on commit 36ea22a

Please sign in to comment.