tests/testthat/test-800-exportLogging-argumentValidation.R

context("Export Logging Argument Validation")

#####################################################################
# Argument Validation 

test_that(
  "Return an error when rcon is not a redcapConnection object", 
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon = "not an rcon"), 
      "no applicable method for 'exportLogging'"
    )
  }
)


test_that(
  "Return an error when log_type is not one of event types",
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon, 
                    logtype = "abc"), 
      "Variable 'logtype': Must be element of set"
    )
  }
)


test_that(
  "Return an error when user is not character", 
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon, 
                    user = 1:2), 
      "Variable 'user': Must be of type 'character'"
    )
  }
)

test_that(
  "Return an error when record is not character", 
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon, 
                    record = 1:2), 
      "Variable 'record': Must be of type 'character'"
    )
  }
)


test_that(
  "Return an error when dag is not a character", 
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon, 
                    dag = 1:2), 
      "Variable 'dag': Must be of type 'character'"
    )
  }
)


test_that(
  "Return an error when beginTime is not POSIXct", 
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon, 
                    beginTime = "2023-01-01 00:00:00"), 
      "Variable 'beginTime': Must be of type 'POSIXct'"
    )
  }
)


test_that(
  "Return an error when beginTime has length > 1", 
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon, 
                    beginTime = rep(Sys.time(), 2)), 
      "Variable 'beginTime': Must have length <= 1"
    )
  }
)


test_that(
  "Return an error when endTime is not POSIXct", 
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon, 
                    endTime = "2023-01-01 00:00:00"), 
      "Variable 'endTime': Must be of type 'POSIXct'"
    )
  }
)


test_that(
  "Return an error when endTime has length > 1", 
  {
    local_reproducible_output(width = 200)
    expect_error(
      exportLogging(rcon, 
                    endTime = rep(Sys.time(), 2)), 
      "Variable 'endTime': Must have length <= 1"
    )
  }
)

test_that(
  "Validate error_handling, config, api_param", 
  {
    local_reproducible_output(width = 200)
    expect_error(exportLogging(rcon, 
                               error_handling = "not an option"), 
                 "'error[_]handling': Must be element of set [{]'null','error'[}]")
    
    expect_error(exportLogging(rcon, 
                               config = list(1)), 
                 "'config': Must have names")
    expect_error(exportLogging(rcon, 
                               config = "not a list"), 
                 "'config': Must be of type 'list'")
    
    expect_error(exportLogging(rcon, 
                               api_param = list(1)), 
                 "'api_param': Must have names")
    expect_error(exportLogging(rcon, 
                               api_param = "not a list"), 
                 "'api_param': Must be of type 'list'")
  }
)

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.