From 4f2571762c020e445f266743dd0305bca7d741fc Mon Sep 17 00:00:00 2001 From: Benjamin Cavy Date: Mon, 9 Dec 2024 23:07:40 +0100 Subject: [PATCH] fix: tests --- app/fr/maif/izanami/web/FeatureController.scala | 9 +++------ app/fr/maif/izanami/web/UserController.scala | 2 +- test/fr/maif/izanami/api/FeatureAPISpec.scala | 2 +- .../maif/izanami/api/FeatureContextAPISpec.scala | 4 ++-- test/fr/maif/izanami/api/ProjectAPISpec.scala | 4 ++-- test/fr/maif/izanami/api/SearchAPISpec.scala | 15 --------------- 6 files changed, 9 insertions(+), 27 deletions(-) diff --git a/app/fr/maif/izanami/web/FeatureController.scala b/app/fr/maif/izanami/web/FeatureController.scala index 4597e8dc4..05b44e31d 100644 --- a/app/fr/maif/izanami/web/FeatureController.scala +++ b/app/fr/maif/izanami/web/FeatureController.scala @@ -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, diff --git a/app/fr/maif/izanami/web/UserController.scala b/app/fr/maif/izanami/web/UserController.scala index 2972634ff..32e39daf8 100644 --- a/app/fr/maif/izanami/web/UserController.scala +++ b/app/fr/maif/izanami/web/UserController.scala @@ -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) diff --git a/test/fr/maif/izanami/api/FeatureAPISpec.scala b/test/fr/maif/izanami/api/FeatureAPISpec.scala index d05214eb9..2677a2fbd 100644 --- a/test/fr/maif/izanami/api/FeatureAPISpec.scala +++ b/test/fr/maif/izanami/api/FeatureAPISpec.scala @@ -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 { diff --git a/test/fr/maif/izanami/api/FeatureContextAPISpec.scala b/test/fr/maif/izanami/api/FeatureContextAPISpec.scala index a120e3311..a0ba06255 100644 --- a/test/fr/maif/izanami/api/FeatureContextAPISpec.scala +++ b/test/fr/maif/izanami/api/FeatureContextAPISpec.scala @@ -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 { diff --git a/test/fr/maif/izanami/api/ProjectAPISpec.scala b/test/fr/maif/izanami/api/ProjectAPISpec.scala index 4c5350e60..a6e956796 100644 --- a/test/fr/maif/izanami/api/ProjectAPISpec.scala +++ b/test/fr/maif/izanami/api/ProjectAPISpec.scala @@ -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") @@ -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 } } diff --git a/test/fr/maif/izanami/api/SearchAPISpec.scala b/test/fr/maif/izanami/api/SearchAPISpec.scala index 26e3cd4c6..09c0ab572 100644 --- a/test/fr/maif/izanami/api/SearchAPISpec.scala +++ b/test/fr/maif/izanami/api/SearchAPISpec.scala @@ -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)