Skip to content

Commit

Permalink
Ensure that check_workspace_param() uses arg val rather than env val
Browse files Browse the repository at this point in the history
Closes #54

- Has function budy use args rather than env values
- Add tests for `check_workspace_param()`
	- Function uses vals in args
	- Function returns TRUE when right creds provided
  • Loading branch information
arthur-shaw committed Oct 12, 2024
1 parent 8bb0dcd commit d58bb34
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ check_workspace_param <- function(
# workspace does not exist
workspace_user <- suppressMessages(
susoapi::get_user_details(
user_id = Sys.getenv("SUSO_USER"),
user_id = user,
server = server,
workspace = workspace,
user = user,
Expand All @@ -190,7 +190,7 @@ check_workspace_param <- function(
assertthat::assert_that(
!is.null(workspace_user),
msg = glue::glue(
'User `{Sys.getenv("SUSO_USER")}` does not have access to workspace `{workspace}`.'
'User `{user}` does not have access to workspace `{workspace}`.'
)
)

Expand Down
35 changes: 35 additions & 0 deletions tests/testthat/test-check_workspace_param.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# uses credentials in args rather than in environment
testthat::test_that("Credentials in args rather than those in env", {

# set SuSo environment vars as empty, emulatinng situation where
# - no `.Renviron` file exists and/or
# - credentials not set
withr::local_envvar(
.new = list(
"SUSO_SERVER" = "",
"SUSO_WORKSPACE" = "",
"SUSO_USER" = "",
"SUSO_PASSWORD" = ""
)
)

testthat::expect_error(
check_workspace_param(
server = "https://demo.mysurvey.solutions",
workspace = "fakespace",
user = "FakeX1",
password = "Fake123456"
),
'User `FakeX1` does not have access to workspace `fakespace`.'
)

})

# returns TRUE when correct credentials provided
testthat::test_that("Returns `TRUE` when correct credentials provided", {

testthat::expect_true(
check_workspace_param()
)

})

0 comments on commit d58bb34

Please sign in to comment.