Skip to content

Commit 3aabdd3

Browse files
authored
Merge pull request #224 from cmu-delphi/ndefries/compare-vers-to-asterisk
Support version params `as_of` and `issues` passed as Date objects
2 parents 1a5e8b5 + fb02033 commit 3aabdd3

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

R/utils.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ check_is_recent <- function(dates, max_age) {
2929
#'
3030
#' @keywords internal
3131
check_is_cachable <- function(epidata_call, fetch_args) {
32-
as_of_cachable <- (!is.null(epidata_call$params$as_of) && epidata_call$params$as_of != "*")
33-
issues_cachable <- (!is.null(epidata_call$params$issues) && all(epidata_call$params$issues != "*"))
32+
as_of_cachable <- (!is.null(epidata_call$params$as_of) && !identical(epidata_call$params$as_of, "*"))
33+
issues_cachable <- (!is.null(epidata_call$params$issues) && all(!identical(epidata_call$params$issues, "*")))
3434
is_cachable <- (
3535
!is.null(cache_environ$epidatr_cache) &&
3636
(as_of_cachable || issues_cachable) &&

tests/testthat/test-utils.R

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,47 @@ test_that("format_list", {
2020
expect_identical(format_list(list("5", "6")), "5,6")
2121
expect_identical(format_list(list("*", "*")), "*,*")
2222
})
23+
24+
test_that("check_is_cachable can handle both str and date inputs of various lengths", {
25+
epidata_call <- list(
26+
params = list(as_of = NULL, issues = NULL)
27+
)
28+
fetch_args <- fetch_args_list()
29+
30+
expect_no_error(check_is_cachable(epidata_call, fetch_args))
31+
32+
# as_of string
33+
epidata_call$params$as_of <- "2022-01-01"
34+
epidata_call$params$issues <- NULL
35+
expect_no_error(check_is_cachable(epidata_call, fetch_args))
36+
37+
# as_of date
38+
epidata_call$params$as_of <- as.Date("2022-01-01")
39+
epidata_call$params$issues <- NULL
40+
expect_no_error(check_is_cachable(epidata_call, fetch_args))
41+
42+
# issues single string
43+
epidata_call$params$as_of <- NULL
44+
epidata_call$params$issues <- "2022-01-01"
45+
expect_no_error(check_is_cachable(epidata_call, fetch_args))
46+
47+
# issues string vector
48+
epidata_call$params$as_of <- NULL
49+
epidata_call$params$issues <- c("2022-01-01", "2022-02-01")
50+
expect_no_error(check_is_cachable(epidata_call, fetch_args))
51+
52+
# issues single date
53+
epidata_call$params$as_of <- NULL
54+
epidata_call$params$issues <- as.Date("2022-01-01")
55+
expect_no_error(check_is_cachable(epidata_call, fetch_args))
56+
57+
# issues date vector
58+
epidata_call$params$as_of <- NULL
59+
epidata_call$params$issues <- c(as.Date("2022-01-01"), as.Date("2022-02-01"))
60+
expect_no_error(check_is_cachable(epidata_call, fetch_args))
61+
62+
# issues epirange
63+
epidata_call$params$as_of <- NULL
64+
epidata_call$params$issues <- epirange(as.Date("2022-01-01"), as.Date("2022-02-01"))
65+
expect_no_error(check_is_cachable(epidata_call, fetch_args))
66+
})

0 commit comments

Comments
 (0)