Skip to content

Commit

Permalink
Update getMetadataEndpoint.R (#114)
Browse files Browse the repository at this point in the history
* Update getMetadataEndpoint.R

- added removal of nas to return NA value instead of erroring out

* linting

-fix linting

* Update getAnalytics.Rd

* add unit test

add unit test pointed at play for NA handling

---------

Co-authored-by: sam-bao <[email protected]>
  • Loading branch information
flopez-bao and sam-bao authored May 15, 2023
1 parent 656294c commit 55f17e9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/getMetadataEndpoint.R
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ duplicateResponse <- function(resp, expand, by) {
unique_values <- unique(values)

#break up url to multiple calls if needed
if (sum(nchar(unique_values)) > 2000) {
if (sum(nchar(unique_values), na.rm = TRUE) > 2000) {

values_list <- .splitUrlComponent(unique_values, 2000)

Expand Down
2 changes: 1 addition & 1 deletion man/getAnalytics.Rd

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"categoryOptions": [
{
"name": "10-14",
"id": "jcGQdcpPSJP"
},
{
"name": "35-39",
"id": "R32YPF38CJJ"
}
]
}
8 changes: 8 additions & 0 deletions tests/testthat/test-getMetadataEndpoint.r
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,11 @@ test_that(
testthat::expect_s3_class(resp, "data.frame")
rm(resp)
})

# test NAs are handled properly
httptest::with_mock_api({
# na value is passed to the api to test handling
age_option_uid <- c(NA, "R32YPF38CJJ", "jcGQdcpPSJP")
res <- datimutils::getCatOptions(age_option_uid, d2_session = play2372)
testthat::expect_identical(res, c(NA, "35-39", "10-14"))
})

0 comments on commit 55f17e9

Please sign in to comment.