diff --git a/tests/fixtures/check_last_audit.yml b/tests/fixtures/check_last_audit.yml new file mode 100644 index 0000000..c37d5ef --- /dev/null +++ b/tests/fixtures/check_last_audit.yml @@ -0,0 +1,35 @@ +http_interactions: +- request: + method: get + uri: https://bugs.r-project.org/bugzilla/rest/last_audit_time + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + Authorization: My bearer token is safe + X-BUGZILLA-API-KEY: Removing this header too just in case + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + date: Fri, 18 Jun 2021 20:57:31 GMT + server: gazelle + etag: nuyzry+9UExbGXwyRTkrfQ + content-length: '42' + content-type: application/json; charset=UTF-8 + access-control-allow-headers: accept, content-type, origin, user-agent, x-requested-with, + x-bugzilla-api-key, x-bugzilla-login, x-bugzilla-token, x-bugzilla-password + access-control-allow-origin: '*' + x-content-type-options: nosniff + x-frame-options: SAMEORIGIN + x-xss-protection: 1; mode=block + body: + encoding: UTF-8 + file: no + string: '{"last_audit_time":"2021-06-18T20:47:32Z"}' + recorded_at: 2021-06-18 20:57:31 GMT + recorded_with: vcr/0.6.0, webmockr/0.8.0 diff --git a/tests/testthat/_snaps/api.md b/tests/testthat/_snaps/api.md new file mode 100644 index 0000000..915943b --- /dev/null +++ b/tests/testthat/_snaps/api.md @@ -0,0 +1,78 @@ +# create_bugzilla_key() works [plain] + + Code + create_bugzilla_key() + Message + i Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. + v Found key `R_BUGZILLA`. + v Using key `R_BUGZILLA`. + x Not authenticated on this site. + v Authenticated on this site! + +# create_bugzilla_key() works [unicode] + + Code + create_bugzilla_key() + Message + ℹ Reading cached keys on '/home/data/.cache/R/bugRzilla/.Renviron'. + ✔ Found key `R_BUGZILLA`. + ✔ Using key `R_BUGZILLA`. + ✖ Not authenticated on this site. + ✔ Authenticated on this site! + +# check_key() works [plain] + + Code + check_key(key_name = missing_key(), verbose = FALSE) + Output + [1] TRUE + +# check_key() works [unicode] + + Code + check_key(key_name = missing_key(), verbose = FALSE) + Output + [1] TRUE + +# use_key() works [plain] + + Code + use_key(missing_key()) + Message + v Using key `R_BUGZILLA`. + +# use_key() works [unicode] + + Code + use_key(missing_key()) + Message + ✔ Using key `R_BUGZILLA`. + +# valid_key() works [plain] + + Code + valid_key(key = "hgfcchg12") + Output + [1] TRUE + +# valid_key() works [ansi] + + Code + valid_key(key = "hgfcchg12") + Output + [1] TRUE + +# valid_key() works [unicode] + + Code + valid_key(key = "hgfcchg12") + Output + [1] TRUE + +# valid_key() works [fancy] + + Code + valid_key(key = "hgfcchg12") + Output + [1] TRUE + diff --git a/tests/testthat/setup-bugRzilla.R b/tests/testthat/setup-bugRzilla.R index e56a6b7..76b34cc 100644 --- a/tests/testthat/setup-bugRzilla.R +++ b/tests/testthat/setup-bugRzilla.R @@ -15,7 +15,7 @@ use_key() invisible(vcr::vcr_configure( dir = vcr_dir, filter_request_headers = list( - "Authorization" = "My bearer token is safe", - "X-BUGZILLA-API-KEY" = "Removing this header too just in case") + "Authorization" = "My bearer token is safe", + "X-BUGZILLA-API-KEY" = "Removing this header too just in case") )) vcr::check_cassette_names() diff --git a/tests/testthat/test-api.R b/tests/testthat/test-api.R new file mode 100644 index 0000000..e2a6bdf --- /dev/null +++ b/tests/testthat/test-api.R @@ -0,0 +1,48 @@ +# This is to check the create_bugzilla_key function +cli::test_that_cli(configs = c("plain", "unicode"), "create_bugzilla_key() works", { + skip_on_ci() + expect_snapshot({ + create_bugzilla_key() + }) +}) + + +# This is to check the set_key function +test_that("set_key works", { + skip_on_ci() + sk <- set_key() + expect_equal(write_renviron(key = sk, value = sk, file = app_file()), NULL) +}) + + +# This is to check the check_key function +cli::test_that_cli(configs = c("plain", "unicode"), "check_key() works", { + skip_on_ci() + expect_snapshot({ + check_key(key_name = missing_key(), verbose = FALSE) + }) +}) + +# This is to check the use_key function +cli::test_that_cli(configs = c("plain", "unicode"), "use_key() works", { + expect_snapshot({ + use_key(missing_key()) + }) +}) + + +# This is to check the check_last_audit function +test_that("check_last_audit works", { + vcr::use_cassette("check_last_audit", { + cla <- check_last_audit() + }) + expect_s3_class(cla, "POSIXlt") +}) + + +# This is to check the valid_key function +cli::test_that_cli("valid_key() works", { + expect_snapshot({ + valid_key(key = "hgfcchg12") + }) +}) diff --git a/tests/testthat/test-bug_search.R b/tests/testthat/test-bug_search.R new file mode 100644 index 0000000..2b92eb7 --- /dev/null +++ b/tests/testthat/test-bug_search.R @@ -0,0 +1,21 @@ +valid_parameters <- c("alias", "assigned_to", "component", "creation_time", + "creator", "id", "last_change_time", "limit", + "longdescs.count", "offset", "op_sys", "platform", + "priority", "product", "resolution", "severity", + "status", "summary", "tags", "target_milestone", + "qa_contact", "url", "version", "whiteboard", + "quicksearch") + +# test_that("bug_search works", { +# vcr::use_cassette("bug_search", { +# bs <- bug_search(id=1) +# url <- "https://bugs.r-project.org/bugzilla/rest/bug?id=1" +# }) +# expect_equal(paste0(missing_host(), "rest/bug?", params(id=1)), url) +# }) + +test_that("params works", { + par <- params() + expect_true(all(names(par) %in% valid_parameters)) + expect_error(params(ids=1)) +}) diff --git a/tests/testthat/test-post_help.R b/tests/testthat/test-post_help.R new file mode 100644 index 0000000..92c3e0c --- /dev/null +++ b/tests/testthat/test-post_help.R @@ -0,0 +1,18 @@ +# yes <- c("Yes", "Definitely", "Positive", "For sure", "Yup", "Yeah", +# "Absolutely") +# no <- c("Not sure", "Not now", "Negative", "No", "Nope", "Absolutely not") +# +# cli::test_that_cli(configs = c("plain"), "read_documentation() works",{ +# expect_snapshot({ +# expect_equal(read_documentation(), "Cancel") +# # expect_equal(read_documentation(), no) +# # expect_equal(read_documentation(), yes) +# }) +# }) + +# test_that("ask_confirmation works", { +# vcr::use_cassette("ask_confirmation", { +# ac <- ask_confirmation(title = NULL, positive = yes, negative = no) +# }) +# expect_equal(sample(positive, 1), sample(negative, 2)) +# })