|
| 1 | +library(testthat) |
| 2 | +context("Users Export") |
| 3 | + |
| 4 | +credential_1 <- REDCapR::retrieve_credential_local( |
| 5 | + path_credential = system.file("misc/example.credentials", package="REDCapR"), |
| 6 | + project_id = 999 |
| 7 | +) |
| 8 | + |
| 9 | +credential_2 <- REDCapR::retrieve_credential_local( |
| 10 | + path_credential = system.file("misc/example.credentials", package="REDCapR"), |
| 11 | + project_id = 153 |
| 12 | +) |
| 13 | + |
| 14 | +test_that("smoke test", { |
| 15 | + testthat::skip_on_cran() |
| 16 | + expect_message({ |
| 17 | + returned_object_1 <- redcap_users_export(redcap_uri=credential_1$redcap_uri, token=credential_1$token, verbose=T) |
| 18 | + returned_object_2 <- redcap_users_export(redcap_uri=credential_2$redcap_uri, token=credential_2$token, verbose=T) |
| 19 | + }) |
| 20 | +}) |
| 21 | + |
| 22 | +test_that("with DAGs", { |
| 23 | + testthat::skip_on_cran() |
| 24 | + expected_outcome_message <- "The REDCap users were successfully exported in \\d+(\\.\\d+\\W|\\W)seconds\\. The http status code was 200\\." |
| 25 | + expected_data_user <- structure( |
| 26 | + list(username = c("dwells", "unittestphifree", "wbeasleya" |
| 27 | + |
| 28 | + "[email protected]"), firstname = c( "Donna", "Unit Test", |
| 29 | + "Will"), lastname = c("Wells", "PHI Free", "Beasley_A"), expiration = structure(c(20334, |
| 30 | + NA, NA), class = "Date"), data_access_group = c("dagb", "daga", |
| 31 | + NA), data_access_group_id = c("332", "331", NA), design = c(FALSE, |
| 32 | + FALSE, TRUE), user_rights = c(FALSE, FALSE, TRUE), data_access_groups = c(FALSE, |
| 33 | + FALSE, TRUE), data_export = c("2", "1", "1"), reports = c(FALSE, |
| 34 | + FALSE, TRUE), stats_and_charts = c(FALSE, FALSE, TRUE), manage_survey_participants = c(TRUE, |
| 35 | + TRUE, TRUE), calendar = c(FALSE, FALSE, TRUE), data_import_tool = c(FALSE, |
| 36 | + FALSE, TRUE), data_comparison_tool = c(FALSE, FALSE, TRUE), logging = c(FALSE, |
| 37 | + FALSE, TRUE), file_repository = c(FALSE, FALSE, TRUE), data_quality_create = c(FALSE, |
| 38 | + FALSE, TRUE), data_quality_execute = c(FALSE, FALSE, TRUE), api_export = c(FALSE, |
| 39 | + TRUE, TRUE), api_import = c(FALSE, FALSE, TRUE), mobile_app = c(FALSE, |
| 40 | + FALSE, TRUE), mobile_app_download_data = c(FALSE, FALSE, TRUE |
| 41 | + ), record_create = c(FALSE, FALSE, TRUE), record_rename = c(FALSE, |
| 42 | + FALSE, FALSE), record_delete = c(FALSE, FALSE, FALSE), lock_records_all_forms = c(FALSE, |
| 43 | + FALSE, FALSE), lock_records = c(FALSE, FALSE, FALSE), lock_records_customization = c(FALSE, |
| 44 | + FALSE, FALSE)), row.names = c(NA, -3L), class = c("tbl_df", "tbl", |
| 45 | + "data.frame") |
| 46 | + ) |
| 47 | + expected_data_user_form <- structure( |
| 48 | + list(username = c("dwells", "unittestphifree", "wbeasleya" |
| 49 | + ), form_name = c("demographics", "demographics", "demographics" |
| 50 | + ), permission = c(TRUE, TRUE, TRUE)), class = c("tbl_df", "tbl", |
| 51 | + "data.frame"), row.names = c(NA, -3L) |
| 52 | + ) |
| 53 | + |
| 54 | + expect_message( |
| 55 | + regexp = expected_outcome_message, |
| 56 | + returned_object <- redcap_users_export(redcap_uri=credential_1$redcap_uri, token=credential_1$token, verbose=T) |
| 57 | + ) |
| 58 | + |
| 59 | + expect_equivalent(returned_object$data_user , expected=expected_data_user , label="The returned data.frame should be correct") # dput(returned_object$data_user); |
| 60 | + expect_equivalent(returned_object$data_user_form, expected=expected_data_user_form, label="The returned data.frame should be correct") # dput(returned_object$data_user_form) |
| 61 | + expect_equal(returned_object$status_code, expected=200L) |
| 62 | + expect_equivalent(returned_object$raw_text, expected="") # dput(returned_object$raw_text) |
| 63 | + expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE) |
| 64 | + expect_true(returned_object$success) |
| 65 | + # system.file("misc/example.credentials", package="REDCapR") |
| 66 | + |
| 67 | + # expect_equal_to_reference(returned_object$data, file=system.file("test-data/project-simple/variations/default.rds", package="REDCapR")) |
| 68 | + # expect_equal_to_reference(returned_object$data, file="./test-data/project-simple/variations/default.rds") |
| 69 | +}) |
| 70 | +test_that("with DAGs", { |
| 71 | + testthat::skip_on_cran() |
| 72 | + expected_outcome_message <- "The REDCap users were successfully exported in \\d+(\\.\\d+\\W|\\W)seconds\\. The http status code was 200\\." |
| 73 | + expected_data_user <- structure( |
| 74 | + list(username = c("unittestphifree", "wbeasleya"), |
| 75 | + |
| 76 | + ), firstname = c("Unit Test", "Will"), lastname = c("PHI Free", |
| 77 | + "Beasley_A"), expiration = structure(c(NA_real_, NA_real_ |
| 78 | + ), class = "Date"), data_access_group = c(NA_character_, |
| 79 | + NA_character_), data_access_group_id = c(NA_character_, NA_character_ |
| 80 | + ), design = c(FALSE, TRUE), user_rights = c(FALSE, TRUE), |
| 81 | + data_access_groups = c(FALSE, TRUE), data_export = c("1", |
| 82 | + "1"), reports = c(TRUE, TRUE), stats_and_charts = c(TRUE, |
| 83 | + TRUE), manage_survey_participants = c(TRUE, TRUE), calendar = c(TRUE, |
| 84 | + TRUE), data_import_tool = c(FALSE, TRUE), data_comparison_tool = c(FALSE, |
| 85 | + TRUE), logging = c(FALSE, TRUE), file_repository = c(TRUE, |
| 86 | + TRUE), data_quality_create = c(FALSE, TRUE), data_quality_execute = c(FALSE, |
| 87 | + TRUE), api_export = c(TRUE, FALSE), api_import = c(FALSE, |
| 88 | + FALSE), mobile_app = c(FALSE, FALSE), mobile_app_download_data = c(FALSE, |
| 89 | + FALSE), record_create = c(TRUE, TRUE), record_rename = c(FALSE, |
| 90 | + FALSE), record_delete = c(FALSE, FALSE), lock_records_all_forms = c(FALSE, |
| 91 | + FALSE), lock_records = c(FALSE, FALSE), lock_records_customization = c(FALSE, |
| 92 | + FALSE)), row.names = c(NA, -2L), class = c("tbl_df", "tbl", |
| 93 | + "data.frame") |
| 94 | + ) |
| 95 | + expected_data_user_form <- structure( |
| 96 | + list(username = c("unittestphifree", "unittestphifree", |
| 97 | + "unittestphifree", "wbeasleya", "wbeasleya", "wbeasleya"), form_name = c("demographics", |
| 98 | + "health", "race_and_ethnicity", "demographics", "health", "race_and_ethnicity" |
| 99 | + ), permission = c(TRUE, TRUE, TRUE, TRUE, TRUE, TRUE)), class = c("tbl_df", |
| 100 | + "tbl", "data.frame"), row.names = c(NA, -6L) |
| 101 | + ) |
| 102 | + |
| 103 | + expect_message( |
| 104 | + regexp = expected_outcome_message, |
| 105 | + returned_object <- redcap_users_export(redcap_uri=credential_2$redcap_uri, token=credential_2$token, verbose=T) |
| 106 | + ) |
| 107 | + |
| 108 | + expect_equivalent(returned_object$data_user , expected=expected_data_user , label="The returned data.frame should be correct") # dput(returned_object$data_user); |
| 109 | + expect_equivalent(returned_object$data_user_form, expected=expected_data_user_form, label="The returned data.frame should be correct") # dput(returned_object$data_user_form) |
| 110 | + expect_equal(returned_object$status_code, expected=200L) |
| 111 | + expect_equivalent(returned_object$raw_text, expected="") # dput(returned_object$raw_text) |
| 112 | + expect_match(returned_object$outcome_message, regexp=expected_outcome_message, perl=TRUE) |
| 113 | + expect_true(returned_object$success) |
| 114 | +}) |
0 commit comments