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.
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.
| Action | Expected response | Dependency assertion | Client assertion |
|---|---|---|---|
| Create order A | 201 · returned ID A · status pending | A exists in the pending state | Store the actual returned ID; do not substitute a recorded example ID |
| Read A | 200 · ID A · status pending | The read resolves to this resource’s current state | Show the pending order associated with A |
| Cancel A | 200 · ID A · status cancelled | The configured cancel transition changes A | Show cancellation only after accepting that response |
| Read A again | 200 · ID A · status cancelled | The changed state is visible; unrelated fixture fields retain their expected values | Keep 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 cancellationAssert 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
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
Related topics
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.