Skip to content

Commit

Permalink
allow different survey timestamps
Browse files Browse the repository at this point in the history
ref #544
wibeasley committed Oct 17, 2024
1 parent 6630386 commit f763ae5
Showing 2 changed files with 23 additions and 11 deletions.
10 changes: 4 additions & 6 deletions inst/test-data/projects/survey/expected/default.R
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
structure(list(participant_id = c(1, 2), redcap_survey_identifier = c(NA,
NA), prescreening_survey_timestamp = structure(c(1728851970,
1728852051), class = c("POSIXct", "POSIXt"), tzone = "UTC"),
dob = structure(c(17596, 17595), class = "Date"), email = c("[email protected]",
"[email protected]"), has_diabetes = c(1, 0), consent___1 = c(1,
0), prescreening_survey_complete = c(2, 2), participant_info_survey_timestamp = c(NA,
NA), dob = structure(c(17596, 17595), class = "Date"), email = c("[email protected]",
"[email protected]"), has_diabetes = c(1, 0), consent___1 = c(1, 0),
prescreening_survey_complete = c(2, 2), participant_info_survey_timestamp = c(NA,
NA), first_name = c(NA, NA), last_name = c(NA, NA), address = c(NA,
NA), telephone_1 = c(NA, NA), ethnicity = c(NA, NA), race = c(NA,
NA), sex = c(NA, NA), height = c(NA, NA), weight = c(NA,
@@ -14,4 +12,4 @@ NA), prescreening_survey_timestamp = structure(c(1728851970,
withdraw_reason = c(NA, NA), date_visit_4 = c(NA, NA), discharge_date_4 = c(NA,
NA), discharge_summary_4 = c(NA, NA), study_comments = c(NA,
NA), completion_data_complete = c(0, 0)), row.names = c(NA,
-2L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"))
-2L), class = c("tbl_df", "tbl", "data.frame"))
24 changes: 19 additions & 5 deletions tests/testthat/test-read-batch-survey.R
Original file line number Diff line number Diff line change
@@ -62,11 +62,18 @@ test_that("default", {
verbose = FALSE
)

if (update_expectation) save_expected(returned_object1$data, path_expected)
expect_true(all(!is.na(returned_object1$data$prescreening_survey_timestamp)))
expect_s3_class(returned_object1$data$prescreening_survey_timestamp, "POSIXct")
d1 <-
returned_object1$data |>
dplyr::select(
-prescreening_survey_timestamp
)

if (update_expectation) save_expected(d1, path_expected)
expected_data_frame <- retrieve_expected(path_expected)

expect_equal(returned_object1$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object1$data)
expect_true(all(!is.na(returned_object1$data$prescreening_survey_timestamp)))
expect_equal(d1, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object1$data)
expect_true(returned_object1$success)
expect_match(returned_object1$status_codes, regexp="200", perl=TRUE)
expect_true(returned_object1$records_collapsed=="", "A subset of records was not requested.")
@@ -86,8 +93,15 @@ test_that("default", {
verbose = FALSE
)

expect_equal(returned_object2$data, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object2$data)
expect_true(all(!is.na(returned_object1$data$prescreening_survey_timestamp)))
expect_true(all(!is.na(returned_object2$data$prescreening_survey_timestamp)))
expect_s3_class(returned_object2$data$prescreening_survey_timestamp, "POSIXct")
d2 <-
returned_object2$data |>
dplyr::select(
-prescreening_survey_timestamp
)

expect_equal(d2, expected=expected_data_frame, label="The returned data.frame should be correct", ignore_attr = TRUE) # dput(returned_object2$data)
expect_true(returned_object2$success)
expect_match(returned_object2$status_codes, regexp="200", perl=TRUE)
expect_true(returned_object2$records_collapsed=="", "A subset of records was not requested.")

0 comments on commit f763ae5

Please sign in to comment.