tests/testthat/test-integrations.R

with_mock_dir("2024.12.0", {
  test_that("get_integrations() gets integrations", {
    client <- Connect$new(server = "https://connect.example", api_key = "fake")
    integrations <- get_integrations(client)
    expect_true(inherits(integrations, "connect_list_integrations"))

    # Check a few fields
    expect_equal(integrations[[1]]$name, "GitHub Integration")
    expect_equal(integrations[[2]]$updated_time, "2025-03-25T19:07:01Z")
    expect_equal(integrations[[1]]$config$client_id, "client_id_123")
  })

  test_that("get_integrations() can be converted to a data frame correctly", {
    client <- Connect$new(server = "https://connect.example", api_key = "fake")
    integrations_df <- get_integrations(client) |>
      as_tibble()
    expect_named(
      integrations_df,
      c(
        "id",
        "guid",
        "created_time",
        "updated_time",
        "name",
        "description",
        "template",
        "auth_type",
        "config"
      )
    )
    expect_equal(
      integrations_df$description,
      c(
        "with refresh support ",
        "The service provides utility to your company"
      )
    )
  })
})

test_that("get_integrations() errs on older Connect versions", {
  client <- MockConnect$new("2024.11.1")
  client$version
  expect_error(
    get_integrations(client),
    "This feature requires Posit Connect version 2024.12.0 but you are using 2024.11.1"
  )
})

Try the connectapi package in your browser

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

connectapi documentation built on Aug. 9, 2025, 1:09 a.m.