tests/testthat/test-1-http.R

context("http")

library(httr)

test_that("check that response is compressed", {
  r <- trundler:::GET("https://api.trundler.dev/category")

  expect_true(headers(r)$`content-encoding` %in% c("gzip", "br", "deflate"))
})

test_that("http error message", {
  expect_equal(trundler:::http_error_message(401), "Missing or invalid API key.")
  expect_equal(trundler:::http_error_message(404), "Not found.")
  expect_equal(trundler:::http_error_message(429), "Limit exceeded.")
})

test_that("HEAD", {
  r <- trundler:::HEAD(sprintf("https://api.trundler.dev/retailer/%d/product", retailer_product_count_id))

  product_count <- as.integer(r$headers$`x-total-count`)

  expect_equal(product_count, as.integer(retailer_product_count))
})
datawookie/retail documentation built on Jan. 11, 2023, 4:07 a.m.