use crate::common::TestApp;
use obscura_server::adapters::redis::cache::RedisCache;
use std::sync::Arc;
use uuid::Uuid;
mod common;
#[tokio::test]
async fn test_redis_cache_basic_operations() {
let app = TestApp::spawn().await;
let redis_client = Arc::clone(&app.resources.pubsub);
let cache = RedisCache::new(redis_client, "test:cache:".to_string(), 60);
let key = Uuid::new_v4().to_string();
let value = b"hello world".to_vec();
let result = cache.get(&key).await.expect("Failed to get");
assert_eq!(result, None, "Expected None for non-existent key");
cache.set(&key, &value).await.expect("Failed to set");
let result = cache.get(&key).await.expect("Failed to get").expect("Expected value but got None");
assert_eq!(result, value, "Value mismatch");
cache.delete(&key).await.expect("Failed to delete");
let result = cache.get(&key).await.expect("Failed to get");
assert_eq!(result, None, "Expected None for deleted key");
}
#[tokio::test]
async fn test_redis_cache_expiration() {
let app = TestApp::spawn().await;
let redis_client = Arc::clone(&app.resources.pubsub);
let cache = RedisCache::new(redis_client, "test:cache:expire:".to_string(), 1);
let key = Uuid::new_v4().to_string();
let value = b"temporary".to_vec();
cache.set(&key, &value).await.expect("Failed to set");
tokio::time::sleep(tokio::time::Duration::from_secs(2)).await;
let result = cache.get(&key).await.expect("Failed to get");
assert_eq!(result, None, "Key should have expired");
}