Skip to content

Commit

Permalink
Add more ITs for $min/$max based on code review for #233 impl (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatu-at-datastax authored Mar 14, 2023
1 parent ae3309c commit 3944caf
Showing 1 changed file with 258 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,135 @@ public void findByColumnAndMin() {
.statusCode(200)
.body("data.docs[0]", jsonEquals(expectedDoc));
}

@Test
public void findByColumnMinNonNumeric() {
insertDoc(
"""
{
"_id": "update_doc_min_text",
"start": "abc",
"end": "xyz"
}
""");
String updateJson =
"""
{
"updateOne": {
"filter" : {"_id" : "update_doc_min_text"},
"update" : {
"$min" : {
"start": "fff",
"end" : "fff"
}
}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(updateJson)
.when()
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("status.matchedCount", is(1))
.body("status.modifiedCount", is(1))
.body("errors", is(nullValue()));

// assert state after update: only "end" changed
String expectedDoc =
"""
{
"_id": "update_doc_min_text",
"start": "abc",
"end": "fff"
}
""";
String findJson =
"""
{
"find": {
"filter" : {"_id" : "update_doc_min_text"}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(findJson)
.when()
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("data.docs[0]", jsonEquals(expectedDoc));
}

@Test
public void findByColumnMinMixedTypes() {
insertDoc(
"""
{
"_id": "update_doc_min_mixed",
"start": "abc",
"end": "xyz"
}
""");
String updateJson =
"""
{
"updateOne": {
"filter" : {"_id" : "update_doc_min_mixed"},
"update" : {
"$min" : {
"start": 123,
"end" : true
}
}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(updateJson)
.when()
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("status.matchedCount", is(1))
.body("status.modifiedCount", is(1))
.body("errors", is(nullValue()));

// assert state after update: only "start" changed (numbers before strings), not
// "end" (boolean after strings)
String expectedDoc =
"""
{
"_id": "update_doc_min_mixed",
"start": 123,
"end": "xyz"
}
""";
String findJson =
"""
{
"find": {
"filter" : {"_id" : "update_doc_min_mixed"}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(findJson)
.when()
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("data.docs[0]", jsonEquals(expectedDoc));
}
}

@Nested
Expand Down Expand Up @@ -1255,6 +1384,135 @@ public void findByColumnAndMax() {
.statusCode(200)
.body("data.docs[0]", jsonEquals(expectedDoc));
}

@Test
public void findByColumnMaxNonNumeric() {
insertDoc(
"""
{
"_id": "update_doc_max_text",
"start": "abc",
"end": "xyz"
}
""");
String updateJson =
"""
{
"updateOne": {
"filter" : {"_id" : "update_doc_max_text"},
"update" : {
"$max" : {
"start": "fff",
"end" : "fff"
}
}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(updateJson)
.when()
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("status.matchedCount", is(1))
.body("status.modifiedCount", is(1))
.body("errors", is(nullValue()));

// assert state after update: only "start" changed
String expectedDoc =
"""
{
"_id": "update_doc_max_text",
"start": "fff",
"end": "xyz"
}
""";
String findJson =
"""
{
"find": {
"filter" : {"_id" : "update_doc_max_text"}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(findJson)
.when()
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("data.docs[0]", jsonEquals(expectedDoc));
}

@Test
public void findByColumnMaxMixedTypes() {
insertDoc(
"""
{
"_id": "update_doc_max_mixed",
"start": "abc",
"end": "xyz"
}
""");
String updateJson =
"""
{
"updateOne": {
"filter" : {"_id" : "update_doc_max_mixed"},
"update" : {
"$max" : {
"start": 123,
"end" : true
}
}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(updateJson)
.when()
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("status.matchedCount", is(1))
.body("status.modifiedCount", is(1))
.body("errors", is(nullValue()));

// assert state after update: only "end" changed (booleans after Strings), not
// "start" (numbers before Strings)
String expectedDoc =
"""
{
"_id": "update_doc_max_mixed",
"start": "abc",
"end": true
}
""";
String findJson =
"""
{
"find": {
"filter" : {"_id" : "update_doc_max_mixed"}
}
}
""";
given()
.header(HttpConstants.AUTHENTICATION_TOKEN_HEADER_NAME, getAuthToken())
.contentType(ContentType.JSON)
.body(findJson)
.when()
.post(CollectionResource.BASE_PATH, keyspaceId.asInternal(), collectionName)
.then()
.statusCode(200)
.body("data.docs[0]", jsonEquals(expectedDoc));
}
}

@Nested
Expand Down

0 comments on commit 3944caf

Please sign in to comment.