library(testthat) credential <- retrieve_credential_testing() test_that("One Shot: Bad Uri -Not HTTPS", { testthat::skip_on_cran() testthat::skip("The response is dependent on the client. This test is probably too picky anyway.") # expected_message_411 <- "\nLength Required\n\n

Length Required

\n

HTTP Error 411. The request must be chunked or have a content length.

\n\n" # expected_message_501 <- "The requested method is not implemented." expect_error( redcap_read_oneshot( redcap_uri = "http://bbmc.ouhsc.edu/redcap/api/", # Not HTTPS token = credential$token ) ) }) test_that("One Shot: Bad Uri -wrong address", { testthat::skip_on_cran() expected_message <- "\n\n404 Not Found\n\n

Not Found

\n

The requested URL was not found on this server.

\n\n" returned_object <- redcap_read_oneshot( redcap_uri = "https://bbmc.ouhsc.edu/redcap/apiFFFFFFFFFFFFFF/", # Wrong url token = credential$token, verbose = FALSE ) expect_equal(returned_object$data, expected=tibble::tibble(), label="An empty data.frame should be returned.", ignore_attr = TRUE) expect_equal(returned_object$status_code, expected=404L) expect_equal(returned_object$raw_text, expected=expected_message) expect_equal(returned_object$records_collapsed, "") expect_equal(returned_object$fields_collapsed, "") expect_false(returned_object$success) expect_s3_class(returned_object$data, "tbl") }) test_that("Batch: Bad Uri -Not HTTPS", { testthat::skip_on_cran() testthat::skip("The response is dependent on the client. This test is probably too picky anyway.") # expected_outcome_message <- "The initial call failed with the code: (411|501)." expect_error( redcap_read( redcap_uri = "http://bbmc.ouhsc.edu/redcap/api/", # Not HTTPS token = credential$token ) ) }) test_that("Batch: Bad Uri -wrong address", { testthat::skip_on_cran() # expected_message <- "The initial call failed with the code: 404." expected_message <- "The requested URL was not found on this server." expect_error( redcap_read( redcap_uri = "https://bbmc.ouhsc.edu/redcap/apiFFFFFFFFFFFFFF/", # Wrong url token = credential$token ), expected_message ) }) test_that("hashed record -warn", { testthat::skip_on_cran() # This dinky little test is mostly to check that the warning message has legal syntax. expected_warning <- "^It appears that the REDCap record IDs have been hashed.+" expect_warning( REDCapR:::warn_hash_record_id(), expected_warning ) }) test_that("guess_max deprecated -warn", { testthat::skip_on_cran() expected_outcome_message <- "The `guess_max` parameter in `REDCapR::redcap_read\\(\\)` is deprecated\\." expect_warning( regexp = expected_outcome_message, redcap_read( redcap_uri = credential$redcap_uri, token = credential$token, guess_max = 100, verbose = FALSE ) ) }) rm(credential)