Skip to content

Commit

Permalink
Fixes #2615 (#2616)
Browse files Browse the repository at this point in the history
* Fixes #2615

* Fixed checkstyle issue

Co-authored-by: Aaron Klish <[email protected]>
  • Loading branch information
aklish and Aaron Klish authored Apr 19, 2022
1 parent c8dd203 commit 18df59e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ private List<Supplier<Pair<Integer, JsonNode>>> handleActions(PatchRequestScope
}
String[] combined = ArrayUtils.addAll(rootUri.split("/"), action.patch.getPath().split("/"));
String fullPath = String.join("/", combined).replace("/-", "");
switch (action.patch.getOperation()) {

Patch.Operation operation = action.patch.getOperation();
if (operation == null) {
throw new InvalidEntityBodyException("Patch extension operation cannot be null.");
}
switch (operation) {
case ADD:
result = handleAddOp(fullPath, action.patch.getValue(), requestScope, action);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static com.yahoo.elide.test.jsonapi.elements.Relation.TO_ONE;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.Matchers.nullValue;
Expand Down Expand Up @@ -1442,6 +1443,22 @@ public void createChildRelateExisting() {
.body(equalTo(expected));
}

@Test
public void invalidPatchNullOp() {
String request = jsonParser.getJson("/ResourceIT/patchExtNullOp.req.json");

String detail = "Patch extension operation cannot be null.";

given()
.contentType(JSONAPI_CONTENT_TYPE_WITH_JSON_PATCH_EXTENSION)
.accept(JSONAPI_CONTENT_TYPE_WITH_JSON_PATCH_EXTENSION)
.body(request)
.patch("/")
.then()
.statusCode(HttpStatus.SC_BAD_REQUEST)
.body("errors[0].detail[0]", containsString(Encode.forHtml(detail)));
}

@Test
public void invalidPatchMissingId() {
String request = jsonParser.getJson("/ResourceIT/invalidPatchMissingId.req.json");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[
{
"op": null,
"path": "/book",
"value": {
"type": "book",
"id": "123",
"attributes": {
"title": "My New Book"
}
}
}
]

0 comments on commit 18df59e

Please sign in to comment.