diff --git a/R/automation.R b/R/automation.R index 5d7aeee46..27d498e95 100644 --- a/R/automation.R +++ b/R/automation.R @@ -206,10 +206,13 @@ 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") + ) ) } @@ -217,7 +220,7 @@ setMethod("sendCrunchAutomationScript", "ProjectFolder", function(x, 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( diff --git a/tests/testthat/app.crunch.io/api/account.json b/tests/testthat/app.crunch.io/api/account.json new file mode 100644 index 000000000..7b00c1073 --- /dev/null +++ b/tests/testthat/app.crunch.io/api/account.json @@ -0,0 +1,6 @@ +{ + "element": "shoji:entity", + "views": { + "execute": "https://app.crunch.io/api/account/execute/" + } +} diff --git a/tests/testthat/test-automation.R b/tests/testthat/test-automation.R index 50b1346e9..078c62c08 100644 --- a/tests/testthat/test-automation.R +++ b/tests/testthat/test-automation.R @@ -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 ) })