From e7511008e2702d3a587c3cbcbeecd26882ecabc4 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Tue, 15 Nov 2022 19:15:01 +0100 Subject: [PATCH] fix #75 --- R/auth.R | 11 ++--- R/post.R | 11 +++-- man/post_toot.Rd | 5 ++- man/post_user.Rd | 4 +- man/verify_credentials.Rd | 8 ++-- tests/fixtures/envvar_silent.yml | 57 +++++++++++++++++++++++++ tests/fixtures/post_toot_silent.yml | 56 ++++++++++++++++++++++++ tests/fixtures/post_toot_verbose.yml | 56 ++++++++++++++++++++++++ tests/fixtures/post_user_pin_silent.yml | 49 +++++++++++++++++++++ tests/testthat/test-auth_verify.R | 8 ++++ tests/testthat/test-post.R | 34 ++++++++++++--- 11 files changed, 278 insertions(+), 21 deletions(-) create mode 100644 tests/fixtures/envvar_silent.yml create mode 100644 tests/fixtures/post_toot_silent.yml create mode 100644 tests/fixtures/post_toot_verbose.yml create mode 100644 tests/fixtures/post_user_pin_silent.yml diff --git a/R/auth.R b/R/auth.R index 8444d80..d63621f 100644 --- a/R/auth.R +++ b/R/auth.R @@ -120,15 +120,16 @@ create_token <- function(client, type = "public"){ #' Verify mastodon credentials #' #' @param token bearer token, either public or user level -#' @return success or failure message of the verification process +#' @return Raise an error if the token is not valid. Return the response from the verification API invisibly otherwise. #' @details If you have created your token as an environment variable, use `verify_envvar` to verify your token. +#' @inheritParams auth_setup #' @examples #' \dontrun{ #' #read a token from a file #' verify_credentials(token) #' } #' @export -verify_credentials <- function(token) { +verify_credentials <- function(token, verbose = TRUE) { if(!is_auth_rtoot(token)){ stop("token is not an object of type rtoot_bearer") } @@ -149,7 +150,7 @@ verify_credentials <- function(token) { } success <- isTRUE(acc[["status_code"]] == 200L) if (success) { - message("Token of type \"", token$type, "\" for instance ", token$instance, " is valid") + sayif(verbose, "Token of type \"", token$type, "\" for instance ", token$instance, " is valid") } else { stop("Token not valid. Use auth_setup() to create a token") } @@ -158,9 +159,9 @@ verify_credentials <- function(token) { #' @export #' @rdname verify_credentials -verify_envvar <- function() { +verify_envvar <- function(verbose = TRUE) { token <- get_token_from_envvar() - verify_credentials(token) + verify_credentials(token, verbose = verbose) } #' save a bearer token to file diff --git a/R/post.R b/R/post.R index 9c4aafc..759cc0f 100644 --- a/R/post.R +++ b/R/post.R @@ -11,6 +11,7 @@ #' @param scheduled_at ISO 8601 Datetime at which to schedule a status. Must be at least 5 minutes in the future. #' @param language ISO 639 language code for this status. #' @return no return value, called for site effects +#' @inheritParams auth_setup #' @examples #' \dontrun{ #' # post a simple status @@ -29,7 +30,8 @@ post_toot <- function( spoiler_text = NULL, visibility = "public", scheduled_at = NULL, - language = NULL){ + language = NULL, + verbose = TRUE){ token <- check_token_rtoot(token) @@ -69,7 +71,7 @@ post_toot <- function( body=params, httr::add_headers(Authorization = paste0("Bearer ",token$bearer))) if(httr::status_code(r)==200L){ - message("Your toot has been posted!") + sayif(verbose, "Your toot has been posted!") } invisible(r) } @@ -103,6 +105,7 @@ check_media <- function(media, alt_text) { #' @param action character, one of "(un)follow","(un)block", "(un)mute", "(un)pin","note" #' @param comment character (if action="note"), The comment to be set on that user. Provide an empty string or leave out this parameter to clear the currently set note. #' @return no return value, called for site effects +#' @inheritParams auth_setup #' @examples #' \dontrun{ #' #follow a user @@ -111,7 +114,7 @@ check_media <- function(media, alt_text) { #' post_user("xxxxxx",action = "unfollow") #' } #' @export -post_user <- function(id,action = "follow",comment = "",token = NULL){ +post_user <- function(id,action = "follow",comment = "",token = NULL, verbose = TRUE){ token <- check_token_rtoot(token) action <- match.arg(action,c("follow","unfollow","block","unblock", "mute","unmute","pin","unpin","note")) @@ -127,7 +130,7 @@ post_user <- function(id,action = "follow",comment = "",token = NULL){ body = params, httr::add_headers(Authorization = paste0("Bearer ",token$bearer))) if(httr::status_code(r)==200L){ - message("successfully performed action on user") + sayif(verbose, "successfully performed action on user") } invisible(r) } diff --git a/man/post_toot.Rd b/man/post_toot.Rd index 7c5fc22..3b41f38 100644 --- a/man/post_toot.Rd +++ b/man/post_toot.Rd @@ -14,7 +14,8 @@ post_toot( spoiler_text = NULL, visibility = "public", scheduled_at = NULL, - language = NULL + language = NULL, + verbose = TRUE ) } \arguments{ @@ -37,6 +38,8 @@ post_toot( \item{scheduled_at}{ISO 8601 Datetime at which to schedule a status. Must be at least 5 minutes in the future.} \item{language}{ISO 639 language code for this status.} + +\item{verbose}{logical whether to display messages} } \value{ no return value, called for site effects diff --git a/man/post_user.Rd b/man/post_user.Rd index fd8cdd0..e5f5317 100644 --- a/man/post_user.Rd +++ b/man/post_user.Rd @@ -4,7 +4,7 @@ \alias{post_user} \title{Perform actions on an account} \usage{ -post_user(id, action = "follow", comment = "", token = NULL) +post_user(id, action = "follow", comment = "", token = NULL, verbose = TRUE) } \arguments{ \item{id}{character, user id to perform the action on} @@ -14,6 +14,8 @@ post_user(id, action = "follow", comment = "", token = NULL) \item{comment}{character (if action="note"), The comment to be set on that user. Provide an empty string or leave out this parameter to clear the currently set note.} \item{token}{user bearer token (read from file by default)} + +\item{verbose}{logical whether to display messages} } \value{ no return value, called for site effects diff --git a/man/verify_credentials.Rd b/man/verify_credentials.Rd index e00921c..2618c04 100644 --- a/man/verify_credentials.Rd +++ b/man/verify_credentials.Rd @@ -5,15 +5,17 @@ \alias{verify_envvar} \title{Verify mastodon credentials} \usage{ -verify_credentials(token) +verify_credentials(token, verbose = TRUE) -verify_envvar() +verify_envvar(verbose = TRUE) } \arguments{ \item{token}{bearer token, either public or user level} + +\item{verbose}{logical whether to display messages} } \value{ -success or failure message of the verification process +Raise an error if the token is not valid. Return the response from the verification API invisibly otherwise. } \description{ Verify mastodon credentials diff --git a/tests/fixtures/envvar_silent.yml b/tests/fixtures/envvar_silent.yml new file mode 100644 index 0000000..4205738 --- /dev/null +++ b/tests/fixtures/envvar_silent.yml @@ -0,0 +1,57 @@ +http_interactions: +- request: + method: get + uri: https://emacs.ch/api/v1/accounts/verify_credentials + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + Authorization: Bearer <<>> + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + cache-control: no-store + content-encoding: gzip + content-security-policy: 'base-uri ''none''; default-src ''none''; frame-ancestors + ''none''; font-src ''self'' https://emacs.ch; img-src ''self'' https: data: + blob: https://emacs.ch; style-src ''self'' https://emacs.ch ''nonce-9/p9d92Slffz1YqNYKPHVw==''; + media-src ''self'' https: data: https://emacs.ch; frame-src ''self'' https:; + manifest-src ''self'' https://emacs.ch; connect-src ''self'' data: blob: https://emacs.ch + https://emacs.ch wss://emacs.ch; script-src ''self'' https://emacs.ch ''wasm-unsafe-eval''; + child-src ''self'' blob: https://emacs.ch; worker-src ''self'' blob: https://emacs.ch' + content-type: application/json; charset=utf-8 + date: Tue, 15 Nov 2022 17:59:55 GMT + etag: W/"a682db363392a2c8dca0e904ac90c6a1" + permissions-policy: interest-cohort=() + server: Mastodon + strict-transport-security: max-age=63072000; includeSubDomains + vary: + - Accept-Encoding + - Origin + x-cached: MISS + x-content-type-options: nosniff + x-frame-options: DENY + x-ratelimit-limit: '300' + x-ratelimit-remaining: '296' + x-ratelimit-reset: '2022-11-15T18:00:00.039696Z' + x-request-id: bc0ad1a2-1cdd-40f6-8bc9-3616e2e093f7 + x-runtime: '0.018868' + x-xss-protection: '0' + body: + encoding: '' + file: no + string: '{"id":"109337011845249544","username":"chainsawriot","acct":"chainsawriot","display_name":"chainsawriot","locked":false,"bot":false,"discoverable":false,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"","url":"https://emacs.ch/@chainsawriot","avatar":"https://emacs.ch/system/accounts/avatars/109/337/011/845/249/544/original/00fc3aabc87d3564.jpg","avatar_static":"https://emacs.ch/system/accounts/avatars/109/337/011/845/249/544/original/00fc3aabc87d3564.jpg","header":"https://emacs.ch/headers/original/missing.png","header_static":"https://emacs.ch/headers/original/missing.png","followers_count":126,"following_count":63,"statuses_count":24,"last_status_at":"2022-11-15","noindex":true,"source":{"privacy":"public","sensitive":false,"language":"","note":"","fields":[{"name":"Stack","value":":emacs:, + R, stumpwm, linux, firefox","verified_at":null},{"name":"Research Interests","value":"Keine + Ahnung","verified_at":null},{"name":"Web","value":"https://chainsawriot.com/about/","verified_at":"2022-11-14T12:22:07.327+00:00"}],"follow_requests_count":0},"emojis":[{"shortcode":"emacs","url":"https://emacs.ch/system/custom_emojis/images/000/000/358/original/9f320443168e793f.png","static_url":"https://emacs.ch/system/custom_emojis/images/000/000/358/static/9f320443168e793f.png","visible_in_picker":true}],"fields":[{"name":"Stack","value":":emacs:, + R, stumpwm, linux, firefox","verified_at":null},{"name":"Research Interests","value":"Keine + Ahnung","verified_at":null},{"name":"Web","value":"\u003ca href=\"https://chainsawriot.com/about/\" + target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan + class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003echainsawriot.com/about/\u003c/span\u003e\u003cspan + class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e","verified_at":"2022-11-14T12:22:07.327+00:00"}],"role":{"id":"-99","name":"","permissions":"65536","color":"","highlighted":false}}' + recorded_at: 2022-11-15 17:59:55 GMT + recorded_with: vcr/1.1.0, webmockr/0.8.2 diff --git a/tests/fixtures/post_toot_silent.yml b/tests/fixtures/post_toot_silent.yml new file mode 100644 index 0000000..2007cf3 --- /dev/null +++ b/tests/fixtures/post_toot_silent.yml @@ -0,0 +1,56 @@ +http_interactions: +- request: + method: post + uri: https://emacs.ch/api/v1/statuses + body: + encoding: '' + string: status=testing in progress, please ignore,sensitive=false,visibility=public + headers: + Accept: application/json, text/xml, application/xml, */* + Authorization: Bearer <<>> + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + cache-control: no-store + content-encoding: gzip + content-security-policy: 'base-uri ''none''; default-src ''none''; frame-ancestors + ''none''; font-src ''self'' https://emacs.ch; img-src ''self'' https: data: + blob: https://emacs.ch; style-src ''self'' https://emacs.ch ''nonce-YxaYMg3GKP5qZdKUUau3Jw==''; + media-src ''self'' https: data: https://emacs.ch; frame-src ''self'' https:; + manifest-src ''self'' https://emacs.ch; connect-src ''self'' data: blob: https://emacs.ch + https://emacs.ch wss://emacs.ch; script-src ''self'' https://emacs.ch ''wasm-unsafe-eval''; + child-src ''self'' blob: https://emacs.ch; worker-src ''self'' blob: https://emacs.ch' + content-type: application/json; charset=utf-8 + date: Tue, 15 Nov 2022 18:04:22 GMT + etag: W/"c552b327bdc75e6e987171b7aadfc790" + permissions-policy: interest-cohort=() + server: Mastodon + strict-transport-security: max-age=63072000; includeSubDomains + vary: + - Accept-Encoding + - Origin + x-content-type-options: nosniff + x-frame-options: DENY + x-ratelimit-limit: '300' + x-ratelimit-remaining: '296' + x-ratelimit-reset: '2022-11-15T21:00:00.373002Z' + x-request-id: 554397da-9378-42a2-b292-f86ca95778b7 + x-runtime: '0.046660' + x-xss-protection: '0' + body: + encoding: '' + file: no + string: '{"id":"109349140059981889","created_at":"2022-11-15T18:04:22.342Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"https://emacs.ch/users/chainsawriot/statuses/109349140059981889","url":"https://emacs.ch/@chainsawriot/109349140059981889","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003etesting + in progress, please ignore\u003c/p\u003e","filtered":[],"reblog":null,"application":{"name":"rtoot + package","website":null},"account":{"id":"109337011845249544","username":"chainsawriot","acct":"chainsawriot","display_name":"chainsawriot","locked":false,"bot":false,"discoverable":false,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"","url":"https://emacs.ch/@chainsawriot","avatar":"https://emacs.ch/system/accounts/avatars/109/337/011/845/249/544/original/00fc3aabc87d3564.jpg","avatar_static":"https://emacs.ch/system/accounts/avatars/109/337/011/845/249/544/original/00fc3aabc87d3564.jpg","header":"https://emacs.ch/headers/original/missing.png","header_static":"https://emacs.ch/headers/original/missing.png","followers_count":126,"following_count":63,"statuses_count":28,"last_status_at":"2022-11-15","noindex":true,"emojis":[{"shortcode":"emacs","url":"https://emacs.ch/system/custom_emojis/images/000/000/358/original/9f320443168e793f.png","static_url":"https://emacs.ch/system/custom_emojis/images/000/000/358/static/9f320443168e793f.png","visible_in_picker":true}],"fields":[{"name":"Stack","value":":emacs:, + R, stumpwm, linux, firefox","verified_at":null},{"name":"Research Interests","value":"Keine + Ahnung","verified_at":null},{"name":"Web","value":"\u003ca href=\"https://chainsawriot.com/about/\" + target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan + class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003echainsawriot.com/about/\u003c/span\u003e\u003cspan + class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e","verified_at":"2022-11-14T12:22:07.327+00:00"}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}' + recorded_at: 2022-11-15 18:04:22 GMT + recorded_with: vcr/1.1.0, webmockr/0.8.2 diff --git a/tests/fixtures/post_toot_verbose.yml b/tests/fixtures/post_toot_verbose.yml new file mode 100644 index 0000000..a2aa16b --- /dev/null +++ b/tests/fixtures/post_toot_verbose.yml @@ -0,0 +1,56 @@ +http_interactions: +- request: + method: post + uri: https://emacs.ch/api/v1/statuses + body: + encoding: '' + string: status=testing in progress, please ignore,sensitive=false,visibility=public + headers: + Accept: application/json, text/xml, application/xml, */* + Authorization: Bearer <<>> + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + cache-control: no-store + content-encoding: gzip + content-security-policy: 'base-uri ''none''; default-src ''none''; frame-ancestors + ''none''; font-src ''self'' https://emacs.ch; img-src ''self'' https: data: + blob: https://emacs.ch; style-src ''self'' https://emacs.ch ''nonce-WhkAK1UcAYaMaoCdwdqlsg==''; + media-src ''self'' https: data: https://emacs.ch; frame-src ''self'' https:; + manifest-src ''self'' https://emacs.ch; connect-src ''self'' data: blob: https://emacs.ch + https://emacs.ch wss://emacs.ch; script-src ''self'' https://emacs.ch ''wasm-unsafe-eval''; + child-src ''self'' blob: https://emacs.ch; worker-src ''self'' blob: https://emacs.ch' + content-type: application/json; charset=utf-8 + date: Tue, 15 Nov 2022 18:04:22 GMT + etag: W/"4819c29985fd22b96038a0483f5c7993" + permissions-policy: interest-cohort=() + server: Mastodon + strict-transport-security: max-age=63072000; includeSubDomains + vary: + - Accept-Encoding + - Origin + x-content-type-options: nosniff + x-frame-options: DENY + x-ratelimit-limit: '300' + x-ratelimit-remaining: '297' + x-ratelimit-reset: '2022-11-15T21:00:00.260950Z' + x-request-id: d6d3fe2b-57e2-47a0-99ca-01a96daa343c + x-runtime: '0.048207' + x-xss-protection: '0' + body: + encoding: '' + file: no + string: '{"id":"109349140052391379","created_at":"2022-11-15T18:04:22.230Z","in_reply_to_id":null,"in_reply_to_account_id":null,"sensitive":false,"spoiler_text":"","visibility":"public","language":"en","uri":"https://emacs.ch/users/chainsawriot/statuses/109349140052391379","url":"https://emacs.ch/@chainsawriot/109349140052391379","replies_count":0,"reblogs_count":0,"favourites_count":0,"edited_at":null,"favourited":false,"reblogged":false,"muted":false,"bookmarked":false,"pinned":false,"content":"\u003cp\u003etesting + in progress, please ignore\u003c/p\u003e","filtered":[],"reblog":null,"application":{"name":"rtoot + package","website":null},"account":{"id":"109337011845249544","username":"chainsawriot","acct":"chainsawriot","display_name":"chainsawriot","locked":false,"bot":false,"discoverable":false,"group":false,"created_at":"2022-11-13T00:00:00.000Z","note":"","url":"https://emacs.ch/@chainsawriot","avatar":"https://emacs.ch/system/accounts/avatars/109/337/011/845/249/544/original/00fc3aabc87d3564.jpg","avatar_static":"https://emacs.ch/system/accounts/avatars/109/337/011/845/249/544/original/00fc3aabc87d3564.jpg","header":"https://emacs.ch/headers/original/missing.png","header_static":"https://emacs.ch/headers/original/missing.png","followers_count":126,"following_count":63,"statuses_count":27,"last_status_at":"2022-11-15","noindex":true,"emojis":[{"shortcode":"emacs","url":"https://emacs.ch/system/custom_emojis/images/000/000/358/original/9f320443168e793f.png","static_url":"https://emacs.ch/system/custom_emojis/images/000/000/358/static/9f320443168e793f.png","visible_in_picker":true}],"fields":[{"name":"Stack","value":":emacs:, + R, stumpwm, linux, firefox","verified_at":null},{"name":"Research Interests","value":"Keine + Ahnung","verified_at":null},{"name":"Web","value":"\u003ca href=\"https://chainsawriot.com/about/\" + target=\"_blank\" rel=\"nofollow noopener noreferrer me\"\u003e\u003cspan + class=\"invisible\"\u003ehttps://\u003c/span\u003e\u003cspan class=\"\"\u003echainsawriot.com/about/\u003c/span\u003e\u003cspan + class=\"invisible\"\u003e\u003c/span\u003e\u003c/a\u003e","verified_at":"2022-11-14T12:22:07.327+00:00"}]},"media_attachments":[],"mentions":[],"tags":[],"emojis":[],"card":null,"poll":null}' + recorded_at: 2022-11-15 18:04:22 GMT + recorded_with: vcr/1.1.0, webmockr/0.8.2 diff --git a/tests/fixtures/post_user_pin_silent.yml b/tests/fixtures/post_user_pin_silent.yml new file mode 100644 index 0000000..6928332 --- /dev/null +++ b/tests/fixtures/post_user_pin_silent.yml @@ -0,0 +1,49 @@ +http_interactions: +- request: + method: post + uri: https://emacs.ch/api/v1/accounts/109337044410360200/pin + body: + encoding: '' + string: '' + headers: + Accept: application/json, text/xml, application/xml, */* + Authorization: Bearer <<>> + response: + status: + status_code: 200 + category: Success + reason: OK + message: 'Success: (200) OK' + headers: + cache-control: no-store + content-encoding: gzip + content-security-policy: 'base-uri ''none''; default-src ''none''; frame-ancestors + ''none''; font-src ''self'' https://emacs.ch; img-src ''self'' https: data: + blob: https://emacs.ch; style-src ''self'' https://emacs.ch ''nonce-s5sxVSnJXDMNUPSFF0xx6g==''; + media-src ''self'' https: data: https://emacs.ch; frame-src ''self'' https:; + manifest-src ''self'' https://emacs.ch; connect-src ''self'' data: blob: https://emacs.ch + https://emacs.ch wss://emacs.ch; script-src ''self'' https://emacs.ch ''wasm-unsafe-eval''; + child-src ''self'' blob: https://emacs.ch; worker-src ''self'' blob: https://emacs.ch' + content-type: application/json; charset=utf-8 + date: Tue, 15 Nov 2022 18:12:24 GMT + etag: W/"71fc28ed1faf9b0390808ead5c4527f1" + permissions-policy: interest-cohort=() + server: Mastodon + strict-transport-security: max-age=63072000; includeSubDomains + vary: + - Accept-Encoding + - Origin + x-content-type-options: nosniff + x-frame-options: DENY + x-ratelimit-limit: '300' + x-ratelimit-remaining: '276' + x-ratelimit-reset: '2022-11-15T18:15:00.511173Z' + x-request-id: 441d3e11-2a78-44f3-91e8-76de6e743a72 + x-runtime: '0.033891' + x-xss-protection: '0' + body: + encoding: '' + file: no + string: '{"id":"109337044410360200","following":true,"showing_reblogs":true,"notifying":false,"languages":null,"followed_by":true,"blocking":false,"blocked_by":false,"muting":false,"muting_notifications":false,"requested":false,"domain_blocking":false,"endorsed":true,"note":""}' + recorded_at: 2022-11-15 18:12:24 GMT + recorded_with: vcr/1.1.0, webmockr/0.8.2 diff --git a/tests/testthat/test-auth_verify.R b/tests/testthat/test-auth_verify.R index f0c14df..a29978b 100644 --- a/tests/testthat/test-auth_verify.R +++ b/tests/testthat/test-auth_verify.R @@ -2,11 +2,19 @@ original_envvar <- Sys.getenv("RTOOT_DEFAULT_TOKEN") Sys.setenv(RTOOT_DEFAULT_TOKEN = "abc;user;emacs.ch") test_that("verify_envvar (Good case)", { + ## The cassette was created with a valid envvar vcr::use_cassette("envvar", { expect_error(capture_message(verify_envvar()), NA) }) }) +test_that("verify_envvar (Good case), silent", { + ## The cassette was created with a valid envvar + vcr::use_cassette("envvar_silent", { + expect_silent(verify_envvar(verbose = FALSE)) + }) +}) + test_that("verify_envvar (Bad case)", { Sys.setenv(RTOOT_DEFAULT_TOKEN = "") expect_error(verify_envvar()) diff --git a/tests/testthat/test-post.R b/tests/testthat/test-post.R index a9e398f..8d150c5 100644 --- a/tests/testthat/test-post.R +++ b/tests/testthat/test-post.R @@ -15,27 +15,27 @@ test_that("post_toot, defensive", { test_that("post_toot, real", { vcr::use_cassette("post_toot_default", { - expect_error(x <- post_toot(status = "testing in progress, please ignore", token = fake_token), NA) + expect_error(x <- post_toot(status = "testing in progress, please ignore", token = fake_token, verbose = FALSE), NA) }) vcr::use_cassette("post_toot_media", { expect_error(x <- post_toot(status = "testing in progress, please ignore", media = "../testdata/logo.png", alt_text = "rtoot logo", - token = fake_token), NA) + token = fake_token, verbose = FALSE), NA) }) vcr::use_cassette("post_toot_spoiler_text", { expect_error(x <- post_toot(status = "testing in progress, please ignore", media = "../testdata/logo.png", alt_text = "rtoot logo", - spoiler_text = "rtoot is the best", token = fake_token), NA) + spoiler_text = "rtoot is the best", token = fake_token, verbose = FALSE), NA) }) vcr::use_cassette("post_toot_sensitive", { expect_error(x <- post_toot(status = "testing in progress, please ignore", media = "../testdata/logo.png", alt_text = "rtoot logo", - spoiler_text = "rtoot is the best", sensitive = TRUE, token = fake_token), NA) + spoiler_text = "rtoot is the best", sensitive = TRUE, token = fake_token, verbose = FALSE), NA) }) vcr::use_cassette("post_toot_visibility", { expect_error(x <- post_toot(status = "testing in progress, please ignore", media = "../testdata/logo.png", alt_text = "rtoot logo", - spoiler_text = "rtoot is the best", visibility = "unlisted", token = fake_token), NA) + spoiler_text = "rtoot is the best", visibility = "unlisted", token = fake_token, verbose = FALSE), NA) }) vcr::use_cassette("post_toot_language", { expect_error(x <- post_toot(status = "jetzt testen", media = "../testdata/logo.png", alt_text = "rtoot logo", - language = "de", visibility = "unlisted", token = fake_token), NA) + language = "de", visibility = "unlisted", token = fake_token, verbose = FALSE), NA) }) }) @@ -44,6 +44,26 @@ test_that("post_user", { expect_error(post_user("5358", action = "promotehimtoprofessor", token = fake_token)) vcr::use_cassette("post_user_pin", { ## Thanks Tim, you are the best! - expect_error(post_user("5358", action = "pin", token = fake_token), NA) + expect_error(post_user("5358", action = "pin", token = fake_token, verbose = FALSE), NA) + }) +}) + +fake_token2 <- rtoot:::get_token_from_envvar("RTOOT_DEFAULT_TOKEN", check_stop = FALSE) +fake_token2$type <- "user" +fake_token2$instance <- "emacs.ch" + +test_that("post_toot, verbose", { + vcr::use_cassette("post_toot_verbose", { + expect_message(x <- post_toot(status = "testing in progress, please ignore", token = fake_token2, verbose = TRUE)) + }) + vcr::use_cassette("post_toot_silent", { + expect_silent(x <- post_toot(status = "testing in progress, please ignore", token = fake_token2, verbose = FALSE)) + }) +}) + +test_that("post_user silent", { + vcr::use_cassette("post_user_pin_silent", { + ## Thanks Tim, you are still the best! + expect_silent(post_user("109337044410360200", action = "pin", token = fake_token2, verbose = FALSE)) }) })