Skip to content

Commit 7decb14

Browse files
committed
Update Scala tests for the $and Filter changes
JAVA-3338
1 parent b4afe55 commit 7decb14

File tree

2 files changed

+8
-14
lines changed

2 files changed

+8
-14
lines changed

driver-scala/src/test/scala/org/mongodb/scala/model/FiltersSpec.scala

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,33 +125,27 @@ class FiltersSpec extends BaseSpec {
125125
toBson(model.Filters.and()) should equal(Document("""{$and : []}"""))
126126
}
127127

128-
it should "and should render and without using $and" in {
128+
it should "and should render using $and" in {
129129
toBson(model.Filters.and(model.Filters.eq("x", 1), model.Filters.eq("y", 2))) should equal(
130-
Document("""{x : 1, y : 2}""")
131-
)
132-
}
133-
134-
it should "and should render $and with clashing keys" in {
135-
toBson(model.Filters.and(model.Filters.eq("a", 1), model.Filters.eq("a", 2))) should equal(
136-
Document("""{$and: [{a: 1}, {a: 2}]}""")
130+
Document("""{$and: [{x : 1}, {y : 2}]}""")
137131
)
138132
}
139133

140134
it should "and should flatten multiple operators for the same key" in {
141135
toBson(model.Filters.and(model.Filters.gt("a", 1), model.Filters.lt("a", 9))) should equal(
142-
Document("""{a : {$gt : 1, $lt : 9}}""")
136+
Document("""{$and: [{a : {$gt : 1}}, {a: {$lt : 9}}]}""")
143137
)
144138
}
145139

146140
it should "and should flatten nested" in {
147141
toBson(
148142
model.Filters.and(model.Filters.and(model.Filters.eq("a", 1), model.Filters.eq("b", 2)), model.Filters.eq("c", 3))
149-
) should equal(Document("""{a : 1, b : 2, c : 3}"""))
143+
) should equal(Document("""{$and: [{$and: [{a : 1}, {b : 2}]}, {c : 3}]}"""))
150144
toBson(
151145
model.Filters.and(model.Filters.and(model.Filters.eq("a", 1), model.Filters.eq("a", 2)), model.Filters.eq("c", 3))
152-
) should equal(Document("""{$and:[{a : 1}, {a : 2}, {c : 3}] }"""))
146+
) should equal(Document("""{$and: [{$and:[{a : 1}, {a : 2}]}, {c : 3}] }"""))
153147
toBson(model.Filters.and(model.Filters.lt("a", 1), model.Filters.lt("b", 2))) should equal(
154-
Document("""{a : {$lt : 1}, b : {$lt : 2} }""")
148+
Document("""{$and: [{a : {$lt : 1}}, {b : {$lt : 2} }]}""")
155149
)
156150
toBson(model.Filters.and(model.Filters.lt("a", 1), model.Filters.lt("a", 2))) should equal(
157151
Document("""{$and : [{a : {$lt : 1}}, {a : {$lt : 2}}]}""")
@@ -169,7 +163,7 @@ class FiltersSpec extends BaseSpec {
169163
toBson(
170164
model.Filters
171165
.elemMatch("results", model.Filters.and(model.Filters.eq("product", "xyz"), model.Filters.gt("score", 8)))
172-
) should equal(Document("""{ results : {$elemMatch : {product : "xyz", score : {$gt : 8}}}}"""))
166+
) should equal(Document("""{ results : {$elemMatch : {$and: [{product : "xyz"}, {score : {$gt : 8}}]}}}"""))
173167
}
174168

175169
it should "render $in" in {

driver-scala/src/test/scala/org/mongodb/scala/model/ProjectionsSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class ProjectionsSpec extends BaseSpec {
5959

6060
it should "elemMatch" in {
6161
toBson(model.Projections.elemMatch("x", Filters.and(model.Filters.eq("y", 1), model.Filters.eq("z", 2)))) should equal(
62-
Document("""{x : {$elemMatch : {y : 1, z : 2}}}""")
62+
Document("""{x : {$elemMatch : {$and: [{y : 1}, {z : 2}]}}}""")
6363
)
6464
}
6565

0 commit comments

Comments
 (0)