Skip to content

Commit

Permalink
Add check for multiple param values with one using git add .
Browse files Browse the repository at this point in the history
  • Loading branch information
asadow committed Mar 6, 2024
1 parent cd1ff19 commit bc64bac
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 76 deletions.
65 changes: 0 additions & 65 deletions R/list_gets_reqs.R

This file was deleted.

28 changes: 22 additions & 6 deletions R/utils-check.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,34 @@ check_params <- function(x, call = rlang::caller_env()) {
if (any(grepl("key", np))) {
keys <- np[grep("key", np)]
cli::cli_abort(c(
"Prevented filter {.arg keys} from being included in the request URL.",
"i" = "Use environment variables for credentials instead."
"Prevented filter {.code {keys}} from being included in the request URL.",
"i" = "Use {.fun mm_authorize} or environment variables for credentials
instead."
))
}

if (any(startsWith(np, "."))) {
dotted <- np[grep("\\.", np)]
x_has_bangbang <- x |>
purrr::map_lgl(\(y) stringr::str_detect(y, "!!") |> any())
x_has_bb_and_more <- x[x_has_bangbang] |> purrr::map_dbl(length) > 1

if (any(x_has_bb_and_more)) {

x_ls <- x[x_has_bb_and_more] |>
imap_chr(\(x, idx) glue::glue("`{idx}` has length {length(x)}."))
names(x_ls) <- rep("x", length(x_ls))

cli::cli_abort(c(
"Prevented filter {.arg dotted} from being included in the request URL.",
"i" = 'Did you mean `{sub("\\\\.", "", dotted[1])} = "<value>"`?'
"{.code {names(x_has_bb_and_more)}} must have length 1 with use of `!!`.",
x_ls,
"i" = "
{.fun mm_data} performs and binds the results of separate GET requests for
each value supplied to a parameter (as Megamation's API won't allow
multiple values in a single request).
Combining the results of a request that uses `!!` with the results of
another request can result in duplicate data."
))
}

return()
}

Expand Down
5 changes: 0 additions & 5 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ test_that("check_bool() errors on TRUE string", {
expect_error(check_bool(allfields), "`allfields` must be")
})

test_that("check_params() errors on dot prefix", {
params <- list(.allfields = TRUE)
expect_error(check_params(params), "Prevented filter")
})

test_that("check_string() returns error message", {
expect_error(check_string(5), "must be a single string")
})
Expand Down

0 comments on commit bc64bac

Please sign in to comment.