pub struct TestMutationContext {
pub auth: AuthContext,
pub request: RequestMetadata,
/* private fields */
}Expand description
Test context for mutation functions with mock dispatch and optional DB access.
Fields§
§auth: AuthContext§request: RequestMetadataImplementations§
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 user_id(&self) -> Result<Uuid>
pub fn user_id(&self) -> Result<Uuid>
Get the authenticated user’s UUID. Returns 401 if not authenticated.
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 dispatch_job_at<T: Serialize>(
&self,
job_type: &str,
args: T,
scheduled_at: DateTime<Utc>,
) -> Result<Uuid>
pub async fn dispatch_job_at<T: Serialize>( &self, job_type: &str, args: T, scheduled_at: DateTime<Utc>, ) -> Result<Uuid>
Dispatch a job at a specific time (records for later verification).
Sourcepub async fn dispatch_job_after<T: Serialize>(
&self,
job_type: &str,
args: T,
delay: Duration,
) -> Result<Uuid>
pub async fn dispatch_job_after<T: Serialize>( &self, job_type: &str, args: T, delay: Duration, ) -> Result<Uuid>
Dispatch a job after a delay (records for later verification).
Sourcepub async fn dispatch<J: ForgeJob>(&self, args: J::Args) -> Result<Uuid>
pub async fn dispatch<J: ForgeJob>(&self, args: J::Args) -> Result<Uuid>
Type-safe dispatch: resolves the job name from the type’s ForgeJob
impl and serializes the args at the call site.
Sourcepub async fn dispatch_at<J: ForgeJob>(
&self,
args: J::Args,
scheduled_at: DateTime<Utc>,
) -> Result<Uuid>
pub async fn dispatch_at<J: ForgeJob>( &self, args: J::Args, scheduled_at: DateTime<Utc>, ) -> Result<Uuid>
Type-safe dispatch at a specific time.
Sourcepub async fn dispatch_after<J: ForgeJob>(
&self,
args: J::Args,
delay: Duration,
) -> Result<Uuid>
pub async fn dispatch_after<J: ForgeJob>( &self, args: J::Args, delay: Duration, ) -> Result<Uuid>
Type-safe dispatch after a delay.
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 async fn start<W: ForgeWorkflow>(&self, input: W::Input) -> Result<Uuid>
pub async fn start<W: ForgeWorkflow>(&self, input: W::Input) -> Result<Uuid>
Type-safe workflow start.
Sourcepub fn env_mock(&self) -> &MockEnvProvider
pub fn env_mock(&self) -> &MockEnvProvider
Get the mock env provider for verification.
Sourcepub fn into_mutation_context(self, pool: PgPool) -> MutationContext
pub fn into_mutation_context(self, pool: PgPool) -> MutationContext
Bridge to a real MutationContext wired with the test mocks.
Handlers are written against &MutationContext. Pass the bridged
context to invoke real handler bodies from tests. The mock job and
workflow dispatchers remain accessible on the TestMutationContext
for assertions (the same Arc<Mock*> is shared with the bridge).
A sqlx::PgPool is required because MutationContext performs
pool-backed operations (tx(), conn()); a real pool is the only
safe way to support those paths. Tests that don’t touch the database
can pass a pool created in a test fixture and never call those
methods.
Trait Implementations§
Source§impl EnvAccess for TestMutationContext
impl EnvAccess for TestMutationContext
fn env_provider(&self) -> &dyn EnvProvider
fn env(&self, key: &str) -> Option<String>
fn env_or(&self, key: &str, default: &str) -> String
fn env_require(&self, key: &str) -> Result<String>
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>
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 UnsafeUnpin 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