From dafc29040632e93d534c1b6259a289e0cb7a9722 Mon Sep 17 00:00:00 2001 From: Simon Dumas Date: Fri, 22 Sep 2023 11:22:21 +0200 Subject: [PATCH] Only use POST for generating resources --- .../delta/routes/ResourcesTrialRoutesSpec.scala | 10 +++++----- docs/src/main/paradox/docs/delta/api/trial.md | 2 +- .../tests/resources/ResourcesTrialSpec.scala | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesTrialRoutesSpec.scala b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesTrialRoutesSpec.scala index 03fb0cfa08..7661a1279f 100644 --- a/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesTrialRoutesSpec.scala +++ b/delta/app/src/test/scala/ch/epfl/bluebrain/nexus/delta/routes/ResourcesTrialRoutesSpec.scala @@ -129,7 +129,7 @@ class ResourcesTrialRoutesSpec extends BaseRouteSpec with ResourceInstanceFixtur "fail to generate a resource for a user without access" in { val payload = json"""{ "resource": $validSource }""" - Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> routes ~> check { + Post(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> routes ~> check { response.status shouldEqual StatusCodes.Forbidden response.asJson shouldEqual jsonContentOf("errors/authorization-failed.json") } @@ -137,7 +137,7 @@ class ResourcesTrialRoutesSpec extends BaseRouteSpec with ResourceInstanceFixtur "generate a resource without passing a schema" in { val payload = json"""{ "resource": $validSource }""" - Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check { + Post(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check { response.status shouldEqual StatusCodes.OK val jsonResponse = response.asJsonObject jsonResponse("schema") shouldBe empty @@ -159,7 +159,7 @@ class ResourcesTrialRoutesSpec extends BaseRouteSpec with ResourceInstanceFixtur "fails to generate a resource when passing an invalid new schema" in { val payload = json"""{ "schema": { "invalid": "xxx" }, "resource": $validSource }""" - Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check { + Post(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check { response.status shouldEqual StatusCodes.BadRequest response.asJson shouldEqual json"""{ @@ -174,7 +174,7 @@ class ResourcesTrialRoutesSpec extends BaseRouteSpec with ResourceInstanceFixtur "fails to generate a resource when the resource payload is invalid and without passing a schema" in { val payload = json"""{ "resource": $invalidSource }""" - Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check { + Post(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check { response.status shouldEqual StatusCodes.OK response.asJson shouldEqual json""" @@ -190,7 +190,7 @@ class ResourcesTrialRoutesSpec extends BaseRouteSpec with ResourceInstanceFixtur "fail to generate a resource passing a new schema" in { val payload = json"""{ "schema": $schemaSource, "resource": $invalidSource }""" - Get(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check { + Post(s"/v1/trial/resources/$projectRef/", payload.toEntity) ~> asAlice ~> routes ~> check { response.status shouldEqual StatusCodes.OK val jsonResponse = response.asJsonObject jsonResponse("schema") should not be empty diff --git a/docs/src/main/paradox/docs/delta/api/trial.md b/docs/src/main/paradox/docs/delta/api/trial.md index 4809dd1f20..ec7330c201 100644 --- a/docs/src/main/paradox/docs/delta/api/trial.md +++ b/docs/src/main/paradox/docs/delta/api/trial.md @@ -19,7 +19,7 @@ It applies the same validation steps than the creation/update of resources, the that nothing is persisted. ``` -GET|POST /v1/trial/resources/{org_label}/{project_label} +POST /v1/trial/resources/{org_label}/{project_label} { "schema": {schema}, diff --git a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/resources/ResourcesTrialSpec.scala b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/resources/ResourcesTrialSpec.scala index 363eb2a9af..5bb562025d 100644 --- a/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/resources/ResourcesTrialSpec.scala +++ b/tests/src/test/scala/ch/epfl/bluebrain/nexus/tests/resources/ResourcesTrialSpec.scala @@ -43,15 +43,15 @@ class ResourcesTrialSpec extends BaseSpec with CirceEq { def schema = root.schema.`@id`.string.getOption(_) "fail for a user without access" in { - deltaClient.getWithBody[Json](s"/trial/resources/$ref/", payloadWithoutSchema, Alice)(expectForbidden) + deltaClient.post[Json](s"/trial/resources/$ref/", payloadWithoutSchema, Alice)(expectForbidden) } "fail for an unknown project" in { - deltaClient.getWithBody[Json](s"/trial/resources/$org/xxx/", payloadWithoutSchema, Alice)(expectForbidden) + deltaClient.post[Json](s"/trial/resources/$org/xxx/", payloadWithoutSchema, Alice)(expectForbidden) } "succeed for a payload without schema" in { - deltaClient.getWithBody[Json](s"/trial/resources/$ref/", payloadWithoutSchema, Bob) { (json, response) => + deltaClient.post[Json](s"/trial/resources/$ref/", payloadWithoutSchema, Bob) { (json, response) => response.status shouldEqual StatusCodes.OK resultId(json).value shouldEqual resourceId schema(json) shouldBe empty @@ -60,7 +60,7 @@ class ResourcesTrialSpec extends BaseSpec with CirceEq { } "succeed for a payload with an existing schema" in { - deltaClient.getWithBody[Json](s"/trial/resources/$ref/", payloadWithExistingSchema, Bob) { (json, response) => + deltaClient.post[Json](s"/trial/resources/$ref/", payloadWithExistingSchema, Bob) { (json, response) => response.status shouldEqual StatusCodes.OK resultId(json).value shouldEqual resourceId schema(json) shouldBe empty @@ -69,7 +69,7 @@ class ResourcesTrialSpec extends BaseSpec with CirceEq { } "succeed for a payload with a new schema" in { - deltaClient.getWithBody[Json](s"/trial/resources/$ref/", payloadWithNewSchema, Bob) { (json, response) => + deltaClient.post[Json](s"/trial/resources/$ref/", payloadWithNewSchema, Bob) { (json, response) => response.status shouldEqual StatusCodes.OK resultId(json).value shouldEqual resourceId schema(json).value shouldBe newSchemaId @@ -79,7 +79,7 @@ class ResourcesTrialSpec extends BaseSpec with CirceEq { "fail for a resource with an invalid context without generating any schema" in { val payload = json"""{ "resource": { "@context": [ "https://bbp.epfl.ch/unknown-context" ], "test": "fail" } }""" - deltaClient.getWithBody[Json](s"/trial/resources/$ref/", payload, Bob) { (json, response) => + deltaClient.post[Json](s"/trial/resources/$ref/", payload, Bob) { (json, response) => response.status shouldEqual StatusCodes.OK resultId(json) shouldBe empty schema(json) shouldBe empty @@ -90,7 +90,7 @@ class ResourcesTrialSpec extends BaseSpec with CirceEq { "fail for a resource with an invalid context but also returning the generated schema" in { val resourcePayload = json"""{ "@context": [ "https://bbp.epfl.ch/unknown-context" ], "test": "fail" }""" val payload = json"""{ "schema": $newSchemaPayload, "resource": $resourcePayload }""" - deltaClient.getWithBody[Json](s"/trial/resources/$ref/", payload, Bob) { (json, response) => + deltaClient.post[Json](s"/trial/resources/$ref/", payload, Bob) { (json, response) => response.status shouldEqual StatusCodes.OK resultId(json) shouldBe empty schema(json).value shouldBe newSchemaId @@ -101,7 +101,7 @@ class ResourcesTrialSpec extends BaseSpec with CirceEq { "fail for a resource when shacl validation fails returning the generated " in { val resourcePayload = SimpleResource.sourcePayloadWithType("nxv:UnexpectedType", 99) val payload = json"""{ "schema": $newSchemaPayload ,"resource": $resourcePayload }""" - deltaClient.getWithBody[Json](s"/trial/resources/$ref/", payload, Bob) { (json, response) => + deltaClient.post[Json](s"/trial/resources/$ref/", payload, Bob) { (json, response) => response.status shouldEqual StatusCodes.OK resultId(json) shouldBe empty schema(json).value shouldBe newSchemaId