Skip to content

Commit

Permalink
[184790111]: Redirect root project folder Crunch Automation
Browse files Browse the repository at this point in the history
scripts to account
  • Loading branch information
sluga committed Apr 17, 2023
1 parent 07f3990 commit 8ea945a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
11 changes: 7 additions & 4 deletions R/automation.R
Original file line number Diff line number Diff line change
Expand Up @@ -206,18 +206,21 @@ setMethod("sendCrunchAutomationScript", "ProjectFolder", function(x,
# which gives us the URL to hit;
# but the account ('top-level folder', what you get from: `projects()`)
# is also of class ProjectFolder, but doesn't include this info;
# running CA scripts on the account is not supported currently
# previously, we function raised an error in this case;
# now, following what frontend did, we execute the script on the account
if (!is.crunchURL(x@views$execute)) {
halt(
"This folder does not support Crunch Automation scripts at this time."
x <- ShojiObject(
crGET(
shojiURL(getAPIRoot(), "views", "account")
)
)
}

dots <- list(...)
if (length(dots) > 0) {
# could have been a warning, but went with error in case a user
# would try running a destructive operation with dry_run = TRUE
stop("extra arguments (...) are not supported when x is a ProjectFolder")
halt("extra arguments (...) are not supported when x is a ProjectFolder")
}

crPOST(
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/app.crunch.io/api/account.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"element": "shoji:entity",
"views": {
"execute": "https://app.crunch.io/api/account/execute/"
}
}
19 changes: 12 additions & 7 deletions tests/testthat/test-automation.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,19 @@ with_mock_crunch({
)
})

test_that("folder-level operation fails on root", {
test_that("folder-level operation works on root/account", {

root_project_folder <- projects()
script <- "CREATE FOLDER 'My not-to-be folder';"

expect_error(
runCrunchAutomation(root_project_folder, script),
"not support Crunch Automation scripts"
project_folder <- projects()
script <- "CREATE FOLDER 'My to-be folder';"
expected_url <- "https://app.crunch.io/api/account/execute/"
expected_body <- paste0(
'{"element":"shoji:view",',
paste0('"value":', '"', script, '"'), '}'
)
expect_POST(
runCrunchAutomation(project_folder, script),
expected_url, expected_body,
fixed = TRUE
)
})

Expand Down

0 comments on commit 8ea945a

Please sign in to comment.