Skip to content

Commit

Permalink
close #8 by customizing when to capitalize or lower case bcdata_recor…
Browse files Browse the repository at this point in the history
…d_id s
  • Loading branch information
NewGraphEnvironment committed Oct 20, 2024
1 parent 36e1d61 commit 6b3f3d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
12 changes: 10 additions & 2 deletions R/rfp_bcd_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#' @importFrom glue glue
#' @importFrom chk chk_string chk_character
#' @importFrom rlang sym
#' @importFrom stringr str_to_upper str_to_lower
#' @family source bcdata
#' @examples
#' \dontrun{
Expand Down Expand Up @@ -61,9 +62,16 @@ rfp_bcd_get_data <- function(
cli::cli_abort(message = "col_filter_value cannot be NULL when col_filter is provided.")
}

# convert column names and bc_record_id to uppercase
bcdata_record_id <- stringr::str_to_upper(bcdata_record_id)
# Check if there is a period in the input string to deal with capitilization issues
if (grepl("\\.", bcdata_record_id)) {
# Convert to uppercase if there is a period
bcdata_record_id <- stringr::str_to_upper(bcdata_record_id)
} else {
# Convert to lowercase if there is no period
bcdata_record_id <- stringr::str_to_lower(bcdata_record_id)
}

# convert column names to uppercase
if(!is.null(col_filter)){
col_filter <- stringr::str_to_upper(col_filter)
}
Expand Down
16 changes: 16 additions & 0 deletions tests/testthat/test-rfp_bcd_get_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ test_that("returns result when col_filter and col_filter_value provided", {
"data.frame")
})


test_that("can provide lower case schema.table", {
expect_s3_class(
rfp_bcd_get_data(bcdata_record_id = "whse_imagery_and_base_maps.gsr_airports_svw", col_filter = 'AIRPORT_NAME',
col_filter_value = "Duncan Airport"),
"data.frame")
})

test_that("can provide upper case schema.table", {
expect_s3_class(
rfp_bcd_get_data(bcdata_record_id = "WHSE_IMAGERY_AND_BASE_MAPS.GSR_AIRPORTS_SVW", col_filter = 'AIRPORT_NAME',
col_filter_value = "Duncan Airport"),
"data.frame")
})


test_that("returns error when col_filter_value provided not present", {
expect_error(
rfp_bcd_get_data(bcdata_record_id = "bc-airports", col_filter = 'AIRPORT_NAME',
Expand Down

0 comments on commit 6b3f3d4

Please sign in to comment.