Skip to content

Commit

Permalink
add test and modify test helper
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmane committed Aug 2, 2024
1 parent 5fec4d9 commit 0360794
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ class ChangeStructureTest extends TableauxTestBase {
}
}

@Test
def changeColumnDecimalDigits(implicit c: TestContext): Unit = okTest {
val postJson = Json.obj("decimalDigits" -> 4)

for {
_ <- createDefaultTable()
resultPost <- sendRequest("POST", "/tables/1/columns/2", postJson)
resultGet <- sendRequest("GET", "/tables/1/columns/2")
} yield {
assertEquals(4, resultGet.getInteger("decimalDigits"))
assertEquals(resultPost, resultGet)
}
}

@Test
def changeColumnKindWhichShouldFail(implicit c: TestContext): Unit = {
okTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class CreateColumnTest extends TableauxTestBase {

def createRichTextColumnJson(name: String) = RequestCreation.Columns().add(RequestCreation.RichTextCol(name)).getJson

def createNumberColumnJson(name: String) = RequestCreation.Columns().add(RequestCreation.NumericCol(name)).getJson
def createNumberColumnJson(name: String, decimalDigits: Option[Int] = None) =
RequestCreation.Columns().add(RequestCreation.NumericCol(name, decimalDigits)).getJson

def createIntegerColumnJson(name: String) = RequestCreation.Columns().add(RequestCreation.IntegerCol(name)).getJson

Expand Down Expand Up @@ -223,6 +224,54 @@ class CreateColumnTest extends TableauxTestBase {
}
}

@Test
def createNumberColumnWithCustomDecimalDigits(implicit c: TestContext): Unit = {
okTest {
val createColumn1 = createNumberColumnJson("column1", None)
val createColumn2 = createNumberColumnJson("column2", Some(5))
val expectedJson = Json.obj(
"status" -> "ok",
"columns" -> Json.arr(
Json
.obj(
"id" -> 1,
"ordering" -> 1,
"multilanguage" -> false,
"identifier" -> false,
"displayName" -> Json.obj(),
"description" -> Json.obj()
)
.mergeIn(createColumn1.getJsonArray("columns").getJsonObject(0))
)
)
val expectedJson2 = Json.obj(
"status" -> "ok",
"columns" -> Json.arr(
Json
.obj(
"id" -> 2,
"ordering" -> 2,
"multilanguage" -> false,
"identifier" -> false,
"displayName" -> Json.obj(),
"description" -> Json.obj()
)
.mergeIn(createColumn2.getJsonArray("columns").getJsonObject(0))
)
)

for {
_ <- sendRequest("POST", "/tables", createTableJson)
test1 <- sendRequest("POST", "/tables/1/columns", createColumn1)
test2 <- sendRequest("POST", "/tables/1/columns", createColumn2)
} yield {
assertJSONEquals(expectedJson, test1)
assertNull(test1.getJsonArray("columns").getJsonObject(0).getInteger("decimalDigits"))
assertJSONEquals(expectedJson2, test2)
}
}
}

@Test
def createIntegerColumn(implicit c: TestContext): Unit = {
okTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ object RequestCreation {

case class RichTextCol(name: String) extends ColumnType("richtext")

case class NumericCol(name: String) extends ColumnType("numeric")
case class NumericCol(override val name: String, decimalDigits: Option[Int] = None) extends ColumnType("numeric") {

override def getJson: JsonObject = {
super.getJson
.mergeIn(
decimalDigits match {
case Some(digits) => Json.obj("decimalDigits" -> digits)
case None => Json.emptyObj()
}
)
}
}

case class IntegerCol(name: String) extends ColumnType("integer")

Expand Down

0 comments on commit 0360794

Please sign in to comment.