Skip to content

Commit

Permalink
bugfix for datacenter URL checking (#270)
Browse files Browse the repository at this point in the history
* bugfix for datacenter URL checking

* Tests for removing base_url trailing slash
  • Loading branch information
jmobrien authored Jun 29, 2022
1 parent 5f57391 commit 71bea2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
2 changes: 1 addition & 1 deletion R/checks.R
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ checkarg_base_url <- function(base_url){
}
# Remove trailing '/' if present (silently), and check for qualtrics.com ending:
if(endsWith(base_url, "qualtrics.com/")){
base_url <- stringr::str_remove(base_url, "/$", "")
base_url <- stringr::str_remove(base_url, "/$")
} else if (!endsWith(base_url, ".qualtrics.com")){
rlang::abort(
c("Error in argument `base_url`",
Expand Down
19 changes: 16 additions & 3 deletions tests/testthat/test-api-credentials.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,29 @@ test_that("can store and access credentials", {
"`base_url` must be of the form"
)

qualtrics_api_credentials(api_key = "1234", base_url = "https://abcd.qualtrics.com")
# Removes protocol with message
expect_message(
qualtrics_api_credentials(api_key = "1234",
base_url = "https://abcd.qualtrics.com"),
"Protocol"
)
expect_false(
startsWith(Sys.getenv("QUALTRICS_BASE_URL" ), "https://")
)

# Removes the trailing slash:
qualtrics_api_credentials(api_key = "1234", base_url = "abcd.qualtrics.com/")
# Now expect this to no longer have slash
expect_false(
endsWith(Sys.getenv("QUALTRICS_BASE_URL" ), "/")
)

# Checks pass with correct credentials:
qualtrics_api_credentials(api_key = "1234", base_url = "abcd.qualtrics.com")
# Now expect this to be true
# Now expect this to be NULL
expect_null(
check_credentials()
)
)
})

test_that("qualtRicsConfigFile() gives a warning", {
Expand Down

0 comments on commit 71bea2a

Please sign in to comment.