diff --git a/R/read_smips.R b/R/read_smips.R index 03d8a6e..19f43fd 100644 --- a/R/read_smips.R +++ b/R/read_smips.R @@ -49,7 +49,6 @@ read_smips <- function(collection = "totalbucket", api_key = get_key(), max_tries = 3L, initial_delay = 1L) { - # Fix any invalid key here, rather than in get_key() in case a user passes a key api_key <- gsub("/", "%2f", api_key, fixed = TRUE) @@ -125,6 +124,7 @@ read_smips <- function(collection = "totalbucket", x <- lubridate::parse_date_time(x, c( # TODO: B and b are the same, maybe remove one later # Are they? `b` should be e.g., "Jan", `B` should be, e.g., "January" + # based on `base::strptime()`, https://rdrr.io/r/base/strptime.html, for parsing inputs, they are the same "Ymd", "dmY", "BdY", "Bdy", "bdY", "bdy" ), tz = tz), warning = function(c) { @@ -168,7 +168,7 @@ read_smips <- function(collection = "totalbucket", #' @noRd #' @keywords Internal .check_collection_agreement <- function(.collection, .day) { - .this_year <- lubridate::year(lubridate::today()) + # .this_year <- lubridate::year(lubridate::today()) .last_week <- lubridate::today() - 7 .url_year <- lubridate::year(.day) diff --git a/tests/testthat/test-get_key.R b/tests/testthat/test-get_key.R new file mode 100644 index 0000000..fc59b04 --- /dev/null +++ b/tests/testthat/test-get_key.R @@ -0,0 +1,12 @@ +test_that("Key retrieval works when a key exists", { + a_key <- "some_api_key" + Sys.setenv(TERN_API_KEY = a_key) + + expect_identical(get_key(), a_key) +}) + +test_that("Key retrieval throws errors when a key does not exist", { + Sys.setenv(TERN_API_KEY = "") + + expect_error(get_key()) +})