Skip to content

Commit

Permalink
fix wrong tests
Browse files Browse the repository at this point in the history
switch back to annotations can have null value
  • Loading branch information
zingmane committed Feb 7, 2025
1 parent 3d797c0 commit 262f02c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,7 @@ class TableauxController(
value: String
)(implicit user: TableauxUser): Future[CellLevelAnnotation] = {
logger.info(s"addCellAnnotation $tableId $columnId $rowId $langtags $annotationType $value")
checkArguments(
greaterZero(tableId),
greaterThan(columnId, -1, "columnId"),
greaterZero(rowId),
notNull(value, "value")
)
checkArguments(greaterZero(tableId), greaterThan(columnId, -1, "columnId"), greaterZero(rowId))

for {
table <- repository.retrieveTable(tableId)
Expand All @@ -59,7 +54,7 @@ class TableauxController(
s"Cannot add an annotation with langtags to a language neutral cell (table: $tableId, column: $columnId)"
)
}
_ = if (annotationType == FlagAnnotationType && langtags.isEmpty) {
_ = if (annotationType == FlagAnnotationType && value == "needs_translation" && langtags.isEmpty) {
throw UnprocessableEntityException(s"Cannot add/change an 'needs_translation' annotation without langtags")
}
_ <- roleModel.checkAuthorization(EditCellAnnotation, ComparisonObjects(table))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,6 @@ class CellLevelAnnotationsTest extends TableauxTestBase {
}
}

@Test
def addInvalidAnnotations_invalidValue(implicit c: TestContext): Unit = {
exceptionTest("error.arguments") {
for {
(tableId, _) <- createTableWithMultilanguageColumns("Test")

// empty row
result <- sendRequest("POST", s"/tables/$tableId/rows")
rowId = result.getLong("id")

_ <- sendRequest("POST", s"/tables/$tableId/columns/1/rows/$rowId/annotations", Json.obj("type" -> "flag"))

} yield ()
}
}

@Test
def addAnnotations_emptyLangtags(implicit c: TestContext): Unit = {
exceptionTest("unprocessable.entity") {
Expand Down Expand Up @@ -477,11 +461,10 @@ class CellLevelAnnotationsTest extends TableauxTestBase {

rowJsonAfterDelete <- sendRequest("GET", s"/tables/$tableId/rows/$rowId")
} yield {
val exceptedFlags = Json
.arr(Json.obj("langtags" -> Json.arr("de", "en"), "type" -> "error", "value" -> null))
val exceptedFlags = Json.arr(Json.obj("langtags" -> Json.arr("de", "en"), "type" -> "error", "value" -> null))

val exceptedFlagsAfterDelete = Json
.arr(Json.obj("langtags" -> Json.arr("de"), "type" -> "error", "value" -> null))
val exceptedFlagsAfterDelete =
Json.arr(Json.obj("langtags" -> Json.arr("de"), "type" -> "error", "value" -> null))

assertJSONEquals(exceptedFlags, rowJson.getJsonArray("annotations").getJsonArray(0))
assertJSONEquals(exceptedFlagsAfterDelete, rowJsonAfterDelete.getJsonArray("annotations").getJsonArray(0))
Expand Down Expand Up @@ -574,17 +557,7 @@ class CellLevelAnnotationsTest extends TableauxTestBase {
)
)

assertJSONEquals(exceptedColumn1FlagsAfterDelete, rowJson2.getJsonArray("annotations").getJsonArray(0))
assertFalse(
"should not include null field",
rowJson2
.getJsonArray("annotations")
.getJsonArray(0)
.getJsonObject(0)
.containsKey("langtaga")
); // JSON serialization from the server should not include null fields, such as "versionedFlows": null

assertNull(rowJson2.getJsonArray("annotations").getJsonArray(1))
assertNull(rowJson2.getJsonArray("annotations"))
}
}
}
Expand Down

0 comments on commit 262f02c

Please sign in to comment.