tests/testthat/test-token.R

token <- "wrong"
msg <- "Unauthorized (HTTP 401)"
q_url <- rcites_url(paste0("taxon_concepts/", tx_id, "/distributions.json"))

test_that("test token", {
  old <- Sys.getenv("SPECIESPLUS_TOKEN")
  suppressMessages({
    on.exit(set_token(old))
    expect_snapshot(set_token("hackme"))
    expect_identical(rcites_getsecret(), "hackme")
    expect_snapshot(forget_token())
    expect_snapshot(set_token("!"))
    expect_identical(rcites_getsecret(), "!")
  })
})

# test_that("caught wrong token", {
#   vcr::use_cassette("wrong_token", {
#     expect_warning(res <- rcites_res(q_url, token, FALSE, TRUE),
#       class = "http_401"
#     )
#   }, match_requests_on = "headers")
# })
ibartomeus/citesr documentation built on Feb. 20, 2023, 6:16 a.m.