Skip to content

Commit

Permalink
Merge pull request #310 from mrc-ide/mrc-2727
Browse files Browse the repository at this point in the history
Update programme test data to include vls indicators
  • Loading branch information
EmmaLRussell committed Nov 10, 2021
2 parents bffa1a2 + 7b513f7 commit bc8ea2c
Show file tree
Hide file tree
Showing 10 changed files with 1,087 additions and 519 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Expand Up @@ -22,7 +22,7 @@ Imports:
ids,
jsonlite (>= 1.2.2),
lgr,
naomi (>= 2.5.7),
naomi (>= 2.5.8),
porcelain (>= 0.1.6),
R6,
redux,
Expand Down
6 changes: 5 additions & 1 deletion R/metadata.R
Expand Up @@ -32,7 +32,11 @@ build_indicator_metadata <- function(metadata) {
colour = scalar(metadata$colour),
invert_scale = scalar(metadata$invert_scale),
scale = scalar(metadata$scale),
accuracy = scalar(metadata$accuracy),
accuracy = if (is.na(metadata$accuracy)) {
json_null()
} else {
scalar(metadata$accuracy)
},
format = scalar(metadata$format)
)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/integration-server.R
Expand Up @@ -88,7 +88,7 @@ test_that("validate programme", {
c("age", "calendar_quarter", "indicators"))
expect_length(response$data$filters$age, 2)
expect_length(response$data$filters$calendar_quarter, 8)
expect_length(response$data$filters$indicators, 1)
expect_length(response$data$filters$indicators, 4)
})

test_that("validate ANC", {
Expand Down
30 changes: 29 additions & 1 deletion tests/testthat/test-endpoints-validate-survey-and-programme.R
Expand Up @@ -113,10 +113,19 @@ test_that("possible filters are returned for data", {
expect_equal(response$filters$calendar_quarter[[1]]$id, scalar("CY2018Q4"))
expect_equal(response$filters$calendar_quarter[[1]]$label, scalar("December 2018"))

expect_length(response$filters$indicators, 1)
expect_length(response$filters$indicators, 4)
expect_equal(response$filters$indicators[[1]]$id, scalar("art_current"))
expect_equal(response$filters$indicators[[1]]$label,
scalar("ART number (attending)"))
expect_equal(response$filters$indicators[[2]]$id, scalar("art_new"))
expect_equal(response$filters$indicators[[2]]$label,
scalar("ART new"))
expect_equal(response$filters$indicators[[3]]$id, scalar("vls_tested"))
expect_equal(response$filters$indicators[[3]]$label,
scalar("VLS tested"))
expect_equal(response$filters$indicators[[4]]$id, scalar("vls_suppressed"))
expect_equal(response$filters$indicators[[4]]$label,
scalar("VLS tests suppressed"))


input <- validate_programme_survey_input(
Expand Down Expand Up @@ -176,3 +185,22 @@ test_that("possible filters are returned for data", {
expect_equal(response$filters$indicators[[4]]$label,
scalar("Viral load suppression"))
})

test_that("filters not returned if indicator missing from input data", {
input <- validate_programme_survey_input(
file.path("testdata", "programme_no_vls.csv"),
"programme",
file.path("testdata", "malawi.geojson"))
response <- validate_survey_programme(input)

expect_equal(names(response$filters),
c("age", "calendar_quarter", "indicators"))

expect_length(response$filters$indicators, 2)
expect_equal(response$filters$indicators[[1]]$id, scalar("art_current"))
expect_equal(response$filters$indicators[[1]]$label,
scalar("ART number (attending)"))
expect_equal(response$filters$indicators[[2]]$id, scalar("art_new"))
expect_equal(response$filters$indicators[[2]]$label,
scalar("ART new"))
})
8 changes: 7 additions & 1 deletion tests/testthat/test-filters.R
Expand Up @@ -211,9 +211,15 @@ test_that("can get indicator filters for programme data", {
programme <- read_csv(programme_path, header = TRUE)
filters <- get_indicator_filters(programme, "programme")

expect_length(filters, 1)
expect_length(filters, 4)
expect_equal(filters[[1]]$id, scalar("art_current"))
expect_equal(filters[[1]]$label, scalar("ART number (attending)"))
expect_equal(filters[[2]]$id, scalar("art_new"))
expect_equal(filters[[2]]$label, scalar("ART new"))
expect_equal(filters[[3]]$id, scalar("vls_tested"))
expect_equal(filters[[3]]$label, scalar("VLS tested"))
expect_equal(filters[[4]]$id, scalar("vls_suppressed"))
expect_equal(filters[[4]]$label, scalar("VLS tests suppressed"))
})

test_that("can get indicator filters for anc data", {
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-metadata.R
Expand Up @@ -17,6 +17,17 @@ test_that("can build metadata response", {
scalar("ANC HIV prevalence"))
expect_equal(metadata$anc$choropleth$indicators[[2]]$name,
scalar("ANC prior ART coverage"))
expect_length(metadata$programme$choropleth$indicators, 4)
programme_indicators <- metadata$programme$choropleth$indicators
expect_equal(programme_indicators[[1]]$indicator, scalar("art_current"))
expect_equal(programme_indicators[[1]]$name,
scalar("ART number (attending)"))
expect_equal(programme_indicators[[2]]$indicator, scalar("art_new"))
expect_equal(programme_indicators[[2]]$name, scalar("ART new"))
expect_equal(programme_indicators[[3]]$indicator, scalar("vls_tested"))
expect_equal(programme_indicators[[3]]$name, scalar("VLS tested"))
expect_equal(programme_indicators[[4]]$indicator, scalar("vls_suppressed"))
expect_equal(programme_indicators[[4]]$name, scalar("VLS tests suppressed"))
})

test_that("error thrown when metadata contains conflicting information", {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-time-series.R
Expand Up @@ -14,7 +14,7 @@ test_that("get_programme_time_series returns data and columns", {
expect_equal(columns[[1]]$id, scalar("plot_type"))
expect_equal(columns[[1]]$column_id, scalar("plot"))
expect_equal(columns[[1]]$label, scalar("Plot type"))
expect_length(columns[[1]]$values, 5)
expect_length(columns[[1]]$values, 20)
expect_setequal(names(columns[[1]]$values[[1]]),
c("id", "label", "description"))
expect_equal(columns[[2]]$id, scalar("area_level"))
Expand Down
12 changes: 10 additions & 2 deletions tests/testthat/test-validate-inputs.R
Expand Up @@ -106,9 +106,17 @@ test_that("do_validate_programme validates programme file", {
expect_equal(data$filters$calendar_quarter[[1]]$id, scalar("CY2018Q4"))
expect_equal(data$filters$calendar_quarter[[1]]$label, scalar("December 2018"))

expect_length(data$filters$indicators, 1)
expect_length(data$filters$indicators, 4)
expect_equal(data$filters$indicators[[1]]$id, scalar("art_current"))
expect_equal(data$filters$indicators[[1]]$label, scalar("ART number (attending)"))
expect_equal(data$filters$indicators[[1]]$label,
scalar("ART number (attending)"))
expect_equal(data$filters$indicators[[2]]$id, scalar("art_new"))
expect_equal(data$filters$indicators[[2]]$label, scalar("ART new"))
expect_equal(data$filters$indicators[[3]]$id, scalar("vls_tested"))
expect_equal(data$filters$indicators[[3]]$label, scalar("VLS tested"))
expect_equal(data$filters$indicators[[4]]$id, scalar("vls_suppressed"))
expect_equal(data$filters$indicators[[4]]$label,
scalar("VLS tests suppressed"))
})

test_that("do_validate_anc validates ANC file and gets data for plotting", {
Expand Down

0 comments on commit bc8ea2c

Please sign in to comment.