Skip to content

Commit

Permalink
verify record_id not returned by redcap_read_oneshot()
Browse files Browse the repository at this point in the history
when not requested

ref #471
  • Loading branch information
wibeasley committed Jul 11, 2023
1 parent 511928d commit cc6da98
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
structure(list(name_first = c("Nutmeg", "Tumtum", "Marcus", "Trudy",
"John Lee"), address = c("14 Rose Cottage St.\nKenning UK, 323232",
"14 Rose Cottage Blvd.\nKenning UK 34243", "243 Hill St.\nGuthrie OK 73402",
"342 Elm\nDuncanville TX, 75116", "Hotel Suite\nNew Orleans LA, 70115"
), interpreter_needed = c(0, 0, 1, NA, 0)), row.names = c(NA,
-5L), spec = structure(list(cols = list(name_first = structure(list(), class = c("collector_character",
"collector")), address = structure(list(), class = c("collector_character",
"collector")), interpreter_needed = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
structure(list(height = c(7, 6, 180, 165, 193.04), weight = c(1,
1, 80, 54, 104), bmi = c(204.1, 277.8, 24.7, 19.8, 27.9), comments = c("Character in a book, with some guessing",
"A mouse character from a good book", "completely made up", "This record doesn't have a DAG assigned\n\nSo call up Trudy on the telephone\nSend her a letter in the mail",
"Had a hand for trouble and a eye for cash\n\nHe had a gold watch chain and a black mustache"
), mugshot = c("mugshot-1.jpg", "mugshot-2.jpg", "mugshot-3.jpg",
"mugshot-4.jpg", "mugshot-5.jpg"), health_complete = c(1, 0,
2, 2, 0)), row.names = c(NA, -5L), spec = structure(list(cols = list(
height = structure(list(), class = c("collector_double",
"collector")), weight = structure(list(), class = c("collector_double",
"collector")), bmi = structure(list(), class = c("collector_double",
"collector")), comments = structure(list(), class = c("collector_character",
"collector")), mugshot = structure(list(), class = c("collector_character",
"collector")), health_complete = structure(list(), class = c("collector_double",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = ","), class = "col_spec"), class = c("spec_tbl_df",
"tbl_df", "tbl", "data.frame"))
56 changes: 56 additions & 0 deletions tests/testthat/test-read-oneshot.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,62 @@ test_that("specify-forms", {

expect_s3_class(returned_object$data, "tbl")
})
test_that("specify-forms-without-record-id", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-oneshot/specify-forms-without-record-id.R"
desired_forms <- c("health")
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

returned_object <-
redcap_read_oneshot(
redcap_uri = credential$redcap_uri,
token = credential$token,
forms = desired_forms,
verbose = FALSE
)

if (update_expectation) save_expected(returned_object$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

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(returned_object$status_code, expected=200L)
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_true(returned_object$fields_collapsed=="", "A subset of fields was not requested.")
expect_true(returned_object$filter_logic=="", "A filter was not specified.")
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)

expect_s3_class(returned_object$data, "tbl")
})
test_that("specify-fields-without-record-id", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-oneshot/specify-fields-without-record-id.R"
desired_fields <- c("name_first", "address", "interpreter_needed")
expected_outcome_message <- "\\d+ records and \\d+ columns were read from REDCap in \\d+(\\.\\d+\\W|\\W)seconds\\."

returned_object <-
redcap_read_oneshot(
redcap_uri = credential$redcap_uri,
token = credential$token,
fields = desired_fields,
verbose = FALSE
)

if (update_expectation) save_expected(returned_object$data, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

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(returned_object$status_code, expected=200L)
expect_equal(returned_object$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object$raw_text)
expect_true(returned_object$records_collapsed=="", "A subset of records was not requested.")
expect_equal(returned_object$fields_collapsed, paste(desired_fields, collapse = ","))
expect_true(returned_object$filter_logic=="", "A filter was not specified.")
expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE)
expect_true(returned_object$success)

expect_s3_class(returned_object$data, "tbl")
})
test_that("specify-forms-only-1st", {
testthat::skip_on_cran()
path_expected <- "test-data/specific-redcapr/read-oneshot/specify-forms-only-1st.R"
Expand Down

0 comments on commit cc6da98

Please sign in to comment.