"webhook endpoint simulation with full security"
"IoT sensor data collection with transformations"
"e-commerce order processing with multiple endpoints"
"log monitoring and alerting system simulation"
"Multiple failed login attempts detected"
"stress testing combined features under load"

webhook endpoint simulation with full security

length(webhook_history) (`actual`) not equal to 1 (`expected`).

  `actual`: 0.0
`expected`: 1.0

<subscriptOutOfBoundsError/error/condition>
Error in `webhook_history[[1]]`: subscript out of bounds

`recent_history` has length 0, not length 2.

test_that("payload_history_config validates inputs correctly", {
expect_silent(payload_history_config(max_items = 50, max_age_hours = 12))
expect_silent(payload_history_config(max_items = 1000, max_age_hours = 168))  # 1 week
test_that("payload history stores and retrieves data correctly", {
payload = list(sensor = "temperature", value = 25.5),
# Store payload manually using internal function
test_payload$meta$timestamp <- Sys.time() + i
Sys.sleep(0.01)  # Small delay to ensure different timestamps
expect_length(history_all, 6)  # 1 original + 5 new
history_limited <- payload_history("/test/sensor", limit = 3)
# Verify they're in reverse chronological order (newest first)
timestamps <- sapply(history_limited, function(x) x$timestamp)
test_that("payload history respects retention policies", {
payload_history_config(max_items = 3, max_age_hours = 0.001)  # ~3.6 seconds
meta = list(timestamp = Sys.time(), method = "POST")
# Should only keep last 3 items due to count limit
# Wait for age-based cleanup (this is approximate)
# Should have fewer items due to age limit
test_that("payload_history filters by time correctly", {
# Store payloads with different timestamps
timestamp = base_time + (i * 3600),  # Each payload 1 hour apart
since_time <- base_time + (3 * 3600)  # 3 hours from base
recent_history <- payload_history("/test/time", since = since_time)
expect_length(recent_history, 2)  # Should get payloads 4 and 5
# Filter to future time (should get nothing)
future_history <- payload_history("/test/time", since = future_time)
since_char <- format(since_time, "%Y-%m-%d %H:%M:%S")
char_history <- payload_history("/test/time", since = since_char)
test_that("payload_history_stats provides accurate information", {
endpoints <- c("/api/sensor1", "/api/sensor2", "/api/logs")
payload = list(endpoint = endpoint, id = i),
timestamp = base_time + (i * 60),  # Each payload 1 minute apart
expect_equal(stats_all$total_entries, 9)  # 3 endpoints * 3 payloads
endpoints <- c("/api/data", "/api/logs", "/api/events")
expect_length(payload_history("/api/logs"), 3)  # Should still exist
expect_equal(total_cleared, 6)  # 2 endpoints * 3 payloads each
test_that("payload history handles edge cases", {
# Test history with special characters in path
special_path <- "/api/data with spaces & symbols!@#"
long_path <- paste0("/api/", paste(rep("very_long_endpoint_name", 10), collapse = "_"))
test_that("payload history memory management works under stress", {
payload_history_config(max_items = 10, max_age_hours = 24)
data = rep(paste("data", i), 100),  # Large payload
ids <- sapply(history, function(x) x$payload$id)
expect_true(all(ids >= 41))  # Should have items 41-50
test_that("payload history handles concurrent access simulation", {
# Simulate concurrent writes to same endpoint
# Store payloads with slight delays to simulate concurrent access
thread_id = i %% 3,  # Simulate 3 different "threads"
# Small random delay to simulate real-world timing
thread_ids <- sapply(history, function(x) x$payload$thread_id)
ids <- sapply(history, function(x) x$id)
expect_equal(length(unique(ids)), length(ids))  # All IDs should be unique