commit de84dc2a5f3c6ce58a29cab7b5a8495487961a80
parent 3e198ba9726294f14e933302c9ce2398c972ec28
Author: kernelkind <kernelkind@gmail.com>
Date: Mon, 2 Feb 2026 12:11:00 -0500
test(outbox): utils
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/crates/enostr/src/relay/mod.rs b/crates/enostr/src/relay/mod.rs
@@ -27,6 +27,9 @@ pub use subscription::{
};
pub use websocket::{WebsocketConn, WebsocketRelay};
+#[cfg(test)]
+pub mod test_utils;
+
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum RelayStatus {
Connected,
diff --git a/crates/enostr/src/relay/test_utils.rs b/crates/enostr/src/relay/test_utils.rs
@@ -0,0 +1,45 @@
+#![cfg(test)]
+//! Test utilities for relay testing
+//!
+//! This module provides mock implementations and helpers for unit and integration tests.
+
+use nostrdb::Filter;
+
+use crate::Wakeup;
+
+/// A mock Wakeup implementation that tracks how many times wake() was called.
+///
+/// This is useful for unit tests to verify that wakeups are triggered correctly
+/// without needing a real UI/event loop.
+#[derive(Clone)]
+pub struct MockWakeup {}
+
+impl MockWakeup {
+ /// Create a new MockWakeup with zero wakeup count.
+ pub fn new() -> Self {
+ Self {}
+ }
+}
+
+impl Default for MockWakeup {
+ fn default() -> Self {
+ Self::new()
+ }
+}
+
+impl Wakeup for MockWakeup {
+ fn wake(&self) {}
+}
+
+// ==================== SubRegistry tests ====================
+
+pub fn trivial_filter() -> Vec<Filter> {
+ vec![Filter::new().kinds(vec![1]).build()]
+}
+
+pub fn filters_json(filters: &[Filter]) -> Vec<String> {
+ filters
+ .iter()
+ .map(|f| f.json().expect("serialize filter to json"))
+ .collect()
+}