tests/testthat/test-client-delete.R

skip_on_cran()
skip_if_offline(url_parse(hb())$domain)
context("HttpClient: delete")

test_that("delete request works", {
  cli <- HttpClient$new(url = hb())
  aa <- cli$delete("delete")

  expect_is(aa, "HttpResponse")
  expect_is(aa$handle, 'curl_handle')
  expect_is(aa$content, "raw")
  expect_is(aa$method, "character")
  expect_equal(aa$method, "delete")
  expect_is(aa$parse, "function")
  expect_is(aa$parse(), "character")
  expect_true(aa$success())

  expect_null(aa$request$fields)
})

test_that("delete request with body", {
  cli <- HttpClient$new(url = hb())
  aa <- cli$delete("delete", body = list(hello = "world"))

  expect_is(aa, "HttpResponse")
  expect_is(aa$handle, 'curl_handle')
  expect_is(aa$content, "raw")
  expect_is(aa$method, "character")
  expect_equal(aa$method, "delete")
  expect_is(aa$parse, "function")
  expect_is(aa$parse("UTF-8"), "character")
  expect_true(aa$success())

  expect_named(aa$request$fields, "hello")
  expect_equal(aa$request$fields[[1]], "world")
})
ropenscilabs/crul documentation built on April 9, 2024, 8:45 p.m.