Skip to content

Commit

Permalink
add asserts for totalSize
Browse files Browse the repository at this point in the history
  • Loading branch information
zingmane committed May 17, 2024
1 parent a5923a9 commit f3bb3e2
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 35 deletions.
4 changes: 2 additions & 2 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [Retrieving a specific column](#retrieving-a-specific-column)
- [Retrieving a specific row](#retrieving-a-specific-row)
- [Retrieving a specific cell](#retrieving-a-specific-cell)
- [2.2. Data types & column kinds](#22-data-types--column-kinds)
- [2.2. Data types \& column kinds](#22-data-types--column-kinds)
- [Primitive data types](#primitive-data-types)
- [Examples](#examples)
- [Complex data types](#complex-data-types)
Expand Down Expand Up @@ -155,7 +155,7 @@ Call this endpoint to retrieve all rows of a specific table. Most important part
"page": { // result can be paged with two query parameters offset and limit
"offset": null,
"limit": null,
"totalSize": 18 // total size of this table
"totalSize": 18 // total number of rows depending on filter query parameters. If no filters are set, totalSize is the total number of rows in the table
},
"rows": [
{ // row object
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2238,6 +2238,7 @@
"example": 100
},
"totalSize": {
"description": "Total number of rows depending on filter query parameters. If no filters are set, totalSize is the total number of rows in the table",
"type": "integer",
"example": 315
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ sealed trait Helper extends LinkTestBase {
obj.getJsonArray("rows")
}

def toRowsArrayAndTotalSize(obj: JsonObject): (JsonArray, Long) = {
(obj.getJsonArray("rows"), obj.getJsonObject("page").getLong("totalSize"))
}

def createCardinalityLinkColumn(
tableId: TableId,
toTableId: TableId,
Expand Down Expand Up @@ -1639,26 +1643,48 @@ class RetrieveFinalAndArchivedRows extends LinkTestBase with Helper {
_ <- sendRequest("PATCH", s"/tables/1/rows/6/annotations", Json.obj("final" -> true, "archived" -> false))
_ <- sendRequest("PATCH", s"/tables/1/rows/7/annotations", Json.obj("final" -> true, "archived" -> true))

finalFalse <- sendRequest("GET", s"/tables/1/rows?final=false").map(toRowsArray)
finalTrue <- sendRequest("GET", s"/tables/1/rows?final=true").map(toRowsArray)
archivedFalse <- sendRequest("GET", s"/tables/1/rows?archived=false").map(toRowsArray)
archivedTrue <- sendRequest("GET", s"/tables/1/rows?archived=true").map(toRowsArray)
allRows <- sendRequest("GET", s"/tables/1/rows").map(toRowsArray)
finalFalseAndArchivedFalse <- sendRequest("GET", s"/tables/1/rows?final=false&archived=false").map(toRowsArray)
finalTrueAndArchivedTrue <- sendRequest("GET", s"/tables/1/rows?final=true&archived=true").map(toRowsArray)
finalFalseAndArchivedTrue <- sendRequest("GET", s"/tables/1/rows?final=false&archived=true").map(toRowsArray)
finalTrueAndArchivedFalse <- sendRequest("GET", s"/tables/1/rows?final=true&archived=false").map(toRowsArray)
(allRows, totalSize1) <- sendRequest("GET", s"/tables/1/rows").map(toRowsArrayAndTotalSize)

(finalFalse, totalSize2) <- sendRequest("GET", s"/tables/1/rows?final=false").map(toRowsArrayAndTotalSize)
(finalTrue, totalSize3) <- sendRequest("GET", s"/tables/1/rows?final=true").map(toRowsArrayAndTotalSize)
(archivedFalse, totalSize4) <- sendRequest("GET", s"/tables/1/rows?archived=false").map(toRowsArrayAndTotalSize)
(archivedTrue, totalSize5) <- sendRequest("GET", s"/tables/1/rows?archived=true").map(toRowsArrayAndTotalSize)

(finalFalseAndArchivedFalse, totalSize6) <-
sendRequest("GET", s"/tables/1/rows?final=false&archived=false").map(toRowsArrayAndTotalSize)
(finalTrueAndArchivedTrue, totalSize7) <-
sendRequest("GET", s"/tables/1/rows?final=true&archived=true").map(toRowsArrayAndTotalSize)
(finalFalseAndArchivedTrue, totalSize8) <-
sendRequest("GET", s"/tables/1/rows?final=false&archived=true").map(toRowsArrayAndTotalSize)
(finalTrueAndArchivedFalse, totalSize9) <-
sendRequest("GET", s"/tables/1/rows?final=true&archived=false").map(toRowsArrayAndTotalSize)

(finalTrueWithPagination, totalSize10) <-
sendRequest("GET", s"/tables/1/rows?final=true&limit=4&offset=0").map(toRowsArrayAndTotalSize)
} yield {
assertEquals(7, allRows.size())
assertEquals(7, totalSize1)

assertEquals(2, finalFalse.size())
assertEquals(2, totalSize2)
assertEquals(5, finalTrue.size())
assertEquals(5, totalSize3)
assertEquals(4, archivedFalse.size())
assertEquals(4, totalSize4)
assertEquals(3, archivedTrue.size())
assertEquals(3, totalSize5)

assertEquals(7, allRows.size())
assertEquals(1, finalFalseAndArchivedFalse.size())
assertEquals(1, totalSize6)
assertEquals(2, finalTrueAndArchivedTrue.size())
assertEquals(2, totalSize7)
assertEquals(1, finalFalseAndArchivedTrue.size())
assertEquals(1, totalSize8)
assertEquals(3, finalTrueAndArchivedFalse.size())
assertEquals(3, totalSize9)

assertEquals(4, finalTrueWithPagination.size())
assertEquals(5, totalSize10)
}
}
}
Expand Down Expand Up @@ -1731,14 +1757,16 @@ class RetrieveFinalAndArchivedRows extends LinkTestBase with Helper {
row <- sendRequest("GET", s"/tables/$tableId1/rows/$rowId1")
} yield {
assertJSONEquals(
Json.fromObjectString("""|{
| "id": 1,
| "values": [
| "table2row1"
| ],
| "final": true
|}
|""".stripMargin),
Json.fromObjectString(
"""|{
| "id": 1,
| "values": [
| "table2row1"
| ],
| "final": true
|}
|""".stripMargin
),
firstCells.getJsonObject(0)
)

Expand Down
32 changes: 17 additions & 15 deletions src/test/scala/com/campudus/tableaux/api/content/LinkTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1178,21 +1178,23 @@ class LinkTest extends LinkTestBase {
js.getJsonArray("columns")
}
} yield {
val expectedJson = Json.fromObjectString(s"""
|{
| "status": "ok",
| "page": {
| "offset": null,
| "limit": null,
| "totalSize": 3
| },
| "rows": [
| {"id": 1,"values": [[{"id": 2,"value": "blub 2"}]]},
| {"id": 2,"values": [[{"id": 3,"value": "blub 3"}]]},
| {"id": 3,"values": [[{"id": 1,"value": "blub 1"}]]}
| ]
|}
""".stripMargin)
val expectedJson = Json.fromObjectString(
s"""
|{
| "status": "ok",
| "page": {
| "offset": null,
| "limit": null,
| "totalSize": 3
| },
| "rows": [
| {"id": 1,"values": [[{"id": 2,"value": "blub 2"}]]},
| {"id": 2,"values": [[{"id": 3,"value": "blub 3"}]]},
| {"id": 3,"values": [[{"id": 1,"value": "blub 1"}]]}
| ]
|}
""".stripMargin
)

assertJSONEquals(expectedJson, rows)

Expand Down

0 comments on commit f3bb3e2

Please sign in to comment.