diff --git a/tests/testthat/test-get_dataset.R b/tests/testthat/test-get_dataset.R index 4bf1139..d9af688 100644 --- a/tests/testthat/test-get_dataset.R +++ b/tests/testthat/test-get_dataset.R @@ -50,3 +50,22 @@ test_that("get_dataset filters error properly", { regexp = "API error" ) }) + +test_that("get_dataset works with multiple filters", { + n_resources <- 3 + columns <- c("Date", "PracticeCode", "HSCP", "AllAges") + + expect_message( + data <- get_dataset("gp-practice-populations", + max_resources = n_resources, + row_filters = list(PracticeCode = c("10002", "10017")), + col_select = columns + ) + ) + + expect_s3_class(data, "tbl_df") + expect_equal(nrow(data), n_resources * 6) + expect_named(data, columns) + expect_true(all(data[["PracticeCode"]] %in% c("10002", "10017"))) +}) + diff --git a/tests/testthat/test-get_resource.R b/tests/testthat/test-get_resource.R index cb3f5bd..863ae69 100644 --- a/tests/testthat/test-get_resource.R +++ b/tests/testthat/test-get_resource.R @@ -62,3 +62,41 @@ test_that("returns data for multiple filters", { expect_length(unique(data_full$GPPractice), 2) expect_length(unique(data_full$PrescribedType), 1) }) + +test_that("returns data for multiple filters in mixed format", { + expect_message( + delays <- get_resource( + res_id = "fd354e4b-6211-48ba-8e4f-8356a5ed4215", + col_select = c("MonthOfDelay", "ReasonForDelay", "NumberOfDelayedBedDays"), + row_filters = list("HBT" = "S08000031", MonthOfDelay = c(201607:201707)) + ) + ) + + expect_s3_class(delays, "tbl_df") + expect_equal(nrow(delays), 195) + expect_named(delays, c("MonthOfDelay", "ReasonForDelay", "NumberOfDelayedBedDays")) + expect_length(unique(delays$MonthOfDelay), 13) +}) + +test_that("errors on invalid filters", { + # non-existent column in row_filters + expect_error( + delays <- get_resource( + res_id = "fd354e4b-6211-48ba-8e4f-8356a5ed4215", + col_select = c("MonthOfDelay", "ReasonForDelay", "NumberOfDelayedBedDays"), + row_filters = c("HBT" = "S08000031", "Month" = 201607) + ), + regexp = "row_filters: invalid value" + ) + + # non-existent column in col_select + expect_error( + delays <- get_resource( + res_id = "fd354e4b-6211-48ba-8e4f-8356a5ed4215", + col_select = c("Month", "ReasonForDelay", "NumberOfDelayedBedDays"), + row_filters = c("HBT" = "S08000031", "MonthOfDelay" = 201607) + ), + regexp = "col_select: invalid value" + ) + +})