Skip to content

Commit

Permalink
fix: fix not compiling test for schema
Browse files Browse the repository at this point in the history
  • Loading branch information
QuadStingray authored and Simon Siedler committed Oct 22, 2024
1 parent 6b9dca2 commit d2f9727
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/test/scala/dev/mongocamp/driver/mongodb/schema/SchemaSpec.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.mongocamp.driver.mongodb.schema

import dev.mongocamp.driver.mongodb.test.TestDatabase.{PersonDAO, PersonDocumentDAO}
import dev.mongocamp.driver.mongodb.test.TestDatabase.{ PersonDAO, PersonDocumentDAO }
import dev.mongocamp.driver.mongodb._
import dev.mongocamp.driver.mongodb.relation.RelationDemoDatabase._
import org.specs2.mutable.{Before, Specification}
import org.specs2.mutable.{ Before, Specification }

import scala.util.Try

Expand All @@ -14,25 +14,25 @@ class SchemaSpec extends Specification with Before {
"Schema" should {
"analyse Json Schema from document dao" in {
// #region schema-analysis
val schemaExplorer = new SchemaExplorer()
val schemaExplorer = new SchemaExplorer()
val schemaAnalysis = schemaExplorer.analyzeSchema(PersonDocumentDAO)
// #endregion schema-analysis
schemaJson.contains("\"$schema\":\"https://json-schema.org/draft/2020-12/schema\"") must beTrue
schemaJson.contains("\"Friends\":") must beTrue
schemaJson.contains("\"title\":\"Friends\"") must beTrue
schemaJson.contains("\"People\":") must beTrue
schemaJson.contains("\"title\":\"People\"") must beTrue
val idPattern1 = schemaJson.contains("\"_id\":{\"pattern\":\"^([a-fA-F0-9]{2})+$\",\"type\":\"string\"}")
val idPattern2 = schemaJson.contains("\"_id\":{\"type\":\"string\",\"pattern\":\"^([a-fA-F0-9]{2})+$\"}")
(idPattern1 || idPattern2) must beTrue
schemaJson.contains("\"isActive\":{\"type\":\"boolean\"}") must beTrue
schemaAnalysis.count must beEqualTo(200)
schemaAnalysis.sample must beEqualTo(200)
schemaAnalysis.percentageOfAnalysed must beEqualTo(1.0)
schemaAnalysis.fields.size must beEqualTo(20)
val idField = schemaAnalysis.fields.head
idField.name must beEqualTo("_id")
idField.fieldTypes.head.fieldType must beEqualTo("objectId")
idField.fieldTypes.head.count must beEqualTo(200)
idField.fieldTypes.head.percentageOfParent must beEqualTo(1.0)
}

"detect Json Schema from document dao" in {
// #region schema-explorer
val schemaExplorer = new SchemaExplorer()
val schema = schemaExplorer.detectSchema(PersonDocumentDAO)
val schemaJson = schema.toJson
val schemaExplorer = new SchemaExplorer()
val schema = schemaExplorer.detectSchema(PersonDocumentDAO)
val schemaJson = schema.toJson
// #endregion schema-explorer
schemaJson.contains("\"$schema\":\"https://json-schema.org/draft/2020-12/schema\"") must beTrue
schemaJson.contains("\"Friends\":") must beTrue
Expand Down

0 comments on commit d2f9727

Please sign in to comment.