Skip to content

Commit df0e219

Browse files
committed
test 2nd instance
ref #530
1 parent e9f19d4 commit df0e219

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

tests/testthat/test-file-oneshot.R

+37-2
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,18 @@ test_that("file in repeating instrument", {
330330
credential_repeating <- retrieve_credential_testing(3181L)
331331
on.exit({
332332
base::unlink(returned_object_1_1$file_name)
333+
base::unlink(returned_object_1_2$file_name)
333334
base::unlink(returned_object_2_1$file_name)
334335
})
335336

336337
# start_time <- Sys.time() - lubridate::seconds(1) #Knock off a second in case there's small time imprecisions
337338
start_time <- Sys.time() - 10 #Knock off ten seconds in case there are small time imprecisions.
338339
path_of_expected_1_1 <- system.file("test-data/levon-and-barry.jpg", package="REDCapR")
339-
# path_of_expected_1_2 <- system.file("test-data/mugshot-1.jpg", package="REDCapR")
340+
path_of_expected_1_2 <- system.file("test-data/mugshot-1.jpg", package="REDCapR")
340341
path_of_expected_2_1 <- system.file("test-data/mugshot-2.jpg", package="REDCapR")
341342
info_expected_1_1 <- file.info(path_of_expected_1_1)
343+
info_expected_1_2 <- file.info(path_of_expected_1_2)
342344
info_expected_2_1 <- file.info(path_of_expected_2_1)
343-
# record <- 1
344345
field <- "image_profile"
345346

346347
expected_outcome_message <- '^(Preparing to download the file `.+\\.jpg`\\.|.+; name=".+\\.jpg" successfully downloaded in \\d+(\\.\\d+\\W|\\W)seconds\\, and saved as .+\\.jpg)'
@@ -382,6 +383,40 @@ test_that("file in repeating instrument", {
382383
expect_true(start_time <= info_actual_1_1$atime, label="The downloaded file's last access time should not precede this function's start time.")
383384

384385
# ---- first record, second instance --------------------------
386+
suppressMessages({
387+
returned_object_1_2 <-
388+
redcap_file_download_oneshot(
389+
record = 1L,
390+
field = field,
391+
repeat_instance = "2",
392+
redcap_uri = credential_repeating$redcap_uri,
393+
token = credential_repeating$token,
394+
verbose = TRUE
395+
)
396+
})
397+
398+
Sys.sleep(delay_after_download_file)
399+
info_actual_1_2 <- file.info(returned_object_1_2$file_name)
400+
expect_true(file.exists(returned_object_1_2$file_name), "The downloaded file should exist.")
401+
402+
#Test the values of the returned object.
403+
expect_true(returned_object_1_2$success)
404+
expect_equal(returned_object_1_2$status_code, expected=200L)
405+
expect_match(returned_object_1_2$outcome_message, regexp=expected_outcome_message, perl=TRUE)
406+
expect_equal(returned_object_1_2$records_affected_count, 1L)
407+
expect_equal(returned_object_1_2$affected_ids, "1")
408+
expect_true(returned_object_1_2$elapsed_seconds>0, "The `elapsed_seconds` should be a positive number.")
409+
expect_equal(returned_object_1_2$raw_text, expected="", ignore_attr = TRUE) # dput(returned_object_1$raw_text)
410+
expect_equal(returned_object_1_2$file_name, "mugshot-1.jpg", label="The name of the downloaded file should be correct.")
411+
412+
#Test the values of the file.
413+
expect_equal(info_actual_1_2$size, expected=info_expected_1_2$size, label="The size of the downloaded file should match.")
414+
expect_false(info_actual_1_2$isdir, "The downloaded file should not be a directory.")
415+
# expect_equal(as.character(info_actual_1_2$mode), expected=as.character(info_expected$mode), label="The mode/permissions of the downloaded file should match.")
416+
expect_true(start_time <= info_actual_1_2$mtime, label="The downloaded file's modification time should not precede this function's start time.")
417+
# expect_true(start_time <= info_actual_1_2$ctime, label="The downloaded file's last change time should not precede this function's start time.")
418+
expect_true(start_time <= info_actual_1_2$atime, label="The downloaded file's last access time should not precede this function's start time.")
419+
385420

386421
# ---- second record, first instance --------------------------
387422
suppressMessages({

0 commit comments

Comments
 (0)