Files
jspg/tests/database/executor.rs
2026-03-10 18:25:29 -04:00

44 lines
1.1 KiB
Rust

use jspg::database::executor::DatabaseExecutor;
use serde_json::Value;
use std::sync::Mutex;
pub struct MockExecutor {
pub query_responses: Mutex<Vec<Result<Value, String>>>,
pub execute_responses: Mutex<Vec<Result<(), String>>>,
}
impl MockExecutor {
pub fn new() -> Self {
Self {
query_responses: Mutex::new(Vec::new()),
execute_responses: Mutex::new(Vec::new()),
}
}
}
impl DatabaseExecutor for MockExecutor {
fn query(&self, _sql: &str, _args: Option<&[Value]>) -> Result<Value, String> {
let mut responses = self.query_responses.lock().unwrap();
if responses.is_empty() {
return Ok(Value::Array(vec![]));
}
responses.remove(0)
}
fn execute(&self, _sql: &str, _args: Option<&[Value]>) -> Result<(), String> {
let mut responses = self.execute_responses.lock().unwrap();
if responses.is_empty() {
return Ok(());
}
responses.remove(0)
}
fn auth_user_id(&self) -> Result<String, String> {
Ok("00000000-0000-0000-0000-000000000000".to_string())
}
fn timestamp(&self) -> Result<String, String> {
Ok("2026-03-10T00:00:00Z".to_string())
}
}