From 3944cafc48e68e90f77c9aa81ab74a4fbbbb5cc6 Mon Sep 17 00:00:00 2001 From: Tatu Saloranta <87213665+tatu-at-datastax@users.noreply.github.com> Date: Mon, 13 Mar 2023 20:19:43 -0700 Subject: [PATCH] Add more ITs for $min/$max based on code review for #233 impl (#256) --- .../api/v1/UpdateOneIntegrationTest.java | 258 ++++++++++++++++++ 1 file changed, 258 insertions(+) diff --git a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/UpdateOneIntegrationTest.java b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/UpdateOneIntegrationTest.java index 6d3ddbb235..ec724b9a3f 100644 --- a/src/test/java/io/stargate/sgv2/jsonapi/api/v1/UpdateOneIntegrationTest.java +++ b/src/test/java/io/stargate/sgv2/jsonapi/api/v1/UpdateOneIntegrationTest.java @@ -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 @@ -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