pub struct TestActionContext {
pub auth: AuthContext,
pub request: RequestMetadata,
/* private fields */
}Expand description
Test context for action functions.
Provides an isolated testing environment for actions with HTTP mocking, configurable authentication, and optional database access.
§Example
ⓘ
let ctx = TestActionContext::builder()
.as_user(Uuid::new_v4())
.mock_http_json("https://api.example.com/*", json!({"status": "ok"}))
.build();
// Make HTTP call (will return mocked response)
let response = ctx.http().execute(...).await;
// Verify HTTP call was made
ctx.http().assert_called("https://api.example.com/*");Fields§
§auth: AuthContextAuthentication context.
request: RequestMetadataRequest metadata.
Implementations§
Source§impl TestActionContext
impl TestActionContext
Sourcepub fn builder() -> TestActionContextBuilder
pub fn builder() -> TestActionContextBuilder
Create a new builder.
Sourcepub fn minimal() -> TestActionContext
pub fn minimal() -> TestActionContext
Create a minimal unauthenticated context.
Sourcepub fn authenticated(user_id: Uuid) -> TestActionContext
pub fn authenticated(user_id: Uuid) -> TestActionContext
Create an authenticated context.
Sourcepub fn job_dispatch(&self) -> &MockJobDispatch
pub fn job_dispatch(&self) -> &MockJobDispatch
Get the mock job dispatch for verification.
Sourcepub fn workflow_dispatch(&self) -> &MockWorkflowDispatch
pub fn workflow_dispatch(&self) -> &MockWorkflowDispatch
Get the mock workflow dispatch for verification.
Sourcepub fn require_user_id(&self) -> Result<Uuid, ForgeError>
pub fn require_user_id(&self) -> Result<Uuid, ForgeError>
Get the authenticated user ID or return an error.
Sourcepub async fn dispatch_job<T>(
&self,
job_type: &str,
args: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
pub async fn dispatch_job<T>(
&self,
job_type: &str,
args: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
Dispatch a job (records for later verification).
Sourcepub async fn start_workflow<T>(
&self,
name: &str,
input: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
pub async fn start_workflow<T>(
&self,
name: &str,
input: T,
) -> Result<Uuid, ForgeError>where
T: Serialize,
Start a workflow (records for later verification).
Sourcepub fn env_mock(&self) -> &MockEnvProvider
pub fn env_mock(&self) -> &MockEnvProvider
Get the mock env provider for verification.
Trait Implementations§
Source§impl EnvAccess for TestActionContext
impl EnvAccess for TestActionContext
Source§fn env_provider(&self) -> &dyn EnvProvider
fn env_provider(&self) -> &dyn EnvProvider
Get the environment provider.
Source§fn env_or(&self, key: &str, default: &str) -> String
fn env_or(&self, key: &str, default: &str) -> String
Get an environment variable with a default value. Read more
Source§fn env_require(&self, key: &str) -> Result<String, ForgeError>
fn env_require(&self, key: &str) -> Result<String, ForgeError>
Get a required environment variable. Read more
Source§fn env_parse<T>(&self, key: &str) -> Result<T, ForgeError>
fn env_parse<T>(&self, key: &str) -> Result<T, ForgeError>
Get an environment variable and parse it to the specified type. Read more
Source§fn env_parse_or<T>(&self, key: &str, default: T) -> Result<T, ForgeError>
fn env_parse_or<T>(&self, key: &str, default: T) -> Result<T, ForgeError>
Get an environment variable and parse it, with a default. Read more
Source§fn env_contains(&self, key: &str) -> bool
fn env_contains(&self, key: &str) -> bool
Check if an environment variable is set.
Auto Trait Implementations§
impl Freeze for TestActionContext
impl !RefUnwindSafe for TestActionContext
impl Send for TestActionContext
impl Sync for TestActionContext
impl Unpin for TestActionContext
impl !UnwindSafe for TestActionContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more