Skip to content

Commit

Permalink
test create_batch_certificates for failure
Browse files Browse the repository at this point in the history
  • Loading branch information
ateucher committed Dec 10, 2024
1 parent 57b9b80 commit 77a2a17
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 13 deletions.
12 changes: 12 additions & 0 deletions tests/testthat/_snaps/create_certificate.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"

54 changes: 41 additions & 13 deletions tests/testthat/test-create_certificate.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -63,24 +63,52 @@ test_that("create_batch_certificates works", {
"https://nasa-openscapes.github.io/2024-nasa-champions"
)
)

create_batch_certificates(
registry = registry,
participants = participants,
cohort_name = "2024-nmfs-champions-a",
cohort_type = "nmfs",
output_dir = file.path(tdir, "nmfs-a")
)

create_batch_certificates(
registry = registry,
participants = participants,
cohort_name = "2024-champions",
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)
)
})

0 comments on commit 77a2a17

Please sign in to comment.