Skip to content

Commit

Permalink
Fix #572: add Integration Tests to verify empty JSON Object is valid …
Browse files Browse the repository at this point in the history
…for `sort` for `find()`/`findOne()`
  • Loading branch information
tatu-at-datastax committed Oct 20, 2023
1 parent 48dcd7d commit 61a28c7
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,41 @@ public void byId() {
.body("data.documents", hasSize(1));
}

// https://github.com/stargate/jsonapi/issues/572 -- is passing empty Object for "sort" ok?
@Test
public void byIdEmptySort() {
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(
"""
{
"find": {
"filter" : {"_id" : "doc1"},
"sort": { }
}
}
""")
.when()
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
.statusCode(200)
.body("status", is(nullValue()))
.body("errors", is(nullValue()))
.body(
"data.documents[0]",
jsonEquals(
"""
{
"_id": "doc1",
"username": "user1",
"active_user" : true,
"date" : {"$date": 1672531200000}
}
"""))
.body("data.documents", hasSize(1));
}

@Test
public void byDateId() {
String json =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,19 +209,42 @@ public void noFilterSortDescending() {

@Test
public void byId() {
String json =
"""
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(
"""
{
"findOne": {
"filter" : {"_id" : "doc1"}
}
}
""";
""")
.when()
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
.statusCode(200)
.body("data.document", is(not(nullValue())))
.body("data.document", jsonEquals(DOC1_JSON))
.body("status", is(nullValue()))
.body("errors", is(nullValue()));
}

// https://github.com/stargate/jsonapi/issues/572 -- is passing empty Object for "sort" ok?
@Test
public void byIdEmptySort() {
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(json)
.body(
"""
{
"findOne": {
"filter": {"_id" : "doc1"},
"sort": {}
}
}
""")
.when()
.post(CollectionResource.BASE_PATH, namespaceName, collectionName)
.then()
Expand Down

0 comments on commit 61a28c7

Please sign in to comment.