Skip to content

Commit

Permalink
Improve Entity Management functions error handling for missing did an…
Browse files Browse the repository at this point in the history
…d eid

* Make the default an empty string, ""
* This default will cause an error with yell_if_missing
* Update docs
  • Loading branch information
florianm committed Apr 1, 2024
1 parent a6b954d commit 7a113cb
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 37 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: ruODK
Title: An R Client for the ODK Central API
Version: 1.4.9.9006
Version: 1.4.9.9007
Authors@R:
c(person(given = c("Florian", "W."),
family = "Mayer",
Expand Down
4 changes: 2 additions & 2 deletions R/entity_detail.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
#' ev <- en$current_version_version[1]
#' }
entity_detail <- function(pid = get_default_pid(),
did = NULL,
eid = NULL,
did = "",
eid = "",
url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
Expand Down
2 changes: 1 addition & 1 deletion R/entity_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
#' ev <- en$current_version_version[1]
#' }
entity_list <- function(pid = get_default_pid(),
did = NULL,
did = "",
deleted = FALSE,
url = get_default_url(),
un = get_default_un(),
Expand Down
2 changes: 1 addition & 1 deletion R/entitylist_detail.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
#' tibble::as_tibble()
#' }
entitylist_detail <- function(pid = get_default_pid(),
did = NULL,
did = "",
url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
Expand Down
2 changes: 1 addition & 1 deletion R/entitylist_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
#' )
#' }
entitylist_download <- function(pid = get_default_pid(),
did = NULL,
did = "",
url = get_default_url(),
un = get_default_un(),
pw = get_default_pw(),
Expand Down
5 changes: 3 additions & 2 deletions R/entitylist_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
#' ds3$approvalRequired # FALSE
#' }
entitylist_update <- function(pid = get_default_pid(),
did = NULL,
did = "",
approval_required = FALSE,
url = get_default_url(),
un = get_default_un(),
Expand Down Expand Up @@ -97,7 +97,8 @@ entitylist_update <- function(pid = get_default_pid(),
times = retries
) |>
yell_if_error(url, un, pw) |>
httr::content(encoding = "utf-8")
httr::content(encoding = "utf-8") |>
janitor::clean_names()
}

# usethis::use_test("entitylist_update") # nolint
2 changes: 2 additions & 0 deletions man-roxygen/param-did.R
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
#' @param did (chr) The name of the Entity List, internally called Dataset.
#' The function will error if this parameter is not given.
#' Default: "".
2 changes: 2 additions & 0 deletions man-roxygen/param-eid.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
#' @param eid (chr) The UUID of an Entity, which can be retrieved by
#' `entity_list()`.
#' The function will error if this parameter is not given.
#' Default: "".
12 changes: 8 additions & 4 deletions man/entity_detail.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/entity_list.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/entitylist_detail.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/entitylist_download.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions man/entitylist_update.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 16 additions & 9 deletions tests/testthat/test-entity_detail.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ test_that("entity_detail works", {
testthat::expect_is(ev, "integer")
})

test_that("entitylist_detail errors if did is missing", {
test_that("entity_detail errors if did is missing", {
testthat::expect_error(
entitylist_detail()
entity_detail()
)
})

test_that("entitylist_detail warns if odkc_version too low", {
test_that("entity_detail warns if odkc_version too low", {
skip_if(Sys.getenv("ODKC_TEST_URL") == "",
message = "Test server not configured"
)
Expand All @@ -66,15 +66,22 @@ test_that("entitylist_detail warns if odkc_version too low", {
odkc_version = get_test_odkc_version()
)

ds <- entitylist_list()
did <- ds$name[1]
el <- entitylist_list()

# Entity List name (dataset ID)
did <- el$name[1]

# All Entities of Entity List
en <- entity_list(did = el$name[1])

ds1 <- entitylist_detail(did = did)
# Entity detail
ed <- entity_detail(did = el$name[1], eid = en$uuid[1])

testthat::expect_warning(
ds1 <- entitylist_detail(did = did, odkc_version = "1.5.3")
# Expect error with missing eid
testthat::expect_error(
entity_detail(did = el$name[1])
)
})


# usethis::use_e("entity_detail") # nolint
# usethis::use_r("entity_detail") # nolint
16 changes: 8 additions & 8 deletions tests/testthat/test-entitylist_update.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ test_that("entitylist_update works", {

did <- ds$name[1]

# Update dataset with opposite approvalRequired
ds2 <- entitylist_update(did = did, approval_required = !ds1$approvalRequired)
testthat::expect_false(ds1$approvalRequired == ds2$approvalRequired)

# Update dataset with opposite approvalRequired again
ds3 <- entitylist_update(did = did, approval_required = !ds2$approvalRequired)
testthat::expect_false(ds2$approvalRequired == ds3$approvalRequired)
testthat::expect_true(ds1$approvalRequired == ds3$approvalRequired)
# Update dataset with opposite approval_required
ds2 <- entitylist_update(did = did, approval_required = !ds1$approval_required)
testthat::expect_false(ds1$approval_required == ds2$approval_required)

# Update dataset with opposite approval_required again
ds3 <- entitylist_update(did = did, approval_required = !ds2$approval_required)
testthat::expect_false(ds2$approval_required == ds3$approval_required)
testthat::expect_true(ds1$approval_required == ds3$approval_required)
})

test_that("entitylist_update errors if did is missing", {
Expand Down

0 comments on commit 7a113cb

Please sign in to comment.