tests/testthat/test-354-getProjectIdFields.R

context("Get Project ID Fields")

test_that(
  "Argument Validation", 
  {
    local_reproducible_output(width = 200)
    expect_error(getProjectIdFields("not an rcon"), 
                 "'rcon': Must inherit from class 'redcapConnection'")
  }
)

test_that(
  "Get the ID fields", 
  {
    expect_equal(getProjectIdFields(rcon), 
                 "record_id")
    
    # Force a secondary unique field
    NewInfo <- data.frame(secondary_unique_field = "text_test")
    importProjectInformation(rcon, NewInfo)
    rcon$refresh_projectInformation()
    
    expect_equal(getProjectIdFields(rcon), 
                 c("record_id", "text_test"))
    
    # Cleanup
    NewInfo <- data.frame(secondary_unique_field = "", 
                          surveys_enabled = 0)
    importProjectInformation(rcon, NewInfo)
    rcon$refresh_projectInformation()
  }
)

test_that("Does not return secondary field that is not in current fields",
  {
    # Force a secondary unique field
    NewInfo <- data.frame(secondary_unique_field = "does_not_exist")
    importProjectInformation(rcon, NewInfo)
    rcon$refresh_projectInformation()
    
    expect_warning(ids <- getProjectIdFields(rcon), "secondary unique field that does not exist")
    expect_equal(ids, "record_id")
    
    # Cleanup
    NewInfo <- data.frame(secondary_unique_field = "", 
                          surveys_enabled = 0)
    importProjectInformation(rcon, NewInfo)
    rcon$refresh_projectInformation()
  }
)

Try the redcapAPI package in your browser

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

redcapAPI documentation built on Sept. 13, 2023, 1:07 a.m.