Skip to content

Commit

Permalink
Better test utils for StoredEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmin-marginean committed May 13, 2024
1 parent df2416d commit 8bfb749
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
invirtVersion = 0.9.8
invirtVersion = 0.9.9
kotlinVersion = 1.9.23
http4kVersion = 5.17.0.0
mockkVersion = 1.13.9
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class CollectionTest : StringSpec() {
collection.countDocuments() shouldBe 1

entity2 shouldBeSameEntity entity1
entity2 shouldBeUpdateOf entity1
entity2 shouldBeNextUpdateOf entity1
}

"collectionName" {
Expand Down
12 changes: 12 additions & 0 deletions invirt-test/src/main/kotlin/invirt/test/mongo-assertions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,24 @@ import com.mongodb.kotlin.client.MongoCollection
import invirt.mongodb.StoredEntity
import io.kotest.assertions.withClue
import io.kotest.matchers.equality.shouldBeEqualToIgnoringFields
import io.kotest.matchers.longs.shouldBeGreaterThan
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import org.bson.Document
import java.time.temporal.ChronoUnit

infix fun StoredEntity.shouldBeUpdateOf(other: StoredEntity) {
val thisUpdatedAt = this.updatedAt.truncatedTo(ChronoUnit.MILLIS)
val otherUpdatedAt = other.updatedAt.truncatedTo(ChronoUnit.MILLIS)
withClue("$thisUpdatedAt is not after $otherUpdatedAt") {
thisUpdatedAt.isAfter(otherUpdatedAt) shouldBe true
}
withClue("$version is not greater than ${other.version} ") {
version shouldBeGreaterThan other.version
}
}

infix fun StoredEntity.shouldBeNextUpdateOf(other: StoredEntity) {
val thisUpdatedAt = this.updatedAt.truncatedTo(ChronoUnit.MILLIS)
val otherUpdatedAt = other.updatedAt.truncatedTo(ChronoUnit.MILLIS)
withClue("$thisUpdatedAt is not after $otherUpdatedAt") {
Expand Down

0 comments on commit 8bfb749

Please sign in to comment.