From cbe2e0a7d809a639147d52f11802752786477f23 Mon Sep 17 00:00:00 2001 From: "alex.hill@gmail.com" Date: Mon, 23 Sep 2024 08:56:20 +0100 Subject: [PATCH] make xcol optional as well --- R/api.R | 10 +++++++++- tests/testthat/test-upload.R | 9 +++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/R/api.R b/R/api.R index b9f0591..9fe2abc 100644 --- a/R/api.R +++ b/R/api.R @@ -12,7 +12,7 @@ target_post_dataset <- function(req, res) { session_id <- get_or_create_session_id(req) logger::log_info("Parsing multipart form request") parsed <- mime::parse_multipart(req) - xcol <- parsed$xcol + xcol <- get_xcol(parsed) name <- get_dataset_name(parsed) if (is.null(xcol)) { res$status <- 400L @@ -92,6 +92,14 @@ get_dataset_name <- function(parsed) { return(name) } +get_xcol <- function(parsed) { + xcol <- parsed$xcol + if (is.null(xcol)) { + xcol <- "day" + } + return(xcol) +} + target_get_dataset <- function(name, req) { logger::log_info(paste("Requesting metadata for dataset:", name)) dataset <- read_dataset(req, name, "natural") diff --git a/tests/testthat/test-upload.R b/tests/testthat/test-upload.R index 85a85af..ad9b275 100644 --- a/tests/testthat/test-upload.R +++ b/tests/testthat/test-upload.R @@ -183,15 +183,12 @@ test_that("can get uploaded dataset without covariates", { expect_equal(body$data$xcol, "time") }) -test_that("returns 400 if no xcol", { +test_that("uses default 'day' if no xcol provided", { request <- local_POST_dataset_request_no_xcol(data.frame(biomarker = c("ab", "ba"), value = 1, - time = 1:10), + day = 1:10), "testdata") router <- build_routes() res <- router$call(request) - expect_equal(res$status, 400) - body <- jsonlite::fromJSON(res$body) - expect_equal(body$errors[1, "detail"], - "Missing required field: xcol.") + expect_equal(res$status, 200) })