Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitFicus committed Dec 9, 2024
1 parent ec01482 commit 4f25717
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 27 deletions.
9 changes: 3 additions & 6 deletions app/fr/maif/izanami/web/FeatureController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,16 @@ import fr.maif.izanami.models.Feature._
import fr.maif.izanami.models._
import fr.maif.izanami.models.features.{BooleanResult, FeaturePatch, ProjectFeaturePatch}
import fr.maif.izanami.utils.syntax.implicits.BetterSyntax
import fr.maif.izanami.v1.OldFeature
import fr.maif.izanami.web.FeatureController.queryFeatures
import io.otoroshi.wasm4s.scaladsl.WasmSourceKind
import play.api.libs.Files
import play.api.libs.json.Format.GenericFormat
import play.api.libs.json._
import play.api.mvc._

import java.time.{Instant, ZoneId}
import java.util.{Base64, TimeZone}
import java.time.Instant
import java.util.Base64
import scala.concurrent.{ExecutionContext, Future}
import scala.io.Source
import scala.util.{Failure, Success, Try}
import scala.util.{Failure, Success}

class FeatureController(
val env: Env,
Expand Down
2 changes: 1 addition & 1 deletion app/fr/maif/izanami/web/UserController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class UserController(
}

def deleteUser(user: String): Action[AnyContent] = adminAction.async { implicit request =>
if (request.user.equals(user)) {
if (request.user.username.equals(user)) {
Future.successful(BadRequest(Json.obj("message" -> "User can't delete itself !")))
} else {
env.datastores.users.deleteUser(user).map(_ => NoContent)
Expand Down
2 changes: 1 addition & 1 deletion test/fr/maif/izanami/api/FeatureAPISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ class FeatureAPISpec extends BaseAPISpec {
.build()
val response = testSituation.createFeature(name = "my-feature", project = "my-project", tenant = "foo")

response.status mustBe NOT_FOUND
response.status mustBe FORBIDDEN
}

"allow metadata in feature creation" in {
Expand Down
4 changes: 2 additions & 2 deletions test/fr/maif/izanami/api/FeatureContextAPISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -642,14 +642,14 @@ class FeatureContextAPISpec extends BaseAPISpec {
res.status mustBe NOT_FOUND
}

"Return 404 if project does not exist" in {
"Return 403 if project does not exist" in {
val situation = TestSituationBuilder()
.loggedInWithAdminRights()
.withTenants(TestTenant("tenant"))
.build()
val res = situation.changeFeatureStrategyForContext("tenant", "project", "context", "F1", enabled = true)

res.status mustBe NOT_FOUND
res.status mustBe FORBIDDEN
}

"Return 404 if context does not exist" in {
Expand Down
4 changes: 2 additions & 2 deletions test/fr/maif/izanami/api/ProjectAPISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ProjectAPISpec extends BaseAPISpec {
response.status mustBe UNAUTHORIZED
}

"Return 404 if project does not exist" in {
"Return 403 if project does not exist" in {
val situation = TestSituationBuilder()
.withTenants(
TestTenant("my-tenant")
Expand All @@ -140,7 +140,7 @@ class ProjectAPISpec extends BaseAPISpec {

val response = situation.deleteProject("my-project", "my-tenant", "barbar123")

response.status mustBe NOT_FOUND
response.status mustBe FORBIDDEN
}
}

Expand Down
15 changes: 0 additions & 15 deletions test/fr/maif/izanami/api/SearchAPISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ class SearchAPISpec extends BaseAPISpec {
fetchResponse.json.get.as[JsArray].value must have size 1
}

"prevent search if filter is not valid" in {
val tenantName = "my-tenant"
val searchQuery = "comm"
val situation = TestSituationBuilder()
.loggedInWithAdminRights()
.withTenants(
TestTenant(tenantName).withProjects(TestProject("project").withFeatureNames("comments", "foo", "bar"))
)
.build()

val fetchResponse = situation.fetchSearchEntitiesWithFilters(searchQuery, List("feat"))

fetchResponse.json.get mustBe Json.obj("message" -> "Invalid filters provided. Please ensure your filters are correct.")
}

// TODO check that result ordering is correct
// TODO check that there is no more than 10 results
// TODO check that path array contains correctly ordered entries (for features, local and global context)
Expand Down

0 comments on commit 4f25717

Please sign in to comment.