Skip to content

Commit

Permalink
use cookies in upload tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hillalex committed Aug 28, 2024
1 parent 478d0e7 commit 06e9158
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions tests/testthat/test-upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,13 @@ test_that("uploading wrong file type returns 400", {
})

test_that("saves file and xcol", {
router <- build_routes()
set.seed(1)
session_id <- generate_session_id()
set.seed(1) #so that same id generated when processing request
router <- build_routes(cookie_key)
request <- local_POST_dataset_request(data.frame(biomarker = "ab",
time = 1:10,
value = 1),
filename = "testdataset",
xcol = "time")
xcol = "time",
cookie = cookie)
res <- router$call(request)
expect_equal(res$status, 200)
dat <- utils::read.csv(file.path("uploads", session_id, "/testdataset/data"))
Expand All @@ -90,13 +88,13 @@ test_that("saves file and xcol", {
})

test_that("can get uploaded dataset metadata with default xcol", {
set.seed(1)
request <- local_POST_dataset_request(data.frame(biomarker = c("ab", "ba"),
value = 1,
day = 1:10,
age = "0-5",
sex = c("M", "F")),
"testdata")
"testdata",
cookie = cookie)
router <- build_routes(cookie_key)
res <- router$call(request)
expect_equal(res$status, 200)
Expand All @@ -113,14 +111,13 @@ test_that("can get uploaded dataset metadata with default xcol", {
})

test_that("can get uploaded dataset metadata with xcol", {
set.seed(1)
request <- local_POST_dataset_request(data.frame(biomarker = c("ab", "ba"),
value = 1,
time = 1:10,
age = "0-5",
sex = c("M", "F")),
"testdata",
xcol = "time")
xcol = "time", cookie = cookie)
router <- build_routes(cookie_key)
res <- router$call(request)
expect_equal(res$status, 200)
Expand All @@ -136,12 +133,12 @@ test_that("can get uploaded dataset metadata with xcol", {
})

test_that("can get uploaded dataset without covariates", {
set.seed(1)
request <- local_POST_dataset_request(data.frame(biomarker = c("ab", "ba"),
value = 1,
time = 1:10),
"testdata",
xcol = "time")
xcol = "time",
cookie = cookie)
router <- build_routes(cookie_key)
res <- router$call(request)
expect_equal(res$status, 200)
Expand All @@ -158,9 +155,9 @@ test_that("can get uploaded dataset without covariates", {

test_that("returns 400 if no xcol", {
request <- local_POST_dataset_request_no_xcol(data.frame(biomarker = c("ab", "ba"),
value = 1,
time = 1:10),
"testdata")
value = 1,
time = 1:10),
"testdata")
router <- build_routes()
res <- router$call(request)
expect_equal(res$status, 400)
Expand Down

0 comments on commit 06e9158

Please sign in to comment.