Skip to content

Commit

Permalink
Fix #572: add ITs to verify empty JSON Object is valid for sort of …
Browse files Browse the repository at this point in the history
…`find`/`findOne`, fix as necessary (#576)
  • Loading branch information
tatu-at-datastax authored Oct 23, 2023
1 parent b675e43 commit 69c6037
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@ public record SortClause(@Valid List<SortExpression> sortExpressions) {

public boolean hasVsearchClause() {
return sortExpressions != null
&& sortExpressions.stream()
.findFirst()
.get()
.path()
.equals(DocumentConstants.Fields.VECTOR_EMBEDDING_FIELD);
&& !sortExpressions.isEmpty()
&& sortExpressions.get(0).path().equals(DocumentConstants.Fields.VECTOR_EMBEDDING_FIELD);
}

public boolean hasVectorizeSearchClause() {
return sortExpressions != null
&& sortExpressions.stream()
.findFirst()
.get()
&& !sortExpressions.isEmpty()
&& sortExpressions
.get(0)
.path()
.equals(DocumentConstants.Fields.VECTOR_EMBEDDING_TEXT_FIELD);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,43 @@ 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": {"username" : "user1"},
"projection": {},
"options": {},
"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 69c6037

Please sign in to comment.