Skip to content

Commit

Permalink
Only use POST for generating resources
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Dumas committed Sep 22, 2023
1 parent 5622e20 commit dafc290
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ 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")
}
}

"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
Expand All @@ -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"""{
Expand All @@ -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"""
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/paradox/docs/delta/api/trial.md
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit dafc290

Please sign in to comment.