feat: all-categories mode in .build_verb_sql()
The concept boundary in this package is subtype, not category, so a total is the existing query with the category dimension collapsed and no category predicate applied. subtype is deliberately kept in the grouping: subtype=operations plus all-categories is 'operating expenditure', which is the measure a fiscal comparison wants. Named 'All Categories' rather than 'Total' because category='Total' would sit one argument from expenditure_concept='total' and mean something different.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
# Baseline at branch point: 843 PASS / 0 FAIL / 0 SKIP / 0 WARN (2026-08-05, origin/main 2fc9e75)
|
||||
|
||||
test_that(".build_verb_sql emits a literal category and no category filter in all-categories mode", {
|
||||
sql <- uscogdata:::.build_verb_sql(
|
||||
view = "spending_annotated",
|
||||
subtype_col = "spend_subtype",
|
||||
govid = "552025209777",
|
||||
years = 2019L,
|
||||
category = NULL,
|
||||
subtype_scope = c("operations", "capital"),
|
||||
all_categories = TRUE
|
||||
)
|
||||
|
||||
expect_match(sql, "'All Categories' AS category", fixed = TRUE)
|
||||
# no category filter of any kind
|
||||
expect_false(grepl("AND category IN", sql, fixed = TRUE))
|
||||
# category is not a grouping key
|
||||
expect_false(grepl("GROUP BY year, canonical_govid, gov_name, xwalk_gov_name, spend_subtype, category",
|
||||
sql, fixed = TRUE))
|
||||
# the subtype allowlist still applies -- this is what makes the sum a concept
|
||||
expect_match(sql, "AND spend_subtype IN ('operations','capital')", fixed = TRUE)
|
||||
})
|
||||
|
||||
test_that(".build_verb_sql is unchanged when all_categories is FALSE", {
|
||||
args <- list(
|
||||
view = "spending_annotated", subtype_col = "spend_subtype",
|
||||
govid = "552025209777", years = 2019L, category = NULL,
|
||||
subtype_scope = c("operations", "capital")
|
||||
)
|
||||
old <- do.call(uscogdata:::.build_verb_sql, args)
|
||||
new <- do.call(uscogdata:::.build_verb_sql, c(args, list(all_categories = FALSE)))
|
||||
expect_identical(old, new)
|
||||
expect_match(new, "GROUP BY year, canonical_govid, gov_name, xwalk_gov_name, spend_subtype, category",
|
||||
fixed = TRUE)
|
||||
})
|
||||
|
||||
test_that(".ALL_CATEGORIES is the exact reserved string", {
|
||||
expect_identical(uscogdata:::.ALL_CATEGORIES, "All Categories")
|
||||
})
|
||||
Reference in New Issue
Block a user