Problem · target: how to test null and type mismatch in api

Negative Tests for Preferences API with nullable fields: What to Assert

User must verify the API handles null and wrong-typed values deliberately.

Direct answer

Invalid payloads slip through because the schema is only used to validate requests, never to produce the negative cases, and Preferences API with nullable fields has 7 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 Preferences API with nullable fields with "CHECK constraint failed: length(locale) BETWEEN 2 AND 5", which is the error the API should return to the client instead of a success response.

Data as of 2026-11-18 · source: 1 Stack Overflow questions, @jest/source-map at 244,922,030 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 — Preferences API

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 Preferences API with nullable fields, the reference engine rejected the bad row with "NOT NULL constraint failed: users.email" — 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 Preferences API with nullable fields 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 Preferences API with nullable fields, the range probe on users.locale sits one step outside the boundary. The constraint is char_length("locale") BETWEEN 2 AND 5 and the probe value is 6. The engine said "CHECK constraint failed: length(locale) BETWEEN 2 AND 5". 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 Preferences API with nullable fields fixture, the assertion that catches a regression is a request carrying locale=6, 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 Preferences API with nullable fields, 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.

Real constraint failures for the Preferences API with nullable fields fixtureReproduced by executing the fixture against a local SQL engine (Node.js v24.22.0, engine 3.53.4) on 2026-11-18T11:53:54.233Z. The message column is verbatim engine output; the SQLSTATE column is the PostgreSQL error class for the same constraint class.
Failure classColumnSQLSTATEError nameEngine message (verbatim)
Missing required fieldusers.email23502not_null_violationNOT NULL constraint failed: users.email
Out-of-contract valueusers.locale23514check_violationCHECK constraint failed: length(locale) BETWEEN 2 AND 5
Boundary probes for every constrained column in Preferences API with nullable fieldsOne violating value per constraint, with the boundary it crosses.
TableColumnDeclared ruleProbe valueWhy it is invalid
userslocale2 to 5 charactersetoo short
usersmarketinginteger 0 or 12outside the allowed set
users.ts

npx --yes @wenlu8848/schemaseed generate --input ./prob_nulls.openapi.yaml --out ./seed --formats ts --count 10 --seed 42

Download prob_nulls.openapi.yaml

// Generated by schemaseed — do not edit by hand.
// Table: users

export interface UsersRow {
  id: string;
  email: string;
  display_name: string;
  nickname?: string | null;
  locale: string;
  timezone?: string | null;
  marketing: number;
}

export const usersRows: UsersRow[] = [
    {
      "id": "6aa597ce-583e-471b-b4f9-6a12fc245d48",
      "email": "hana.ibarra381@example.net",
      "display_name": "Quinn Novak",
      "nickname": "alpha ember",
      "locale": "Nairo",
      "timezone": "Eli Moreau",
      "marketing": 0
    },
    {
      "id": "498bd819-019c-4335-afb7-45cd91b14ebb",
      "email": "sami.lund277@example.org",
      "display_name": "Nairobi, Elm Avenue 92",
      "locale": "umbra",
      "timezone": "Iris Holt",
      "marketing": 0
    },
    {
      "id": "7b07e38c-f830-4b22-8b49-7295bd469c8e",
      "email": "chen.adler418@test.dev",
      "display_name": "alpha cedar",
      "nickname": "lumen ember",
      "locale": "zephy",
      "timezone": "quartz juniper",
      "marketing": 0
    },
    {
      "id": "a93b1c4c-e67e-4b8c-9f51-16d23e2401a7",
      "email": "rosa.novak512@example.net",
      "display_name": "onyx indigo",
      "nickname": "quartz summit",
      "locale": "Fay C",
      "timezone": "lumen meadow",
      "marketing": 0
    },
    {
      "id": "85ef2671-d17f-4404-95d7-319d28c2832c",
      "email": "chen.novak151@test.dev",
      "display_name": "Quinn Bianchi",
      "nickname": "zephyr-bravo-620",
      "locale": "meado",
      "timezone": "quinn.petrov@test.dev",
      "marketing": 0
    },
    {
      "id": "31bda2d2-cb16-4e7d-b88a-00bbb030ed8a",
      "email": "jun.bianchi336@example.net",
      "display_name": "umbra juniper",
      "nickname": "willow meadow",
      "locale": "lumen",
      "marketing": 0
    },
    {
      "id": "52ddf724-aa7f-4aaf-8a11-2909d74ddc49",
      "email": "hana.duarte555@example.com",
      "display_name": "Sami Novak",
      "nickname": "quartz river",
      "locale": "fay.d",
      "marketing": 0
    },
    {
      "id": "fccfe1ae-7838-4d53-a84f-9708e1c1f3ed",
      "email": "eli.adler556@test.dev",
      "display_name": "Toronto, Riverside Lane 197",
      "nickname": "Osaka, Maple Street 228",
      "locale": "grove",
      "marketing": 0
    },
    {
      "id": "e61bfd52-0449-4a80-a564-d0cfadcfa0eb",
      "email": "quinn.costa686@mail.example",
      "display_name": "Auckland, Harbor Road 210",
      "nickname": "Auckland, Maple Street 195",
      "locale": "Ada K",
      "timezone": "Dara Moreau",
      "marketing": 0
    },
    {
      "id": "eda9b425-d04b-43da-ab49-850d43f16f11",
      "email": "omar.novak260@example.org",
      "display_name": "gus.jansen@example.net",
      "nickname": "Jun Lund",
      "locale": "sami.",
      "timezone": "cedar willow",
      "marketing": 0
    }
  ];

Frequently asked questions

How many invalid cases do I actually need?
One per constraint class, not one per field. The Preferences API with nullable fields fixture declares its rules across 1 tables and 7 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 Preferences API with nullable fields 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 — users.locale 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 Preferences API with nullable fields the first probe is users.locale = 6, and the engine replied "CHECK constraint failed: length(locale) BETWEEN 2 AND 5".

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