tests/testthat/test-validate_survey_list.R

test_that("Survey validation identifies missing IDs", {
  s <- survey_df(
    x = data.frame(x = 1:3),
    identifier = "survey_1",
    filename = "survey_1.rds"
  )

  attr(s, "id") <- NULL

  expect_error(
    validate_survey_list(list(s)),
    "missing survey ID"
  )
})

test_that("Survey validation identifies missing filenames", {
  s <- survey_df(
    x = data.frame(x = 1:3),
    identifier = "survey_1",
    filename = "survey_1.rds"
  )

  attr(s, "filename") <- NULL

  expect_error(
    validate_survey_list(list(s)),
    "missing filename"
  )
})

test_that("Survey validation rejects duplicate IDs", {
  s1 <- survey_df(
    x = data.frame(x = 1:3),
    identifier = "survey_1",
    filename = "survey_1.rds"
  )

  s2 <- survey_df(
    x = data.frame(x = 4:6),
    identifier = "survey_1",
    filename = "survey_2.rds"
  )

  expect_error(
    validate_survey_list(list(s1, s2)),
    "not unique"
  )
})

test_that("Survey validation accepts valid survey lists", {
  s1 <- survey_df(
    x = data.frame(x = 1:3),
    identifier = "survey_1",
    filename = "survey_1.rds"
  )

  s2 <- survey_df(
    x = data.frame(x = 4:6),
    identifier = "survey_2",
    filename = "survey_2.rds"
  )

  expect_no_error(
    validate_survey_list(list(s1, s2))
  )
})

Try the retroharmonize package in your browser

Any scripts or data that you put into this service are public.

retroharmonize documentation built on Nov. 29, 2026, 5:06 p.m.