Skip to content

Commit

Permalink
Fix it test
Browse files Browse the repository at this point in the history
  • Loading branch information
denis_savitsky authored and danslapman committed Feb 4, 2024
1 parent e2a6bad commit 0ce9ed8
Showing 1 changed file with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import scala.concurrent.ExecutionContext

import com.dimafeng.testcontainers.ForAllTestContainer
import com.dimafeng.testcontainers.MongoDBContainer
import com.mongodb.client.model.FindOneAndUpdateOptions
import com.mongodb.client.model.ReturnDocument
import concurrent.duration.DurationInt
import oolong.bson.BsonDecoder
import oolong.dsl.*
Expand All @@ -28,6 +30,7 @@ class OolongMongoUpdateSpec extends AsyncFlatSpec with ForAllTestContainer with
TestClass("1", 1, InnerClass("qwe", 3), Nil, Some(2L), List.empty),
TestClass("2", 2, InnerClass("asd", 0), Nil, None, List.empty),
TestClass("3", 12, InnerClass("sdf", 1), Nil, None, List.empty),
TestClass("4", 13, InnerClass("sdf", 1), List(1), None, List.empty),
TestClass("12345", 12, InnerClass("sdf", 11), Nil, None, List.empty),
)

Expand Down Expand Up @@ -132,39 +135,36 @@ class OolongMongoUpdateSpec extends AsyncFlatSpec with ForAllTestContainer with

it should "update with $addToSet" in {
for {
res <- collection
.updateOne(
upd <- collection
.findOneAndUpdate(
query[TestClass](_.field1 == "0"),
update[TestClass](
_.addToSet(_.field4, 3)
)
),
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
)
.head()
upd <- collection
.find(query[TestClass](_.field1 == "0"))
.head()
.map(BsonDecoder[TestClass].fromBson(_).get)

} yield assert(
res.wasAcknowledged() && res.getModifiedCount == 1 && upd.field4.size == 3
upd.field4 == List(1, 2, 3)
)
}

it should "update with $addToSet using $each" in {
for {
res <- collection
.updateOne(
query[TestClass](_.field1 == "0"),
upd <- collection
.findOneAndUpdate(
query[TestClass](_.field1 == "4"),
update[TestClass](
_.addToSetAll(_.field4, List(4, 5))
)
_.addToSetAll(_.field4, List(2, 3))
),
new FindOneAndUpdateOptions().returnDocument(ReturnDocument.AFTER)
)
.head()
upd <- collection
.find(query[TestClass](_.field1 == "0"))
.head()
.map(BsonDecoder[TestClass].fromBson(_).get)
} yield assert(
res.wasAcknowledged() && res.getModifiedCount == 1 && upd.field4.size == 4
upd.field4 == List(1, 2, 3)
)
}

Expand Down

0 comments on commit 0ce9ed8

Please sign in to comment.