Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add vcr testing framework and example unittests for get_public_timeline #36

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* text=auto
tests/fixtures/**/* -diff
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Suggests:
knitr,
rmarkdown,
testthat (>= 3.0.0),
rstudioapi
rstudioapi,
vcr (>= 0.6.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
382 changes: 382 additions & 0 deletions tests/fixtures/get_public_timeline_anonymous.yml

Large diffs are not rendered by default.

326 changes: 326 additions & 0 deletions tests/fixtures/get_public_timeline_default.yml

Large diffs are not rendered by default.

383 changes: 383 additions & 0 deletions tests/fixtures/get_public_timeline_instance.yml

Large diffs are not rendered by default.

225 changes: 225 additions & 0 deletions tests/fixtures/get_public_timeline_instance_local.yml

Large diffs are not rendered by default.

408 changes: 408 additions & 0 deletions tests/fixtures/get_public_timeline_notparse.yml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tests/testthat/setup-rtoot.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
library("vcr") # *Required* as vcr is set up on loading
invisible(
vcr::vcr_configure(
filter_sensitive_data = list("<<<MASTODON TOKEN>>>" = Sys.getenv('RTOOT_DEFAULT_TOKEN')),
dir = vcr::vcr_test_path("fixtures")
))
vcr::check_cassette_names()
26 changes: 26 additions & 0 deletions tests/testthat/test-get_public_timeline.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
test_that("get_public_timeline", {
vcr::use_cassette("get_public_timeline_default", {
x <- get_public_timeline()
})
expect_true(nrow(x) != 0)
expect_true("tbl_df" %in% class(x))
vcr::use_cassette("get_public_timeline_notparse", {
x <- get_public_timeline(parse = FALSE)
})
expect_false("tbl_df" %in% class(x))
vcr::use_cassette("get_public_timeline_instance", {
x <- get_public_timeline(instance = "mastodon.social")
})
expect_true(nrow(x) != 0)
expect_true("tbl_df" %in% class(x)) ## we can't test because it can contain statuses from another instance
vcr::use_cassette("get_public_timeline_instance_local", {
x <- get_public_timeline(local = TRUE, limit = 10)
})
## it should have only one type of hostname
expect_equal(length(unique(sapply(x$uri, function(uri) httr::parse_url(uri)$hostname))), 1)
vcr::use_cassette("get_public_timeline_anonymous", {
x <- get_public_timeline(instance = "mastodon.social", anonymous = TRUE)
})
expect_true(nrow(x) != 0)
expect_true("tbl_df" %in% class(x)) ## we can't test because it can contain statuses from another instance
})