Test an order lifecycle

Arrange an authored create/read/cancel contract, verify response origin and state, and repeat the case with explicit isolation and cleanup.

Authored contract · synthetic data

Create, read, cancel, then read the changed order

This sequential test models one order lifecycle: a new order starts pending, cancel changes it to cancelled, and subsequent reads retain that state. A recorded response supplies an input; the configured resource and lifecycle model supplies the cross-request relationship.

  • Identity: save each create response’s actual ID and use it for every later action and assertion.
  • Transition policy: this example explicitly rejects a repeated cancel after cancellation. That policy must be configured; a generic success response is not acceptance.
  • Gostly case: prepare the documented create/read and identity contract and an authored pending-to-cancelled chart with explicit invalid-transition rejection. Load that chart before capture and the scenario baseline, in an isolated workspace.
  • Starting point: inspect the API baseline before the create and start with a clean client. Confirm the selected service and library are ready in MOCK; keep unrelated faults, polling or timer transitions outside this trace.
Expected results for this authored test
ActionExpected responseDependency assertionClient assertion
Create order A201 · returned ID A · status pendingA exists in the pending stateStore the actual returned ID; do not substitute a recorded example ID
Read A200 · ID A · status pendingThe read resolves to this resource’s current stateShow the pending order associated with A
Cancel A200 · ID A · status cancelledThe configured cancel transition changes AShow cancellation only after accepting that response
Read A again200 · ID A · status cancelledThe changed state is visible; unrelated fixture fields retain their expected valuesKeep A cancelled after a refresh or re-read

Add the refused action. Send cancel again. Under this example’s configured rejection policy, expect a 409 refusal, leave A cancelled and check that the client does not announce another successful change.

Require the intended response origin. Recorded responses can answer before the mutable paths. This case requires resource-origin evidence on its reads and transition-origin evidence on the accepted cancel, alongside the expected ID and state. Use the documented response markers; a recorded 200 does not satisfy those checks.

The static response test that falsely passes

These independent stubs make every request look successful. They never connect cancellation to the later read.

DELIBERATELY BROKEN FIXTURE · authored example
Create       201  { id: "fixed-order", status: "pending" }
Read         200  { id: "fixed-order", status: "pending" }
Cancel       200  { id: "fixed-order", status: "cancelled" }
Read again   200  { id: "fixed-order", status: "pending" }

Status-only check: passes [201, 200, 200, 200]
State check: fails — the final read has forgotten the cancellation

Assert the returned ID and state before and after the action. Making every read return cancelled would fail the initial pending check instead. Include a client assertion too: an optimistically updated interface can look correct while the API still serves stale state.

Make isolation and cleanup part of the test plan

  1. Separate resource instances. Create A and B, keep both returned IDs and cancel only A. Read both: A must be cancelled and B must remain pending.
  2. Separate test contexts. Give concurrent tests distinct API episodes and client state. Reset one context and verify the other context’s resource has not changed; do not share one mutable baseline instance between workers.
  3. Restore the API baseline. Confirm reset completion before the next create, then use its new returned ID. A reset does not promise stable IDs or restore the proxy’s serving configuration.
  4. Clear the client’s old state. Remove cached IDs, queued work and optimistic results. Check that the next trace uses its own create response rather than an old test’s ID.
  5. Inspect stale-ID responses. A fallback recording can still produce a 200. Check identity, body and response origin rather than treating that status as proof the old resource survived reset.
  6. Close the disposable test context. Release its isolated API state and client work after the run, including failures. Keep the observed trace before cleanup if it explains a failure.

For each run, keep the fixture/chart revision, service route, test context, returned IDs, actions, response origins and application assertion result. A response log alone does not establish that the client persisted or displayed the correct state.

Review statechart setup, response markers and the episode/reset workflow. A reset does not restore application storage or proxy configuration; live episodes end on proxy restart.

Use the stateful API testing guide to choose the model and boundaries. This authored lifecycle does not establish database transactions, authentication, durable writes or every provider business rule.