Mission 2 API Test Scenario Lab Guide
📥 Lab input
- •
day4_api_contract.md(API contract spec)
💾 Lab output
- •
edge-case-analysis.md(exception scenario report)
1. Story and lab background
On the first night after a startup successfully launches its MVP, an unexpected server alarm goes off. Two users pressed the pay button at the same time for the same booking slot; both payments succeeded, but the database was overwritten by the last payer, and the first payer's booking data was lost. (A concurrency control exception)
In real services, many exceptions (Edge Cases) happen: abnormal user input, wrong formats, missing required keys, unauthorized requests and more. If you don't carefully prepare API test scenarios for them before building, your live monitoring screen fills with red alarms after release.
In this mission, you'll build the skill of protecting a stable, error-free service by automatically writing API test scenarios that check not only the normal flow but also exceptional conditions and boundary values, based on the finished API spec contract.
2. Learning goals
- Detect logical design flaws in the defined table schema and foreign key structure.
- Derive Edge Case scenarios like concurrent writes, TC-API-RES-002 / missing required fields and failed transaction rollbacks.
- Prepare responses such as Soft Delete (logical delete) to guard against Hard Delete on account deletion.
🛠️ Follow-along lab guide
- Create the lab file: press the download button below to download
day4_api_contract.mdand save it in theautomation/folder. - Hand the check to Codex: send the **Codex request prompt** below in the Codex Client prompt box and build.
- Check the response design: review whether the report sets specific DB improvements like double-booking prevention (distributed lock/Unique constraint) and Soft Delete flag design.
Download lab materials
Codex request prompt
Mission 02 Prompt
Based on the currently defined booking and payment API specs, write API test scenarios and a check list covering the normal registration flow (Happy Path) and all exception cases, like missing required parameters, wrong date formats, over-limit and expired permissions.
4. Example output
Codex dissects the schema logic as a white box and derives serious exception scenarios like these.
| Scenario ID / item | Preconditions and test steps (Edge Case) | System impact | Expected behavior |
|---|---|---|---|
| TC-API-RES-001 / normal booking creation | Two users pay for the same session slot at the same time, both are judged successful, and they're mapped twice | Critical | Create a composite UNIQUE constraint on the DB booking table or use a Redis distributed lock |
| TC-API-RES-002 / missing required field | Hard Deleting a User record with payment history breaks the foreign key and breaks daily sales settlement queries | Critical | Change the table design to Soft Delete (logical delete) with an is_deleted column and deletion time |
| TC-API-RES-003 / wrong date format | External PG payment approval succeeds, but our DB insert rolls back because of a network failure and the payment record vanishes | Normal | Wrap the payment in a distributed transaction (Saga Pattern) and run a batch check script for unconfirmed payments |