Skip to content

Commit

Permalink
Add and update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Moohan committed Nov 28, 2024
1 parent ca10de5 commit aa6073b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
32 changes: 32 additions & 0 deletions tests/testthat/test-get_resource.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,35 @@ test_that("returns data with row specifications", {
expect_equal(nrow(get_resource(res_id = gp_list_apr_2021, rows = 999)), 926) %>%
expect_warning()
})

test_that("returns data for multiple filters", {
expect_message(
data_row_limit <- get_resource(
res_id = "e4985a62-9d59-4e71-8800-3f7ca29ffe0c",
col_select = c("GPPractice", "DMDCode"),
row_filters = list("GPPractice" = c("80005", "80202")),
rows = 100
)
)

expect_s3_class(data_row_limit, "tbl_df")
expect_equal(nrow(data_row_limit), 100)
expect_named(data_row_limit, c("GPPractice", "DMDCode"))

expect_message(
data_full <- get_resource(
res_id = "e4985a62-9d59-4e71-8800-3f7ca29ffe0c",
col_select = c("GPPractice", "DMDCode", "PrescribedType"),
row_filters = list(
"GPPractice" = c("80005", "80202"),
"PrescribedType" = "AMP"
)
)
)

expect_s3_class(data_full, "tbl_df")
expect_equal(nrow(data_full), 1108)
expect_named(data_full, c("GPPractice", "DMDCode", "PrescribedType"))
expect_length(unique(data_full$GPPractice), 2)
expect_length(unique(data_full$PrescribedType), 1)
})
10 changes: 6 additions & 4 deletions tests/testthat/test-parse_row_filters.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ test_that("throws error for bad types", {
)
})

test_that("throws error for length > 1", {
expect_error(
test_that("returns FALSE for length > 1", {
expect_false(
parse_row_filters(list(x = letters)),
regexp = " has too many values\\."
)
) %>%
expect_message(
"Multiple filters were supplied, defaulting to SQL"
)
})

test_that("throws error when un-named", {
Expand Down

0 comments on commit aa6073b

Please sign in to comment.