Skip to content

Commit 5311e0c

Browse files
committed
test wildcard and day/week support
1 parent 83e7ce3 commit 5311e0c

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

R/endpoints.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@ pub_covid_hosp_facility <- function(
209209
cli::cli_warn(coercion_msg, class = "epidatr__epirange_week_coercion")
210210
collection_weeks <- reformat_epirange(collection_weeks, to_type = "day")
211211
# Single week date.
212-
} else if ((test_integerish(collection_weeks) || test_character(collection_weeks)) &&
213-
nchar(collection_weeks) == 6) {
212+
} else if (
213+
(test_integerish(collection_weeks) || test_character(collection_weeks)) &&
214+
nchar(collection_weeks) == 6
215+
) {
214216
cli::cli_warn(coercion_msg, class = "epidatr__single_week_coercion")
215217
collection_weeks <- parse_api_week(collection_weeks)
216218
}

tests/testthat/test-endpoints.R

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,25 @@ test_that("basic_epidata_call", {
141141
time_values = epirange(201501, 202001),
142142
fetch_args = fetch_args_list(dry_run = TRUE)
143143
) %>% request_url())
144+
expect_no_error(pvt_twitter(
145+
auth = "yourkey",
146+
locations = "CA",
147+
time_type = "day",
148+
time_values = epirange(20150101, 20200101),
149+
fetch_args = fetch_args_list(dry_run = TRUE)
150+
) %>% request_url())
144151
expect_no_error(pub_wiki(
145152
articles = "avian_influenza",
146153
time_type = "week",
147154
time_values = epirange(201501, 202001),
148155
fetch_args = fetch_args_list(dry_run = TRUE)
149156
) %>% request_url())
157+
expect_no_error(pub_wiki(
158+
articles = "avian_influenza",
159+
time_type = "day",
160+
time_values = epirange(20150101, 20200101),
161+
fetch_args = fetch_args_list(dry_run = TRUE)
162+
) %>% request_url())
150163
})
151164

152165
test_that("endoints accept wildcard for date parameter", {
@@ -324,6 +337,44 @@ test_that("endoints accept wildcard for date parameter", {
324337
))
325338
expect_identical(call$params$epiweeks$from, 100001)
326339
expect_identical(call$params$epiweeks$to, 300001)
340+
341+
expect_no_error(call <- pvt_twitter(
342+
auth = "yourkey",
343+
locations = "CA",
344+
time_type = "week",
345+
time_values = "*",
346+
fetch_args = fetch_args_list(dry_run = TRUE)
347+
))
348+
expect_identical(call$params$epiweeks$from, 100001)
349+
expect_identical(call$params$epiweeks$to, 300001)
350+
351+
expect_no_error(call <- pvt_twitter(
352+
auth = "yourkey",
353+
locations = "CA",
354+
time_type = "day",
355+
time_values = "*",
356+
fetch_args = fetch_args_list(dry_run = TRUE)
357+
))
358+
expect_identical(call$params$dates$from, 10000101)
359+
expect_identical(call$params$dates$to, 30000101)
360+
361+
expect_no_error(call <- pub_wiki(
362+
articles = "avian_influenza",
363+
time_type = "week",
364+
time_values = "*",
365+
fetch_args = fetch_args_list(dry_run = TRUE)
366+
))
367+
expect_identical(call$params$epiweeks$from, 100001)
368+
expect_identical(call$params$epiweeks$to, 300001)
369+
370+
expect_no_error(call <- pub_wiki(
371+
articles = "avian_influenza",
372+
time_type = "day",
373+
time_values = "*",
374+
fetch_args = fetch_args_list(dry_run = TRUE)
375+
))
376+
expect_identical(call$params$dates$from, 10000101)
377+
expect_identical(call$params$dates$to, 30000101)
327378
})
328379

329380
test_that("endpoints fail when given args via dots", {

0 commit comments

Comments
 (0)