-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0140a9a
commit c5b841b
Showing
13 changed files
with
180 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/test/scala/fr/loicknuchel/safeql/models/ExceptionsSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package fr.loicknuchel.safeql.models | ||
|
||
import fr.loicknuchel.safeql.testingutils.BaseSpec | ||
|
||
class ExceptionsSpec extends BaseSpec { | ||
private val e1 = new Exception("an error") | ||
private val e2 = new Exception("an other error") | ||
private val m = MultiException(e1, e2) | ||
|
||
describe("Exceptions") { | ||
describe("MultiException") { | ||
it("should carry multiple exceptions") { | ||
m.getMessage shouldBe "\n - an error\n - an other error" | ||
m.getLocalizedMessage shouldBe "\n - an error\n - an other error" | ||
m.getStackTrace shouldBe e1.getStackTrace | ||
m.getCause shouldBe e1.getCause | ||
} | ||
} | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
src/test/scala/fr/loicknuchel/safeql/models/MultiExceptionSpec.scala
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
src/test/scala/fr/loicknuchel/safeql/models/PageSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package fr.loicknuchel.safeql.models | ||
|
||
import fr.loicknuchel.safeql.testingutils.BaseSpec | ||
|
||
class PageSpec extends BaseSpec { | ||
describe("Page") { | ||
describe("Params") { | ||
it("should have all default values") { | ||
Page.Params().page shouldBe 1 // testing the empty constructor | ||
} | ||
it("should have setters") { | ||
val p = Page.Params() | ||
|
||
p.page shouldBe 1 | ||
p.page(2).page shouldBe 2 | ||
|
||
p.pageSize shouldBe 20 | ||
p.pageSize(2).pageSize shouldBe 2 | ||
|
||
p.search shouldBe None | ||
p.search("q").search shouldBe Some("q") | ||
|
||
p.orderBy shouldBe List() | ||
p.orderBy("name,date", "score").orderBy shouldBe List("name", "date", "score") | ||
|
||
p.filters shouldBe Map() | ||
p.filters("type" -> "meetup", "future" -> "true").filters shouldBe Map("type" -> "meetup", "future" -> "true") | ||
|
||
p.nullsFirst shouldBe false | ||
p.withNullsFirst.nullsFirst shouldBe true | ||
} | ||
it("should clean arguments on orderBy setter") { | ||
val p = Page.Params() | ||
p.orderBy("a,,b ,c", "d,e").orderBy shouldBe List("a", "b", "c", "d", "e") | ||
} | ||
it("should update order by only when empty") { | ||
val p = Page.Params() | ||
p.defaultOrderBy("b").orderBy shouldBe List("b") | ||
p.orderBy("a").defaultOrderBy("b").orderBy shouldBe List("a") | ||
} | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/scala/fr/loicknuchel/safeql/testingutils/CLI.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package fr.loicknuchel.safeql.testingutils | ||
|
||
import cats.data.NonEmptyList | ||
import cats.effect.IO | ||
import fr.loicknuchel.safeql.gen.Generator | ||
import fr.loicknuchel.safeql.gen.writer.ScalaWriter.{DatabaseConfig, FieldConfig, SchemaConfig, TableConfig} | ||
import fr.loicknuchel.safeql.gen.writer.{ScalaWriter, Writer} | ||
|
||
object CLI { | ||
def main(args: Array[String]): Unit = { | ||
GenerateSampleDatabase.run().unsafeRunSync() | ||
println("Done") | ||
} | ||
|
||
object GenerateSampleDatabase { | ||
val writer: ScalaWriter = ScalaWriter( | ||
directory = "src/test/scala", | ||
packageName = "fr.loicknuchel.safeql.testingutils.database", | ||
identifierStrategy = Writer.IdentifierStrategy.upperCase, | ||
config = DatabaseConfig( | ||
scaladoc = _ => Some("Hello"), | ||
imports = List("fr.loicknuchel.safeql.testingutils.Entities._"), | ||
schemas = Map("PUBLIC" -> SchemaConfig(tables = Map( | ||
"users" -> TableConfig(alias = Some("u"), fields = Map( | ||
"id" -> FieldConfig(customType = Some("User.Id")))), | ||
"categories" -> TableConfig(alias = "c", sort = TableConfig.Sort("name", NonEmptyList.of("-name", "id")), search = List("name"), fields = Map( | ||
"id" -> FieldConfig(customType = Some("Category.Id")))), | ||
"posts" -> TableConfig(alias = Some("p"), fields = Map( | ||
"id" -> FieldConfig(customType = Some("Post.Id")))) | ||
))))) | ||
|
||
def run(): IO[Unit] = { | ||
Generator.flyway("classpath:sql_migrations").writer(writer).generate() | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters