whenCommand

fun whenCommand(command: Any, requestId: String = "request-", expectedVersion: Int? = null, scope: Scope? = null, headers: Map<String, String> = emptyMap(), operator: Operator? = null, caller: Caller? = null, expect: Expectations<S>.() -> Unit)

Sends command through the kernel and checks its outcome in expect. An exception the decide function throws fails the specification, unless expect checks it with Expectations.expectError.

caller sends it, the specification's by default (aggregateSpec, asCaller), as the gateway admits a caller's command: in its scope, by its operator, with its application as the request fact app_id. scope names a scope it acts in, in the specification's tenant, as Wow-Scope does for a caller crossing scopes (its operator then acting elsewhere). A caller the gateway refuses fails the specification with the gateway's answer: one of another tenant than the specification's that names no scope, or one naming a scope without Caller.crossScope; headers adds request facts (a scheduled command's me.ahoo.wow.api.schedule.ScheduleContext.headers, say) and operator replaces the caller's. Without a caller, the command is an anonymous one in scope, none by default. headers never name a fact admission takes from the caller (CallerAdmission.FACTS, app_id): such a header fails the specification, with or without a caller, since the gateway never records it; give the application with caller instead.

A command whose body names its aggregate (me.ahoo.wow.api.annotation.AggregateId) names the specification's, or none: one that names another fails the specification, as admission refuses it.