From 7efb0ce5449db6f7fd1bb4e121b1a26feb95d890 Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Sun, 3 Nov 2024 13:37:53 -0600 Subject: [PATCH] test for first-subdirectory ref #549 --- .../first-subdirectory.R | 7 +++ tests/testthat/test-file-repo-list-oneshot.R | 44 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 inst/test-data/specific-redcapr/file-repo-list-oneshot/first-subdirectory.R diff --git a/inst/test-data/specific-redcapr/file-repo-list-oneshot/first-subdirectory.R b/inst/test-data/specific-redcapr/file-repo-list-oneshot/first-subdirectory.R new file mode 100644 index 00000000..e839c4d5 --- /dev/null +++ b/inst/test-data/specific-redcapr/file-repo-list-oneshot/first-subdirectory.R @@ -0,0 +1,7 @@ +structure(list(folder_id = NA_integer_, doc_id = 6651L, name = "levon-and-barry.jpg"), row.names = c(NA, +-1L), spec = structure(list(cols = list(folder_id = structure(list(), class = c("collector_integer", +"collector")), doc_id = structure(list(), class = c("collector_integer", +"collector")), name = structure(list(), class = c("collector_character", +"collector"))), default = structure(list(), class = c("collector_guess", +"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df", +"tbl_df", "tbl", "data.frame")) diff --git a/tests/testthat/test-file-repo-list-oneshot.R b/tests/testthat/test-file-repo-list-oneshot.R index b130787f..cbf11c23 100644 --- a/tests/testthat/test-file-repo-list-oneshot.R +++ b/tests/testthat/test-file-repo-list-oneshot.R @@ -61,7 +61,51 @@ test_that("default", { expect_true(returned_object$elapsed_seconds>0, "The `elapsed_seconds` should be a positive number.") expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text) }) +test_that("first-subdirectory", { + testthat::skip_on_cran() + expected_message <- "The file repository structure describing 1 elements was read from REDCap in [0-9.]+ seconds\\. The http status code was 200\\." + + path_expected <- "test-data/specific-redcapr/file-repo-list-oneshot/first-subdirectory.R" + + suppressMessages({ + expect_message( + returned_object <- + redcap_file_repo_list_oneshot( + redcap_uri = credential$redcap_uri, + token = credential$token, + folder_id = 1 + ), + expected_message + ) + }) + + if (update_expectation) save_expected(returned_object$data, path_expected) + expected_data_frame <- retrieve_expected(path_expected) + + #Test the values of the returned object. + if (credential$redcap_uri == "https://redcap-dev-2.ouhsc.edu/redcap/api/") { + expect_equal(returned_object$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object$data) + } + + expect_equal(nrow(returned_object$data), expected=1L) + expect_equal(returned_object$data$name, expected_data_frame$name) + expect_equal(class(returned_object$data$folder_id), "integer") + expect_equal(class(returned_object$data$doc_id ), "integer") + expect_equal( + !is.na(returned_object$data$folder_id), + c(FALSE) + ) + expect_equal( + !is.na(returned_object$data$doc_id), + c(TRUE) + ) + expect_true(returned_object$success) + expect_equal(returned_object$status_code, expected=200L) + expect_match(returned_object$outcome_message, regexp=expected_message, perl=TRUE) + expect_true(returned_object$elapsed_seconds>0, "The `elapsed_seconds` should be a positive number.") + expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text) +}) test_that("download w/ bad token -Error", { testthat::skip_on_cran()