From b9fcf53075607eda2cec76dcebfe55dcbddb45d5 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Wed, 20 Nov 2024 17:24:04 +0100 Subject: [PATCH] chore: fix formatting tests --- .../mongosh/MongoshDialectFormatter.kt | 4 +-- .../mongosh/MongoshDialectFormatterTest.kt | 34 ++++++++++++------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/packages/mongodb-dialects/mongosh/src/main/kotlin/com/mongodb/jbplugin/dialects/mongosh/MongoshDialectFormatter.kt b/packages/mongodb-dialects/mongosh/src/main/kotlin/com/mongodb/jbplugin/dialects/mongosh/MongoshDialectFormatter.kt index d27183cc..3a9eb8b7 100644 --- a/packages/mongodb-dialects/mongosh/src/main/kotlin/com/mongodb/jbplugin/dialects/mongosh/MongoshDialectFormatter.kt +++ b/packages/mongodb-dialects/mongosh/src/main/kotlin/com/mongodb/jbplugin/dialects/mongosh/MongoshDialectFormatter.kt @@ -24,12 +24,12 @@ import org.owasp.encoder.Encode object MongoshDialectFormatter : DialectFormatter { override fun formatQuery( query: Node, - explain: Boolean + explain: Boolean, ): OutputQuery { val isAggregate = isAggregate(query) val canEmitAggregate = canEmitAggregate(query) - val outputString = MongoshBackend(prettyPrint = !explain).apply { + val outputString = MongoshBackend(prettyPrint = explain).apply { if (isAggregate && !canEmitAggregate) { emitComment("Only aggregates with a single match stage can be converted.") return@apply diff --git a/packages/mongodb-dialects/mongosh/src/test/kotlin/com/mongodb/jbplugin/dialects/mongosh/MongoshDialectFormatterTest.kt b/packages/mongodb-dialects/mongosh/src/test/kotlin/com/mongodb/jbplugin/dialects/mongosh/MongoshDialectFormatterTest.kt index 80873277..2ee13849 100644 --- a/packages/mongodb-dialects/mongosh/src/test/kotlin/com/mongodb/jbplugin/dialects/mongosh/MongoshDialectFormatterTest.kt +++ b/packages/mongodb-dialects/mongosh/src/test/kotlin/com/mongodb/jbplugin/dialects/mongosh/MongoshDialectFormatterTest.kt @@ -21,7 +21,7 @@ class MongoshDialectFormatterTest { var collection = "" var database = "" - db.getSiblingDB(database).getCollection(collection).find({ "myField": "myVal", }) + db.getSiblingDB(database).getCollection(collection).find({"myField": "myVal", }) """.trimIndent() ) { Node( @@ -53,7 +53,7 @@ class MongoshDialectFormatterTest { assertGeneratedQuery( """ - db.getSiblingDB("myDb").getCollection("myColl").find({ "myField": "myVal", }) + db.getSiblingDB("myDb").getCollection("myColl").find({"myField": "myVal", }) """.trimIndent() ) { Node( @@ -87,7 +87,7 @@ class MongoshDialectFormatterTest { assertGeneratedQuery( """ - db.getSiblingDB("myDb").getCollection("myColl").deleteMany({ "myField": "myVal", }) + db.getSiblingDB("myDb").getCollection("myColl").deleteMany({"myField": "myVal", }) """.trimIndent() ) { Node( @@ -122,8 +122,12 @@ class MongoshDialectFormatterTest { """ var collection = "" var database = "" - - db.getSiblingDB(database).getCollection(collection).explain().find({ "myField": "myVal", }) + + db.getSiblingDB(database) + .getCollection(collection) + .explain().find( + {"myField": "myVal", } + ) """.trimIndent(), explain = true ) { @@ -157,7 +161,7 @@ class MongoshDialectFormatterTest { var collection = "" var database = "" - db.getSiblingDB(database).getCollection(collection).aggregate([ { "${"$"}match": { "myField": "myVal"}}]) + db.getSiblingDB(database).getCollection(collection).aggregate([{"${"$"}match": {"myField": "myVal"}}]) """.trimIndent(), explain = false ) { @@ -208,8 +212,14 @@ class MongoshDialectFormatterTest { """ var collection = "" var database = "" - - db.getSiblingDB(database).getCollection(collection).explain().aggregate([ { "${"$"}match": { "myField": "myVal"}}]) + + db.getSiblingDB(database) + .getCollection(collection) + .explain().aggregate( + [ + {"${'$'}match": {"myField": "myVal"}} + ] + ) """.trimIndent(), explain = true ) { @@ -262,7 +272,7 @@ class MongoshDialectFormatterTest { var collection = "" var database = "" - db.getSiblingDB(database).getCollection(collection).find({ "${"$"}$operator": [ { "myField": "myVal"}, ]}) + db.getSiblingDB(database).getCollection(collection).find({"${"$"}$operator": [{"myField": "myVal"}, ]}) """.trimIndent() ) { Node( @@ -295,7 +305,7 @@ class MongoshDialectFormatterTest { assertGeneratedQuery( """ - db.getSiblingDB("myDb").getCollection("myColl").find({ "myField": { "${"$"}not": "myVal"}, }) + db.getSiblingDB("myDb").getCollection("myColl").find({"myField": {"${"$"}not": "myVal"}, }) """.trimIndent() ) { Node( @@ -348,7 +358,7 @@ class MongoshDialectFormatterTest { var collection = "" var database = "" - db.getSiblingDB(database).getCollection(collection).find({ "myField": { "${"$"}$operator": "myVal"}, }) + db.getSiblingDB(database).getCollection(collection).find({"myField": {"${"$"}$operator": "myVal"}, }) """.trimIndent() ) { Node( @@ -383,7 +393,7 @@ class MongoshDialectFormatterTest { var collection = "" var database = "" - db.getSiblingDB(database).getCollection(collection).find({ "myField": { "${"$"}$operator": [1, 2]}, }) + db.getSiblingDB(database).getCollection(collection).find({"myField": {"${"$"}$operator": [1, 2]}, }) """.trimIndent() ) { Node(