forge_core/testing/mod.rs
1//! Testing utilities for FORGE applications.
2//!
3//! This module provides comprehensive testing infrastructure for all FORGE function types:
4//! - Queries (read-only database access)
5//! - Mutations (write operations + job/workflow dispatch)
6//! - Actions (external HTTP calls)
7//! - Jobs (background processing)
8//! - Crons (scheduled tasks)
9//! - Workflows (durable multi-step processes)
10//!
11//! # Philosophy
12//!
13//! Following sqlx's testing philosophy, we recommend testing against real databases
14//! rather than mocks. However, for unit tests that don't need database access,
15//! the test contexts can be used without a database connection.
16//!
17//! # Zero-Config Database
18//!
19//! `TestDatabase::embedded()` automatically downloads and starts an embedded PostgreSQL
20//! instance - no configuration required. This is the recommended approach for tests.
21//!
22//! # Example
23//!
24//! ```ignore
25//! use forge::prelude::*;
26//!
27//! #[tokio::test]
28//! async fn test_authenticated_query() {
29//! let ctx = TestQueryContext::builder()
30//! .as_user(Uuid::new_v4())
31//! .with_role("admin")
32//! .build();
33//!
34//! assert!(ctx.auth.is_authenticated());
35//! assert!(ctx.auth.has_role("admin"));
36//! }
37//! ```
38
39pub mod assertions;
40pub mod context;
41pub mod db;
42pub mod mock_dispatch;
43pub mod mock_http;
44
45pub use assertions::*;
46pub use context::*;
47pub use db::{IsolatedTestDb, TestDatabase};
48pub use mock_dispatch::{DispatchedJob, MockJobDispatch, MockWorkflowDispatch, StartedWorkflow};
49pub use mock_http::{MockHttp, MockHttpBuilder, MockRequest, MockResponse};
50
51use std::time::Duration;
52
53/// Default test timeout.
54pub const DEFAULT_TEST_TIMEOUT: Duration = Duration::from_secs(30);
55
56/// Default job test timeout.
57pub const DEFAULT_JOB_TIMEOUT: Duration = Duration::from_secs(10);
58
59/// Default workflow test timeout.
60pub const DEFAULT_WORKFLOW_TIMEOUT: Duration = Duration::from_secs(60);