From d58bb3440e5859441966b545627bde4b0a439a33 Mon Sep 17 00:00:00 2001 From: Arthur Shaw Date: Fri, 11 Oct 2024 16:34:13 -0400 Subject: [PATCH] Ensure that `check_workspace_param()` uses arg val rather than env val 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 --- R/utils.R | 4 +-- tests/testthat/test-check_workspace_param.R | 35 +++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests/testthat/test-check_workspace_param.R diff --git a/R/utils.R b/R/utils.R index a036d19..d3a90a7 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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, @@ -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}`.' ) ) diff --git a/tests/testthat/test-check_workspace_param.R b/tests/testthat/test-check_workspace_param.R new file mode 100644 index 0000000..e63de4f --- /dev/null +++ b/tests/testthat/test-check_workspace_param.R @@ -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() + ) + +})