Skip to content

Commit

Permalink
Add tests for #149
Browse files Browse the repository at this point in the history
By first making it testable and slightly more robust
  • Loading branch information
chainsawriot committed Dec 30, 2023
1 parent ef54b1a commit 7b4be4d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* added progress bar for long running queries (#141) by @chainsawriot
* added 429 check (#144)
* fixed #146 by adding a confirmation step for `auth_setup(browser = FALSE)`(#147)
* fixed #149 by removing quotes around the inputted instance name though `auth_setup(instance = "")` (#150) by @thisisnic

# rtoot 0.3.3

Expand Down
4 changes: 1 addition & 3 deletions R/auth.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ auth_setup <- function(instance = NULL, type = NULL, name = NULL, path = NULL, c
while (is.null(instance) || instance == "") {
instance <- rtoot_ask(prompt = "On which instance do you want to authenticate (e.g., \"mastodon.social\")? ", pass = FALSE)
}
if(quoted_string(instance)){
instance <- substr(instance, 2, nchar(instance)-1)
}
instance <- process_instance(instance) #149
client <- get_client(instance = instance)
if (!isTRUE(type %in% c("public", "user"))) {
type <- c("public", "user")[rtoot_menu(choices = c("public", "user"), title = "What type of token do you want?", verbose = TRUE)]
Expand Down
11 changes: 9 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ break_process_request <- function(api_response, retryonratelimit = FALSE, verbos
}

## a function to determine if input to readline has been quoted or not
quoted_string <- function(x){
(grepl("^\"", x) && grepl("\"$", x)) || (grepl("^'", x) && grepl("'$", x))
is_quoted_string <- function(x) {
grepl("^[\"'].+[\"']$", x)
}

process_instance <- function(x) {
if (!is_quoted_string(x)) {
return(x)
}
gsub("^['\"]+|['\"]+$", "", x)
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ You can post toots with:
post_toot(status = "my first rtoot #rstats")
```

It can also include media and alt_text.
It can also include media and alt\_text.

``` r
post_toot(
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-auth_create_token.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ test_that("defensive", {
expect_error(create_token(iris), "client is not an object of type rtoot_client")
expect_error(create_token(fake_client, type = "elon"), "should be one of")
})

test_that("test for #149", {
expect_equal(process_instance("\"fosstodon.org\""), "fosstodon.org")
expect_equal(process_instance("\'fosstodon.org\'"), "fosstodon.org")
expect_equal(process_instance("\'\'fosstodon.org\'\'"), "fosstodon.org")
expect_equal(process_instance("fosstodon.org"), "fosstodon.org")
expect_equal(process_instance("fosst\"odon.org"), "fosst\"odon.org")
})

0 comments on commit 7b4be4d

Please sign in to comment.