diff --git a/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesRoutes.scala b/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesRoutes.scala index cd77870dff..cdeaafe870 100644 --- a/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesRoutes.scala +++ b/delta/app/src/main/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesRoutes.scala @@ -93,6 +93,7 @@ final class ResourcesRoutes( .flatTap(index(project, _, mode)) .map(_.void) .attemptNarrow[ResourceRejection] + .rejectOn[InvalidSchemaRejection] ) } }, @@ -113,6 +114,7 @@ final class ResourcesRoutes( .flatTap(index(project, _, mode)) .map(_.void) .attemptNarrow[ResourceRejection] + .rejectOn[InvalidSchemaRejection] ) case (Some(rev), source, tag) => // Update a resource @@ -122,7 +124,7 @@ final class ResourcesRoutes( .flatTap(index(project, _, mode)) .map(_.void) .attemptNarrow[ResourceRejection] - .rejectOn[ResourceNotFound] + .rejectWhen { case _: ResourceNotFound | _: InvalidSchemaRejection => true } ) } } diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/SchemasSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/SchemasSpec.scala index 1dbc0e5f8d..37edd1d686 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/SchemasSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/kg/SchemasSpec.scala @@ -1,6 +1,7 @@ package ch.epfl.bluebrain.nexus.tests.kg -import akka.http.scaladsl.model.StatusCodes +import akka.http.scaladsl.model.{HttpResponse, StatusCodes} +import cats.syntax.all._ import ch.epfl.bluebrain.nexus.delta.kernel.utils.UrlUtils import ch.epfl.bluebrain.nexus.tests.BaseIntegrationSpec import ch.epfl.bluebrain.nexus.tests.Identity.resources.Rick @@ -195,6 +196,24 @@ class SchemasSpec extends BaseIntegrationSpec { } } yield succeed } + + "create a schema against the resource endpoint" in { + val id = genId() + val schemaSegment = UrlUtils.encode("https://bluebrain.github.io/nexus/schemas/shacl-20170720.ttl") + + for { + payload <- SchemaPayloads.simple(id) + _ <- deltaClient.put[Json](s"/resources/$project/$schemaSegment/$id", payload, Rick) { expectCreated } + // Attempting to create it again and to get a 409 as a response + _ <- deltaClient.put[Json](s"/resources/$project/$schemaSegment/$id", payload, Rick) { (json, response) => + json should have(`@type`("ResourceAlreadyExists")) + response.status shouldEqual StatusCodes.Conflict + } + // Should be fetched as a schema + _ <- deltaClient.get[Json](s"/schemas/$project/$id", Rick) { expectOk } + } yield succeed + + } } }