-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from seroanalytics/paging
Paging
- Loading branch information
Showing
7 changed files
with
188 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
invalid_file_type <- function(res) { | ||
res$status <- 400L | ||
msg <- "Invalid file type; please upload file of type text/csv." | ||
bad_request_response(msg) | ||
} | ||
|
||
duplicate_dataset_name <- function(res, name) { | ||
res$status <- 400L | ||
msg <- paste(name, "already exists.", | ||
"Please choose a unique name for this dataset.") | ||
bad_request_response(msg) | ||
} | ||
|
||
missing_columns <- function(res, missing_cols) { | ||
res$status <- 400L | ||
msg <- paste("Missing required columns:", | ||
paste(missing_cols, collapse = ", ")) | ||
bad_request_response(msg) | ||
} | ||
|
||
invalid_xcol <- function(res) { | ||
res$status <- 400L | ||
msg <- paste("Invalid x column values:", | ||
"these should be numbers or dates in a standard format.") | ||
bad_request_response(msg) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
test_that("page 1 is first n ids if n < length(ids)", { | ||
ids <- c("a", "b", "c", "d", "e") | ||
result <- get_paged_ids(ids, 1, 2) | ||
expect_equal(result, c("a", "b")) | ||
}) | ||
|
||
test_that("page 1 is all ids if n >= length(ids)", { | ||
ids <- c("a", "b", "c", "d", "e") | ||
result <- get_paged_ids(ids, 1, 10) | ||
expect_equal(result, ids) | ||
}) | ||
|
||
test_that("page 2 is second n ids", { | ||
ids <- c("a", "b", "c", "d", "e") | ||
result <- get_paged_ids(ids, 2, 2) | ||
expect_equal(result, c("c", "d")) | ||
}) | ||
|
||
test_that("last page is last m ids where m <= n", { | ||
ids <- c("a", "b", "c", "d", "e") | ||
result <- get_paged_ids(ids, 3, 2) | ||
expect_equal(result, c("e")) | ||
}) | ||
|
||
test_that("first page of results returned by default", { | ||
dat <- data.frame(biomarker = "ab", | ||
pid = 1:25, | ||
value = 1, | ||
day = 1:25) | ||
router <- build_routes(cookie_key) | ||
post_request <- local_POST_dataset_request(dat, | ||
"testdataset", | ||
cookie = cookie) | ||
expect_equal(router$call(post_request)$status, 200) | ||
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(body$data$page, 1) | ||
expect_equal(body$data$numPages, 2) | ||
|
||
data <- body$data$data | ||
expect_equal(nrow(data), 20) | ||
}) | ||
|
||
test_that("correct page of results returned", { | ||
dat <- data.frame(biomarker = "ab", | ||
pid = 1:25, | ||
value = 1, | ||
day = 1:25) | ||
router <- build_routes(cookie_key) | ||
post_request <- local_POST_dataset_request(dat, | ||
"testdataset", | ||
cookie = cookie) | ||
expect_equal(router$call(post_request)$status, 200) | ||
res <- router$call(make_req("GET", | ||
"/dataset/testdataset/individual/pid/", | ||
qs = "page=2", | ||
HTTP_COOKIE = cookie)) | ||
|
||
expect_equal(res$status, 200) | ||
body <- jsonlite::fromJSON(res$body) | ||
expect_equal(body$data$page, 2) | ||
expect_equal(body$data$numPages, 2) | ||
|
||
data <- body$data$data | ||
expect_equal(nrow(data), 5) | ||
}) |
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