Skip to content

Commit

Permalink
Add test for joined query
Browse files Browse the repository at this point in the history
  • Loading branch information
Moohan committed Sep 26, 2024
1 parent 63c7e78 commit bf8da7b
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions tests/testthat/test-get_resource_sql.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,37 @@ test_that("throws errors on invalid sql argument", {
)
})

test_that("gets expected data", {
sql <- "
test_that("gets expected data for a simple SQL query", {
data <- get_resource_sql(
sql = "
SELECT
\"TotalCancelled\",\"TotalOperations\",\"Hospital\",\"Month\"
FROM
\"bcc860a4-49f4-4232-a76b-f559cf6eb885\"
WHERE
\"Hospital\" = 'D102H'
"
df <- get_resource_sql(sql)
)

expect_s3_class(data, "tbl")
expect_equal(unique(data$Hospital), "D102H")
expect_named(data, c("TotalCancelled", "TotalOperations", "Hospital", "Month"))
})

test_that("gets expected data for a joined SQL query", {
data <- get_resource_sql(
sql = paste(
"SELECT pops.\"Year\", pops.\"HB\", lookup.\"HBName\", pops.\"AllAges\"",
"FROM \"27a72cc8-d6d8-430c-8b4f-3109a9ceadb1\" AS pops",
"JOIN \"652ff726-e676-4a20-abda-435b98dd7bdc\" AS lookup",
"ON pops.\"HB\" = lookup.\"HB\"",
"WHERE pops.\"Sex\" = 'All' AND pops.\"Year\" > 2006"
)
)

expect_equal(unique(df$Hospital), "D102H")
expect_equal(
c("TotalCancelled", "TotalOperations", "Hospital", "Month"),
names(df)
expect_s3_class(data, "tbl")
expect_gt(min(as.integer(data$Year)), 2006L)
expect_named(data,c("Year", "HB", "HBName", "AllAges")
)
})

Expand Down

0 comments on commit bf8da7b

Please sign in to comment.