pub struct TestMutationContext {
pub auth: AuthContext,
pub request: RequestMetadata,
/* private fields */
}Expand description
Test context for mutation functions.
Provides an isolated testing environment for mutations with configurable authentication, optional database access, and mock job/workflow dispatch.
§Example
ⓘ
let ctx = TestMutationContext::builder()
.as_user(Uuid::new_v4())
.build();
// Dispatch a job
ctx.dispatch_job("send_email", json!({"to": "test@example.com"})).await?;
// Verify job was dispatched
ctx.job_dispatch().assert_dispatched("send_email");Fields§
§auth: AuthContextAuthentication context.
request: RequestMetadataRequest metadata.
Implementations§
Source§impl TestMutationContext
impl TestMutationContext
Sourcepub fn builder() -> TestMutationContextBuilder
pub fn builder() -> TestMutationContextBuilder
Create a new builder.
Sourcepub fn minimal() -> TestMutationContext
pub fn minimal() -> TestMutationContext
Create a minimal unauthenticated context.
Sourcepub fn authenticated(user_id: Uuid) -> TestMutationContext
pub fn authenticated(user_id: Uuid) -> TestMutationContext
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 TestMutationContext
impl EnvAccess for TestMutationContext
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 TestMutationContext
impl !RefUnwindSafe for TestMutationContext
impl Send for TestMutationContext
impl Sync for TestMutationContext
impl Unpin for TestMutationContext
impl !UnwindSafe for TestMutationContext
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