R/test-secret-santa.R

Defines functions send_test_email test_secret_santa

Documented in test_secret_santa

#' Test secret santa process
#'
#' @description Prior to exeuting \code{run_secret_santa}, you may wish to test
#'              the setup by sending yourself an e-mail generated by the
#'              package.  This function will mimic the real process, but will
#'              only send one e-mail, and only to the address you specify,
#'              so you can ensure it looks the way you intend.
#' 
#' @param config_path file path to the \code{secretsanta} config JSON.
#' @param mail_to the e-mail address to which the test message will be sent.
#'
#' @export
test_secret_santa <- function(config_path, mail_to) {
  config     <- jsonlite::fromJSON(config_path)
  santa_data <- make_santa_data(config)

  send_test_email(config, santa_data, mail_to)
}


send_test_email <- function(config, santa_data, mail_to) {
  santa_data$giver_email <- mail_to
  test_mime <- build_mime(config, santa_data[1, , drop = FALSE])
  gmailr::gm_send_message(test_mime)
  print(paste("Sent email to", santa_data$giver_email[1]))
}
ataustin/secretsanta documentation built on Nov. 27, 2024, 7:39 p.m.