Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherkenny committed Nov 26, 2023
1 parent fb3aa0a commit 017dd6d
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 8 deletions.
8 changes: 6 additions & 2 deletions R/record_like.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
#' @export
#'
#' @examplesIf has_bluesky_pass() & has_bluesky_user()
#' bs_like('https://bsky.app/profile/bskyr.bsky.social/post/3kf2577exva2x')
#' bs_like(post = 'https://bsky.app/profile/bskyr.bsky.social/post/3kf2577exva2x')
bs_like <- function(post,
user = get_bluesky_user(), pass = get_bluesky_pass(),
auth = bs_auth(user, pass), clean = TRUE) {
post_rcd <- bs_get_record(post, auth = auth, clean = FALSE)
if (is.list(post) && all(c('uri', 'cid') %in% names(post))) {
post_rcd <- post
} else {
post_rcd <- bs_get_record(post, auth = auth, clean = FALSE)
}

like <- list(
subject = list(
Expand Down
3 changes: 0 additions & 3 deletions R/record_post.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#' Make a post on Bluesky Social
#'
#' Note: This function currently only supports text posts. Further support
#' planned for version 0.1.0
#'
#' @param text text of post
#' @param images character vector of paths to images to attach to post
#' @param images_alt character vector of alt text for images. Must be same length as `images` if used.
Expand Down
2 changes: 1 addition & 1 deletion man/bs_like.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions man/bs_post.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ if (has_bluesky_pass() && has_bluesky_user()) {
auth <- list(accessJwt = '')
}

rcd <- list(
uri = 'at://did:plc:5c2r73erhng4bszmxlfdtscf/app.bsky.feed.post/3kf2577exva2x',
cid = 'bafyreibf5g5pkajhv4afkronrzyu3ywfk7dkjt5sdjdvkawkhcwv2l5fgu'
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"uri": "at://did:plc:5c2r73erhng4bszmxlfdtscf/app.bsky.feed.like/3kf4mlmbev42x",
"cid": "bafyreifidgs3zisskplffwrn7abz6gtg2h7acpyc6wtpbgyao37jdbn52q"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"uri": "at://did:plc:5c2r73erhng4bszmxlfdtscf/app.bsky.feed.like/3kf4mlmfmhb2j",
"cid": "bafyreictlgr7qud5vrrytk6fnu6t6alpncovslx7j57wauvq7qygub4hmy"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
{
"records": [
{
"uri": "at://did:plc:wpe35pganb6d4pg4ekmfy6u5/app.bsky.feed.post/3kepscxiljc22",
"cid": "bafyreih2dhtkm43egdhjlpatxrljcudjemarco2qb3jprqvewg3gmt3x2q",
"value": {
"text": "It's that time of the semester. Made with the ThemePark package in #rstats",
"$type": "app.bsky.feed.post",
"embed": {
"$type": "app.bsky.embed.images",
"images": [
{
"alt": "A line graph, with week on the x axis and probability that the audience lets the presenter present on the y axis. The slope is negative.",
"image": {
"$type": "blob",
"ref": {
"$link": "bafkreidwfye5fxj5t2ad5vdh4faxnokkgrk4eb2txfbdakzkbllq2mqbxi"
},
"mimeType": "image/jpeg",
"size": 381665
},
"aspectRatio": {
"width": 1751,
"height": 1006
}
}
]
},
"langs": [
"en"
],
"facets": [
{
"index": {
"byteEnd": 74,
"byteStart": 67
},
"features": [
{
"tag": "rstats",
"$type": "app.bsky.richtext.facet#tag"
}
]
}
],
"createdAt": "2023-11-21T18:50:00.821Z"
}
},
{
"uri": "at://did:plc:wpe35pganb6d4pg4ekmfy6u5/app.bsky.feed.post/3kc2bxjdrfm23",
"cid": "bafyreigseo27m7usmq7bzyot2czzny4ocayddierhhf6fhm6ynh65nehh4",
"value": {
"text": "The tinytiger R package is now updated to version 0.0.8 on CRAN. No major user changes. This update fixes some documentation and adjusts tests to fail more gracefully if the internet is unstable at the time of testing.\n\ncran.r-project.org/package=tiny...",
"$type": "app.bsky.feed.post",
"langs": [
"en"
],
"facets": [
{
"index": {
"byteEnd": 254,
"byteStart": 220
},
"features": [
{
"uri": "https://cran.r-project.org/package=tinytiger",
"$type": "app.bsky.richtext.facet#link"
}
]
}
],
"createdAt": "2023-10-18T18:40:58.448Z"
}
},
{
"uri": "at://did:plc:wpe35pganb6d4pg4ekmfy6u5/app.bsky.feed.post/3kbisbltrok2l",
"cid": "bafyreicoyeu2ec3p76rjvkm2ooz2j644iwd2k6srgmd4fejx7cwpovd7mm",
"value": {
"text": "A quick word cloud made in R with ggwordcloud from today's oral arguments in Alexander v. SC Conference of NAACP. Pretty similar to the Alabama case last year (x.com/Chris_T_Kenn...)",
"$type": "app.bsky.feed.post",
"embed": {
"$type": "app.bsky.embed.images",
"images": [
{
"alt": "A word cloud in the shape of South Carolina with words from the oral argument in Alexander on 2023-10-11. Top 10 words are court, district, race, evidence, data, racial, case, map, dr",
"image": {
"$type": "blob",
"ref": {
"$link": "bafkreibcne4rx4wetzzg5r3fafo47v2rqqylvsor3mf35ewdwzdy2uatri"
},
"mimeType": "image/jpeg",
"size": 526461
},
"aspectRatio": {
"width": 2000,
"height": 1667
}
}
]
},
"langs": [
"en"
],
"facets": [
{
"index": {
"byteEnd": 181,
"byteStart": 160
},
"features": [
{
"uri": "https://x.com/Chris_T_Kenny/status/1577407724395978753?s=20",
"$type": "app.bsky.richtext.facet#link"
}
]
}
],
"createdAt": "2023-10-11T19:45:01.201Z"
}
},
{
"uri": "at://did:plc:wpe35pganb6d4pg4ekmfy6u5/app.bsky.feed.post/3kasvzedyyu2r",
"cid": "bafyreigwfne74munn6fsffzu5w25vpsbecwdxqztucefo7o5emu4gfsyam",
"value": {
"text": "Can’t say I expected that to work on the first try, but the AT Protocol is pretty cool.",
"$type": "app.bsky.feed.post",
"langs": [
"en"
],
"reply": {
"root": {
"cid": "bafyreifijeifzyh724gobyh3s2cswupnzib3wdbhrtmozbt4abb3wmyvaa",
"uri": "at://did:plc:wpe35pganb6d4pg4ekmfy6u5/app.bsky.feed.post/3kasvrt6b372y"
},
"parent": {
"cid": "bafyreifijeifzyh724gobyh3s2cswupnzib3wdbhrtmozbt4abb3wmyvaa",
"uri": "at://did:plc:wpe35pganb6d4pg4ekmfy6u5/app.bsky.feed.post/3kasvrt6b372y"
}
},
"createdAt": "2023-10-03T02:53:25.697Z"
}
},
{
"uri": "at://did:plc:wpe35pganb6d4pg4ekmfy6u5/app.bsky.feed.post/3kasvrt6b372y",
"cid": "bafyreifijeifzyh724gobyh3s2cswupnzib3wdbhrtmozbt4abb3wmyvaa",
"value": {
"text": "Test post from rstats (attempt #1)",
"$type": "app.bsky.feed.post",
"createdAt": "2023-10-03T02:49:12.980686Z"
}
}
],
"cursor": "3kasvrt6b372y"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"uri": "at://did:plc:5c2r73erhng4bszmxlfdtscf/app.bsky.feed.post/3kf4mlmkp2b2y",
"cid": "bafyreih7q6j7sp4zpfljzsse3pvnyzewrcc7f4cwdilvshaxxnbnka5zai"
}
13 changes: 13 additions & 0 deletions tests/testthat/test-record_like.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
with_mock_dir("t/r/like", {
test_that("`bs_like()` works", {
x <- bs_like(post = rcd, auth = auth)
expect_s3_class(x, 'tbl_df')
})
})

with_mock_dir("t/r/likeL", {
test_that("`bs_like()` works", {
x <- bs_like(post = rcd, auth = auth, clean = FALSE)
expect_equal(class(x), 'list')
})
})
6 changes: 6 additions & 0 deletions tests/testthat/test-record_post.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
with_mock_dir("t/r/postT", {
test_that("`bs_post()` just text works", {
x <- bs_post(text = 'test post', auth = auth)
expect_s3_class(x, 'tbl_df')
})
})
8 changes: 8 additions & 0 deletions tests/testthat/test-repo_list_records.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ with_mock_dir("t/r/listrcd", {
expect_s3_class(x, 'tbl_df')
})
})

with_mock_dir("t/r/listrcdL", {
test_that("`bs_list_records()` works", {
x <- bs_list_records(repo = 'did:plc:wpe35pganb6d4pg4ekmfy6u5',
collection = 'app.bsky.feed.post', auth = auth, clean = FALSE)
expect_equal(class(x), 'list')
})
})

0 comments on commit 017dd6d

Please sign in to comment.