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 authenticated(user_id: Uuid) -> Self
pub fn authenticated(user_id: Uuid) -> Self
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>
pub fn require_user_id(&self) -> Result<Uuid>
Get the authenticated user ID or return an error.
Sourcepub fn require_subject(&self) -> Result<&str>
pub fn require_subject(&self) -> Result<&str>
Like require_user_id() but for non-UUID auth providers.
Sourcepub async fn dispatch_job<T: Serialize>(
&self,
job_type: &str,
args: T,
) -> Result<Uuid>
pub async fn dispatch_job<T: Serialize>( &self, job_type: &str, args: T, ) -> Result<Uuid>
Dispatch a job (records for later verification).
Sourcepub async fn cancel_job(
&self,
job_id: Uuid,
reason: Option<String>,
) -> Result<bool>
pub async fn cancel_job( &self, job_id: Uuid, reason: Option<String>, ) -> Result<bool>
Cancel a job (records for later verification).
Sourcepub async fn start_workflow<T: Serialize>(
&self,
name: &str,
input: T,
) -> Result<Uuid>
pub async fn start_workflow<T: Serialize>( &self, name: &str, input: T, ) -> Result<Uuid>
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.
Sourcepub fn pending_jobs(&self) -> Vec<PendingJob>
pub fn pending_jobs(&self) -> Vec<PendingJob>
Get pending jobs from the outbox buffer.
Sourcepub fn pending_workflows(&self) -> Vec<PendingWorkflow>
pub fn pending_workflows(&self) -> Vec<PendingWorkflow>
Get pending workflows from the outbox buffer.
Sourcepub fn assert_job_buffered(&self, job_type: &str)
pub fn assert_job_buffered(&self, job_type: &str)
Assert that a job was buffered in the outbox.
Sourcepub fn assert_workflow_buffered(&self, workflow_name: &str)
pub fn assert_workflow_buffered(&self, workflow_name: &str)
Assert that a workflow was buffered in the outbox.
Trait Implementations§
Source§impl EnvAccess for TestMutationContext
impl EnvAccess for TestMutationContext
Source§fn env_provider(&self) -> &dyn EnvProvider
fn env_provider(&self) -> &dyn EnvProvider
Source§fn env_or(&self, key: &str, default: &str) -> String
fn env_or(&self, key: &str, default: &str) -> String
Source§fn env_require(&self, key: &str) -> Result<String>
fn env_require(&self, key: &str) -> Result<String>
Source§fn env_parse<T: FromStr>(&self, key: &str) -> Result<T>
fn env_parse<T: FromStr>(&self, key: &str) -> Result<T>
Source§fn env_parse_or<T: FromStr>(&self, key: &str, default: T) -> Result<T>
fn env_parse_or<T: FromStr>(&self, key: &str, default: T) -> Result<T>
Source§fn env_contains(&self, key: &str) -> bool
fn env_contains(&self, key: &str) -> bool
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
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>
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>
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