# WARNING - Generated by {fusen} from dev/flat_qmra.Rmd: do not edit by hand # nolint: line_length_linter.

test_that("get_tbl_risk works", {
  scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre"))
  
  expect_error(get_tbl_risk(scenario_test))

  scenario_conc <- inflow_concentration(scenario = scenario_test,
   pathogenName = c("Campylobacter jejuni", "Escherichia coli"))
  
  expect_error(get_tbl_risk(scenario_conc))
  
  scenario_volume <-
    scenario_conc |>                     
    mutate(
      volume = map(
        .x = config,                                         
        .f = ~ simulate_exposure(config = .x)              
      )
    )
  
  expect_error(get_tbl_risk(scenario_volume))
  
  scenario_dose_ini <- initial_dose_calculation(scenario_volume)
  
  scenario_scheme <- update_treatment_scheme(scenario_dose_ini)
  
  expect_error(get_tbl_risk(scenario_scheme))
  
  scenario_with_logreduc_and_co <- scenario_scheme |> 
    mutate( log_reduction = map(config, simulate_treatment))
  
  expect_error(get_tbl_risk(scenario_with_logreduc_and_co))
  
  scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co)
  
  result <- get_tbl_risk(scenario_final_dose_and_co_test)
  
  expect_equal(object = names(result[[1]]),
                expected = c("repeatID", "eventID", "inflow", "PathogenID", "PathogenName", 
"PathogenGroup", "volume_perEvent", "logreduction", "dose_perEvent", 
"effluent", "exposure_perEvent"))
  
  expect_equal(object = length(result),
                expected = 2)
  
  expect_equal(object = length(result[[1]]),
                expected = 11)
  expect_equal(object = length(result[[1]]$logreduction),
                expected = 120000)
})
