Skip to content

Commit

Permalink
add schema
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Sep 19, 2024
1 parent 221188e commit 34d433a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/router.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ get_individual <- function() {
color = "string",
filter = "string",
linetype = "string"),
returning = porcelain::porcelain_returning_json())
returning = porcelain::porcelain_returning_json("Plotly"))
}

prune_inactive_sessions <- function(cache) {
Expand Down
33 changes: 33 additions & 0 deletions inst/schema/Plotly.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"data": {
"type": "array",
"items": {
"type": "object",
"properties": {
"x": {
"type": ["array", "null", "number"]
},
"y": {
"type": ["array", "null", "number"]
}
},
"additionalProperties": true
}
},
"layout": {
"type": "object",
"additionalProperties": true
},
"warnings": {
"type": ["string", "null", "array"],
"items": {
"type": "string"
}
}
},
"required": ["data", "layout", "warnings"],
"additionalProperties": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ test_that("GET /individual/<pidcol> returns 400 if pidcol not found", {
expect_equal(res$status, 400)
validate_failure_schema(res$body)
body <- jsonlite::fromJSON(res$body)
str(body)
expect_equal(body$errors[1, "detail"],
"Id column 'pid' not found.")
})
Expand All @@ -44,7 +43,9 @@ test_that("can get individual trajectories for uploaded dataset with xcol", {
res <- router$call(make_req("GET",
"/dataset/testdataset/individual/pid/",
HTTP_COOKIE = cookie))

expect_equal(res$status, 200)

body <- jsonlite::fromJSON(res$body)
expect_equal(nrow(body$data$data), 2)
expect_equal(body$data$data$x[[1]], c(1, 3, 5, 7, 9))
Expand Down

0 comments on commit 34d433a

Please sign in to comment.