Skip to content

Commit

Permalink
Merge pull request #16 from AAGI-AUS/feature/add-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhsparks authored Dec 2, 2024
2 parents 6654f07 + 138f77b commit fdfd890
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/read_smips.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-get_key.R
Original file line number Diff line number Diff line change
@@ -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())
})

0 comments on commit fdfd890

Please sign in to comment.