diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 027a62bc..2e5b2526 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -12,6 +12,9 @@ jobs: env: MUGGLE_PKG_NAME: ${{ github.event.repository.name }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + crossref_plus: ${{ secrets.CR_MD_PLUS_TOKEN }} + # TODO commiter email here https://github.com/subugoe/metar/issues/110 + crossref_email: held@sub.uni-goettingen.de steps: - uses: actions/checkout@v2 - name: Cache R Packages diff --git a/DESCRIPTION b/DESCRIPTION index 5a22406e..1e5331d1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -49,10 +49,13 @@ Suggests: testthat, subugoetheme, shinycaas, - rmarkdown + rmarkdown, + bench (>= 1.1.1) URL: https://subugoe.github.io/metacheck, https://github.com/subugoe/metacheck BugReports: https://github.com/subugoe/metacheck/issues Remotes: subugoe/subugoetheme@1.1.1, subugoe/shinycaas@1.0.0, + subugoe/rcrossref@51d036808c1dc1f46cf1bad1b136e97ad213e162 rstudio/shinyvalidate +Config/testthat/edition: 3 diff --git a/R/test_helper.R b/R/test_helper.R new file mode 100644 index 00000000..cd3c20ed --- /dev/null +++ b/R/test_helper.R @@ -0,0 +1,3 @@ +is_valid_email <- function(x) { + grepl("^\\s*[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\s*$", as.character(x), ignore.case=TRUE) +} diff --git a/tests/testthat.R b/tests/testthat.R new file mode 100644 index 00000000..bf96ceda --- /dev/null +++ b/tests/testthat.R @@ -0,0 +1,4 @@ +library(testthat) +library(metacheck) + +test_check("metacheck") diff --git a/tests/testthat/test-cr_auth.R b/tests/testthat/test-cr_auth.R new file mode 100644 index 00000000..3c78c7d7 --- /dev/null +++ b/tests/testthat/test-cr_auth.R @@ -0,0 +1,22 @@ +test_that("crossref metadata is enabled", { + # could not capture with header response from rcrossref, + # so result must be inspected manually in logs + rcrossref::cr_abstract('10.1109/TASC.2010.2088091', verbose = TRUE) + expect_equal(1, 1) +}) + +test_that("crossref metadata plus is faster", { + skip("Test does not work; times are often the same.") + with_mdplus <- bench::bench_time( + rcrossref::cr_agency(sample_dois[1:10], .progress = "text") + )["real"] + withr::local_envvar(.new = c("crossref_plus" = "")) + without_mdplus <- bench::bench_time( + rcrossref::cr_agency(sample_dois[1:10], .progress = "text") + )["real"] + expect_lte(with_mdplus, without_mdplus) +}) + +test_that("metacheck declares polite user agent", { + expect_true(is_valid_email(Sys.getenv("crossref_email"))) +})