Problem · target: how to test api enum constraints
Negative Tests for Order status enum API: What to Assert
User needs to prove the enum is enforced, including the near-miss values.
Direct answer
Invalid payloads slip through because the schema is only used to validate requests, never to produce the negative cases, and Order status enum API has 6 constraints that nobody is testing.
This covers contract violations rather than memory-safety bugs, so a fuzzer is still the right tool when the defect class is a parser crash.
The engine rejected the violating row for Order status enum API with "CHECK constraint failed: orders_total_cents_check", which is the error the API should return to the client instead of a success response.
Data as of 2026-11-18 · source: 4 Stack Overflow questions, find-my-way at 115,367,824 monthly downloads · negative-case messages reproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) at 2026-11-18T11:53:54.233Z
What actually goes wrong — Order status
The failure is rarely a crash. The API accepts the payload, returns 200, and stores a row that violates a rule the schema promised to enforce. For Order status enum API, the reference engine rejected the bad row with "NOT NULL constraint failed: orders.reference" — that is the message the API should have surfaced to the client instead of a success response.
The four failure modes
Invalid payloads cluster into four families, and the Order status enum API fixture exercises all of them. Missing required fields, wrong types, out-of-range values and values outside a declared enum. Each family maps to a distinct engine error, and each family needs a distinct assertion in the test suite.
What the boundary probes look like
For Order status enum API, the range probe on orders.total_cents sits one step outside the boundary. The constraint is "total_cents" >= 0 and the probe value is -1. The engine said "CHECK constraint failed: orders_total_cents_check". A test that asserts a 4xx response for this value is asserting that the constraint the schema declares is actually enforced at the edge.
The assertion you actually want
Assert on the response code and on the error body, not on the absence of a crash. For the Order status enum API fixture, the assertion that catches a regression is a request carrying total_cents=-1, expecting a 4xx status and an error body that names the field. A test that only asserts "the request failed" passes even when the API fails for the wrong reason.
Where a fuzzing tool is the wrong answer
Unstructured fuzzing finds crashes, which is a different job from finding contract violations. For Order status enum API, a schema-derived negative set covers the cases a fuzzer would take hours to stumble into, and each one has a deterministic expected response. Reach for a fuzzer when the bug class is a parser crash, not when the bug class is a contract the API forgot to enforce.
| Failure class | Column | SQLSTATE | Error name | Engine message (verbatim) |
|---|---|---|---|---|
| Missing required field | orders.reference | 23502 | not_null_violation | NOT NULL constraint failed: orders.reference |
| Out-of-contract value | orders.total_cents | 23514 | check_violation | CHECK constraint failed: orders_total_cents_check |
| Table | Column | Declared rule | Probe value | Why it is invalid |
|---|---|---|---|---|
| orders | status | one of placed, paid, packed, shipped, delivered, cancelled | not_a_real_member | not a declared member |
| orders | status | one of placed, paid, packed, shipped, delivered, cancelled | PLACED | wrong case |
| orders | total_cents | >= 0 | -1 | below the lower bound |
npx --yes @wenlu8848/schemaseed generate --input ./prob_enums.openapi.yaml --out ./seed --formats ts --count 10 --seed 42
Download prob_enums.openapi.yaml
// Generated by schemaseed — do not edit by hand.
// Table: orders
export interface OrdersRow {
id: string;
reference: string;
status: string;
total_cents: number;
}
export const ordersRows: OrdersRow[] = [
{
"id": "1ac284da-0bc9-4bb8-95eb-c73e7e349614",
"reference": "Osaka, Elm Avenue 91",
"status": "placed",
"total_cents": 287
},
{
"id": "9645a667-7850-4cc7-b28f-cd3bde464b14",
"reference": "jun.grant@example.org",
"status": "shipped",
"total_cents": 797
},
{
"id": "ed74b93c-183a-491a-9aa2-022d870b2162",
"reference": "alpha delta",
"status": "placed",
"total_cents": 673
},
{
"id": "0c046f60-9101-4c69-8b91-a426838af067",
"reference": "Bogota, Elm Avenue 29",
"status": "packed",
"total_cents": 636
},
{
"id": "c98a71b8-6a9c-44d3-bb85-88b930379d37",
"reference": "river-bravo-356",
"status": "cancelled",
"total_cents": 955
},
{
"id": "e2c83719-226c-4036-86a1-c58a9f8f9d1f",
"reference": "Pia Ibarra",
"status": "cancelled",
"total_cents": 52
},
{
"id": "dae82b7a-8e61-4c59-812d-c2c8d4a7c52e",
"reference": "indigo-onyx-690",
"status": "cancelled",
"total_cents": 65
},
{
"id": "6a8cae67-5286-4771-8b1f-77bb4df4d4ec",
"reference": "jun.fontaine@test.dev",
"status": "paid",
"total_cents": 62
},
{
"id": "d69951c7-b015-4d5d-9e09-ac73d891854c",
"reference": "Gus Novak",
"status": "cancelled",
"total_cents": 455
},
{
"id": "3841add0-ff4a-4f79-8328-9df791f77e53",
"reference": "quartz ember",
"status": "paid",
"total_cents": 720
}
];
Frequently asked questions
- How many invalid cases do I actually need?
- One per constraint class, not one per field. The Order status enum API fixture declares its rules across 1 tables and 4 columns, and the table above lists the probe value for each.
- Should I fuzz instead?
- Only for crashes. A schema-derived negative set covers every declaration in Order status enum API deterministically, with an expected response for each.
- What status code should the API return?
- Your API decides that, consistently. The generator hands you the violating value and the constraint it breaks — orders.total_cents on this fixture — so the assertion can name the field.
- Do I need to write the assertions by hand?
- No. The negative instances come from the schema. For Order status enum API the first probe is orders.total_cents = -1, and the engine replied "CHECK constraint failed: orders_total_cents_check".
Run it against your own schema
SchemaSeed is MIT licensed and free: unlimited local generation, no account, no telemetry and no usage limit. It reads your schema file on your own machine, so nothing is uploaded anywhere. If it saves you time, you can support the project.
Get SchemaSeed — free Support the project
Questions: support@schemaseed.drz8848.win