From 77a2a17b4cf55c02d9caa7d7249977de8a35b465 Mon Sep 17 00:00:00 2001 From: Andy Teucher Date: Tue, 10 Dec 2024 14:29:04 -0800 Subject: [PATCH] test create_batch_certificates for failure --- tests/testthat/_snaps/create_certificate.md | 12 +++++ tests/testthat/test-create_certificate.R | 54 ++++++++++++++++----- 2 files changed, 53 insertions(+), 13 deletions(-) diff --git a/tests/testthat/_snaps/create_certificate.md b/tests/testthat/_snaps/create_certificate.md index 51b9fd5..df8ee6e 100644 --- a/tests/testthat/_snaps/create_certificate.md +++ b/tests/testthat/_snaps/create_certificate.md @@ -8,3 +8,15 @@ [3] "nmfs-a/OpenscapesCertificate_2024-nmfs-champions-a_Rupert-White.pdf" [4] "nmfs-a/OpenscapesCertificate_2024-nmfs-champions-a_Sally-Green.pdf" +# create_batch_certificates gives error message when it fails but still proceeds + + Code + create_batch_certificates(registry = registry, participants = participants, + cohort_name = "2024-nmfs-champions-a", cohort_type = "nmfs", output_dir = file.path( + tdir, "nmfs-a")) + Message + x Unable to create certificate for "Sally Green" + i Error: character string is not in a standard unambiguous format + Output + [1] "output_dirname/nmfs-a" + diff --git a/tests/testthat/test-create_certificate.R b/tests/testthat/test-create_certificate.R index f5e42bf..3f5aad3 100644 --- a/tests/testthat/test-create_certificate.R +++ b/tests/testthat/test-create_certificate.R @@ -37,17 +37,17 @@ test_that("create_certificate works with nmfs", { test_that("create_batch_certificates works", { tdir <- withr::local_tempdir() - + participants <- dplyr::tibble( - cohort = c( - "2024-nmfs-champions-a", - "2024-nmfs-champions-a", - "2024-champions", - "2024-champions" - ), - first = c("Sally", "Rupert", "Lily", "Leo"), - last = c("Green", "White", "Brown", "Blue") - ) + cohort = c( + "2024-nmfs-champions-a", + "2024-nmfs-champions-a", + "2024-champions", + "2024-champions" + ), + first = c("Sally", "Rupert", "Lily", "Leo"), + last = c("Green", "White", "Brown", "Blue") + ) registry <- dplyr::tibble( cohort_name = c( @@ -63,7 +63,7 @@ test_that("create_batch_certificates works", { "https://nasa-openscapes.github.io/2024-nasa-champions" ) ) - + create_batch_certificates( registry = registry, participants = participants, @@ -71,7 +71,7 @@ test_that("create_batch_certificates works", { cohort_type = "nmfs", output_dir = file.path(tdir, "nmfs-a") ) - + create_batch_certificates( registry = registry, participants = participants, @@ -79,8 +79,36 @@ test_that("create_batch_certificates works", { cohort_type = "nmfs", output_dir = file.path(tdir, "nasa") ) - + expect_snapshot( list.files(tdir, recursive = TRUE) ) }) + +test_that("create_batch_certificates gives message when it fails but still proceeds", { + tdir <- withr::local_tempdir() + + participants <- dplyr::tibble( + cohort = "2024-nmfs-champions-a", + first = "Sally", + last = "Green" + ) + + registry <- dplyr::tibble( + cohort_name = "2024-nmfs-champions-a", + date_start = "yesterday", # will cause certificate create to fail + date_end = "2024-02-02", + cohort_website = "https://nmfs-openscapes.github.io/2024-nmfs-champions" + ) + + expect_snapshot( + create_batch_certificates( + registry = registry, + participants = participants, + cohort_name = "2024-nmfs-champions-a", + cohort_type = "nmfs", + output_dir = file.path(tdir, "nmfs-a") + ), + transform = \(x) gsub("\\[1\\] .+(/nmfs-a)", "[1] \"output_dirname\\1", x) + ) +})