parsed_missing$test (`actual`) not equal to TRUE (`expected`).

`actual` is NULL
`expected` is a logical vector (TRUE)

test_that("enhanced request body parsing handles all content types", {
json_body <- charToRaw('{"name": "test", "value": 123, "nested": {"key": "value"}}')
req_json <- list(HTTP_CONTENT_TYPE = "application/json")
req_form <- list(HTTP_CONTENT_TYPE = "application/x-www-form-urlencoded")
text_body <- charToRaw("This is plain text content")
req_text <- list(HTTP_CONTENT_TYPE = "text/plain")
expect_equal(parsed_text, "This is plain text content")
# Test CSV content (should be treated as text)
req_csv <- list(HTTP_CONTENT_TYPE = "text/csv")
# Test unknown content type (should try JSON, fallback to string)
req_unknown <- list(HTTP_CONTENT_TYPE = "application/custom")
# Test unknown content type with non-JSON (should return string)
unknown_text_body <- charToRaw("not json content")
test_that("XML parsing works correctly", {
req_xml <- list(HTTP_CONTENT_TYPE = "application/xml")
# Malformed XML should return error object
req_text_xml <- list(HTTP_CONTENT_TYPE = "text/xml")
test_that("multipart form data handling works", {
HTTP_CONTENT_TYPE = paste0("multipart/form-data; boundary=", boundary)
req_no_boundary <- list(HTTP_CONTENT_TYPE = "multipart/form-data")
# Test with malformed multipart (should not crash)
malformed_multipart <- charToRaw("not actually multipart data")
test_that("transformation hooks work correctly", {
timestamp_hook <- function(data, content_type, req) {
if (is.list(data) && !is.null(data$timestamp)) {
data$timestamp <- as.POSIXct(data$timestamp, origin = "1970-01-01")
validation_hook <- function(data, content_type, req) {
# Test with JSON data containing timestamp
# Test with data that doesn't have timestamp
json_no_timestamp <- '{"name": "test", "value": 123}'
expect_null(parsed_no_timestamp$timestamp)  # Should not be modified
# Test with non-list data (should not crash)
expect_equal(parsed_text, "plain text")  # Should be unchanged
test_that("transformation hooks handle errors gracefully", {
error_hook <- function(data, content_type, req) {
normal_hook <- function(data, content_type, req) {
# Test that error in first hook doesn't prevent second hook from running
# Should not crash and should continue processing
# Normal hook should still have run despite error in first hook
test_that("payload_data_config validates inputs correctly", {
# Should fail with invalid transformation hooks
# Should fail with invalid max_payload_size
valid_hook <- function(data, content_type, req) data
test_that("data processing handles edge cases and large payloads", {
large_json <- jsonlite::toJSON(large_data, auto_unbox = TRUE)
# Test with malformed JSON that contains special characters
malformed_json <- '{"name": "test", "value": 123, "incomplete"'
binary_data <- as.raw(c(0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A))  # PNG header
req_binary <- list(HTTP_CONTENT_TYPE = "image/png")
# Should fall through to JSON attempt, then return as string (may be garbled)
nested_json <- paste0(rep('{"level":', nested_levels), collapse = "")
nested_json <- paste0(nested_json, '"deepest"', paste0(rep("}", nested_levels), collapse = ""))
# Should parse successfully (jsonlite handles deep nesting well)
unicode_json <- '{"message": "Hello 世界 🌍", "emoji": "🚀", "accents": "café"}'
test_that("content type detection handles various formats", {
req_charset <- list(HTTP_CONTENT_TYPE = "application/json; charset=utf-8")
req_multi_params <- list(HTTP_CONTENT_TYPE = "application/json; charset=utf-8; boundary=something")
req_upper <- list(HTTP_CONTENT_TYPE = "APPLICATION/JSON")
req_mixed <- list(HTTP_CONTENT_TYPE = "Application/Json")
req_whitespace <- list(HTTP_CONTENT_TYPE = "  application/json  ")
expect_equal(parsed_missing$test, TRUE)  # Should fallback to JSON parsing
expect_true(is.character(parsed_missing))  # Or return as string
# Test with content type in different request fields
HEADERS = list("content-type" = "text/plain")  # Should prefer HTTP_CONTENT_TYPE
test_that("error handling provides useful information", {
# Test JSON parsing error with detailed information
bad_json <- '{"name": "test", "value": 123, "missing_quote: true}'
invalid_content <- as.raw(c(0xFF, 0xFE, 0xFD, 0xFC))
req_invalid <- list(HTTP_CONTENT_TYPE = "application/json")
# Test error handling in transformation hooks
"Transformation hook failed: Custom error message"
# Should still return the parsed data despite hook error