Skip to content

Commit

Permalink
chore: fix formatting tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kmruiz committed Nov 20, 2024
1 parent 8663269 commit b9fcf53
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ import org.owasp.encoder.Encode
object MongoshDialectFormatter : DialectFormatter {
override fun <S> formatQuery(
query: Node<S>,
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b9fcf53

Please sign in to comment.