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 06e9158 commit 12d2f32
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions tests/testthat/test-upload.R
Original file line number Diff line number Diff line change
@@ -1,45 +1,44 @@
test_that("uploading data with wrong columns returns 400", {
router <- build_routes()
set.seed(1)
router <- build_routes(cookie_key)
request <- local_POST_dataset_request(data.frame(biomarker = "ab",
day = 1:10),
"testdataset")
"testdataset",
cookie = cookie)
res <- router$call(request)
expect_equal(res$status, 400)
validate_failure_schema(res$body)
body <- jsonlite::fromJSON(res$body)
expect_equal(body$errors[1, "detail"], "Missing required columns: value")

set.seed(1)
request <- local_POST_dataset_request(data.frame(biomarker = "ab",
value = 1:10),
"testdataset")
"testdataset",
cookie = cookie)
res <- router$call(request)
expect_equal(res$status, 400)
body <- jsonlite::fromJSON(res$body)
expect_equal(body$errors[1, "detail"], "Missing required columns: day")

set.seed(1)
request <- local_POST_dataset_request(data.frame(day = 1:10,
value = 1:10),
"testdataset")
"testdataset",
cookie = cookie)
res <- router$call(request)
expect_equal(res$status, 400)
body <- jsonlite::fromJSON(res$body)
expect_equal(body$errors[1, "detail"], "Missing required columns: biomarker")
})

test_that("uploading dataset with duplicate name returns 400", {
router <- build_routes()
set.seed(1)
router <- build_routes(cookie_key)
request <- local_POST_dataset_request(data.frame(biomarker = "ab",
day = 1:10,
value = 1),
"testdataset")
"testdataset",
cookie = cookie)
res <- router$call(request)
expect_equal(res$status, 200)

set.seed(1) #so that same session id gets created
res <- router$call(request)
body <- jsonlite::fromJSON(res$body)
validate_failure_schema(res$body)
Expand All @@ -48,13 +47,13 @@ test_that("uploading dataset with duplicate name returns 400", {
})

test_that("can upload dataset with different xcol", {
router <- build_routes()
set.seed(1)
router <- build_routes(cookie_key)
request <- local_POST_dataset_request(data.frame(biomarker = "ab",
time = 1:10,
value = 1),
"testdataset",
xcol = "time")
xcol = "time",
cookie = cookie)
res <- router$call(request)
expect_equal(res$status, 200)
})
Expand Down

0 comments on commit 12d2f32

Please sign in to comment.