← tests

body

The parser and the validator, with size crossed against validation.

Comparable across every framework. Bind parses without validating, so validate minus bind is the validator alone rather than the validator plus the parse.

A refusal's status is written 4XX. Frameworks refuse with different statuses, so each declares its own in its client-exception, and the test reads it from there.

testheftrequestbasewhat differs from the base
body.bind_small2POST /body/bind/small
body.bind_medium3POST /body/bind/mediumbody.bind_smalla larger response body, same route and same handler
body.bind_large4POST /body/bind/largebody.bind_mediuma larger response body, same route and same handler
body.validate_large5POST /body/validate/largebody.bind_largethe bound body checked against a schema
body.validate_medium3POST /body/validate/mediumbody.bind_mediumthe bound body checked against a schema
body.validate_small2POST /body/validate/smallbody.bind_smallthe bound body checked against a schema
body.rejected_all2POST /body/validate/smallbody.validate_smallthe request refused rather than served
body.rejected_first2POST /body/validate/first-errorbody.rejected_allthe first field error reported instead of all of them

body.bind_small

heft 2

base of body.bind_medium, body.validate_small, items.create

A body parsed and bound without being validated. The answer carries a count of the leaves it found, which is what says the request was parsed rather than piped to the response. This is what the validate row of the same size is subtracted from.

Request

POST /body/bind/small
content-typeapplication/json

payload order.small

{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1}]}

Expected response

HTTP 200

payload bind.small

{"fields":4,"bytes":66,"echo":{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1}]}}

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/body/bind-small.ts
tests/body/bind-small.tsopen on GitHub →
import { performanceTest } from "#kit";
import { bind, order } from "#payloads";

const path = "/body/bind/small";

export default performanceTest({
  id: { family: "body", name: "bind_small" },
  path,
  heft: 2,
  about:
    "A body parsed and bound without being validated. The answer carries a " +
    "count of the leaves it found, which is what says the request was parsed " +
    "rather than piped to the response. This is what the validate row of the " +
    "same size is subtracted from.",

  request: (c) => c.post(path, order.small.value).okWith(bind.small),
});

body.bind_medium

heft 3

base body.bind_smallbase of body.bind_large, body.validate_medium

A body parsed and bound without being validated. The answer carries a count of the leaves it found, which is what says the request was parsed rather than piped to the response. This is what the validate row of the same size is subtracted from.

Request

POST /body/bind/medium
content-typeapplication/json

payload order.medium

{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1},{"productId":2,"qty":2},{"productId":3,"qty":3},{"productId":4,"qty":4},{"productId":5,"qty":5},{"productId":6,"qty":1},{"productId":7,"qty":2},{"productId":8,"qty":3},{"productId":9,"qty":4},{"productId":10,"qty":5},{"productId":11,"qty":1},{"productId":12,"qty":2},{"productId":13,"qty":3},{"productId":14,"qty":4},{"productId":15,"qty":5},{"productId":16,"qty":1},{"productId":17,"qty":2},{"productId":18,"qty":3},{"productId":19,"qty":4},{"productId":20,"qty":5},{"productId":21,"qty":1},{"productId":22,"qty":2},{"productId":23,"qty":3},{"productId":24,"qty":4},{"productId":25,"qty":5},{"productId":26,"qty":1},{"productId":27,"q
… 8,379 bytes total

Expected response

HTTP 200

payload bind.medium

{"fields":674,"bytes":8379,"echo":{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1},{"productId":2,"qty":2},{"productId":3,"qty":3},{"productId":4,"qty":4},{"productId":5,"qty":5},{"productId":6,"qty":1},{"productId":7,"qty":2},{"productId":8,"qty":3},{"productId":9,"qty":4},{"productId":10,"qty":5},{"productId":11,"qty":1},{"productId":12,"qty":2},{"productId":13,"qty":3},{"productId":14,"qty":4},{"productId":15,"qty":5},{"productId":16,"qty":1},{"productId":17,"qty":2},{"productId":18,"qty":3},{"productId":19,"qty":4},{"productId":20,"qty":5},{"productId":21,"qty":1},{"productId":22,"qty":2},{"productId":23,"qty":3},{"productId":24,"qty":4},{"productId":25,"qty":5},{"product
… 8,414 bytes total

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/body/bind-medium.ts
tests/body/bind-medium.tsopen on GitHub →
import { performanceTest } from "#kit";
import { bind, order } from "#payloads";

const path = "/body/bind/medium";

export default performanceTest({
  id: { family: "body", name: "bind_medium" },
  path,
  base: "body.bind_small",
  varies: "size",
  heft: 3,
  about:
    "A body parsed and bound without being validated. The answer carries a " +
    "count of the leaves it found, which is what says the request was parsed " +
    "rather than piped to the response. This is what the validate row of the " +
    "same size is subtracted from.",

  request: (c) => c.post(path, order.medium.value).okWith(bind.medium),
});

body.bind_large

heft 4

base body.bind_mediumbase of body.validate_large

A body parsed and bound without being validated, at about 40 KB. The answer carries a count of the leaves it found, which is what says the request was parsed rather than piped to the response. Read against body.bind_medium, the difference is the parser and the binder at scale.

Request

POST /body/bind/large
content-typeapplication/json

payload order.large

{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1},{"productId":2,"qty":2},{"productId":3,"qty":3},{"productId":4,"qty":4},{"productId":5,"qty":5},{"productId":6,"qty":1},{"productId":7,"qty":2},{"productId":8,"qty":3},{"productId":9,"qty":4},{"productId":10,"qty":5},{"productId":11,"qty":1},{"productId":12,"qty":2},{"productId":13,"qty":3},{"productId":14,"qty":4},{"productId":15,"qty":5},{"productId":16,"qty":1},{"productId":17,"qty":2},{"productId":18,"qty":3},{"productId":19,"qty":4},{"productId":20,"qty":5},{"productId":21,"qty":1},{"productId":22,"qty":2},{"productId":23,"qty":3},{"productId":24,"qty":4},{"productId":25,"qty":5},{"productId":26,"qty":1},{"productId":27,"q
… 39,754 bytes total

Expected response

HTTP 200

payload bind.large

{"fields":3202,"bytes":39754,"echo":{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1},{"productId":2,"qty":2},{"productId":3,"qty":3},{"productId":4,"qty":4},{"productId":5,"qty":5},{"productId":6,"qty":1},{"productId":7,"qty":2},{"productId":8,"qty":3},{"productId":9,"qty":4},{"productId":10,"qty":5},{"productId":11,"qty":1},{"productId":12,"qty":2},{"productId":13,"qty":3},{"productId":14,"qty":4},{"productId":15,"qty":5},{"productId":16,"qty":1},{"productId":17,"qty":2},{"productId":18,"qty":3},{"productId":19,"qty":4},{"productId":20,"qty":5},{"productId":21,"qty":1},{"productId":22,"qty":2},{"productId":23,"qty":3},{"productId":24,"qty":4},{"productId":25,"qty":5},{"produ
… 39,791 bytes total

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/body/bind-large.ts
tests/body/bind-large.tsopen on GitHub →
import { performanceTest } from "#kit";
import { bind, order } from "#payloads";

const path = "/body/bind/large";

export default performanceTest({
  id: { family: "body", name: "bind_large" },
  path,
  base: "body.bind_medium",
  varies: "size",
  heft: 4,
  about:
    "A body parsed and bound without being validated, at about 40 KB. The " +
    "answer carries a count of the leaves it found, which is what says the " +
    "request was parsed rather than piped to the response. Read against " +
    "body.bind_medium, the difference is the parser and the binder at scale.",

  request: (c) => c.post(path, order.large.value).okWith(bind.large),
});

body.validate_large

heft 5

base body.bind_large

The same body checked against a schema before the handler sees it, and answered exactly as the bind row answers it. Read against body.bind_large, the difference is the validator alone rather than the validator plus the parse.

Request

POST /body/validate/large
content-typeapplication/json

payload order.large

{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1},{"productId":2,"qty":2},{"productId":3,"qty":3},{"productId":4,"qty":4},{"productId":5,"qty":5},{"productId":6,"qty":1},{"productId":7,"qty":2},{"productId":8,"qty":3},{"productId":9,"qty":4},{"productId":10,"qty":5},{"productId":11,"qty":1},{"productId":12,"qty":2},{"productId":13,"qty":3},{"productId":14,"qty":4},{"productId":15,"qty":5},{"productId":16,"qty":1},{"productId":17,"qty":2},{"productId":18,"qty":3},{"productId":19,"qty":4},{"productId":20,"qty":5},{"productId":21,"qty":1},{"productId":22,"qty":2},{"productId":23,"qty":3},{"productId":24,"qty":4},{"productId":25,"qty":5},{"productId":26,"qty":1},{"productId":27,"q
… 39,754 bytes total

Expected response

HTTP 200

payload bind.large

{"fields":3202,"bytes":39754,"echo":{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1},{"productId":2,"qty":2},{"productId":3,"qty":3},{"productId":4,"qty":4},{"productId":5,"qty":5},{"productId":6,"qty":1},{"productId":7,"qty":2},{"productId":8,"qty":3},{"productId":9,"qty":4},{"productId":10,"qty":5},{"productId":11,"qty":1},{"productId":12,"qty":2},{"productId":13,"qty":3},{"productId":14,"qty":4},{"productId":15,"qty":5},{"productId":16,"qty":1},{"productId":17,"qty":2},{"productId":18,"qty":3},{"productId":19,"qty":4},{"productId":20,"qty":5},{"productId":21,"qty":1},{"productId":22,"qty":2},{"productId":23,"qty":3},{"productId":24,"qty":4},{"productId":25,"qty":5},{"produ
… 39,791 bytes total

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/body/validate-large.ts
tests/body/validate-large.tsopen on GitHub →
import { performanceTest } from "#kit";
import { bind, order } from "#payloads";

const path = "/body/validate/large";

export default performanceTest({
  id: { family: "body", name: "validate_large" },
  path,
  base: "body.bind_large",
  varies: "validation",
  heft: 5,
  about:
    "The same body checked against a schema before the handler sees it, and " +
    "answered exactly as the bind row answers it. Read against " +
    "body.bind_large, the difference is the validator alone rather than the " +
    "validator plus the parse.",

  request: (c) => c.post(path, order.large.value).okWith(bind.large),
});

body.validate_medium

heft 3

base body.bind_medium

The same body checked against a schema before the handler sees it, and answered exactly as the bind row answers it. Read against body.bind_medium, the difference is the validator alone rather than the validator plus the parse.

Request

POST /body/validate/medium
content-typeapplication/json

payload order.medium

{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1},{"productId":2,"qty":2},{"productId":3,"qty":3},{"productId":4,"qty":4},{"productId":5,"qty":5},{"productId":6,"qty":1},{"productId":7,"qty":2},{"productId":8,"qty":3},{"productId":9,"qty":4},{"productId":10,"qty":5},{"productId":11,"qty":1},{"productId":12,"qty":2},{"productId":13,"qty":3},{"productId":14,"qty":4},{"productId":15,"qty":5},{"productId":16,"qty":1},{"productId":17,"qty":2},{"productId":18,"qty":3},{"productId":19,"qty":4},{"productId":20,"qty":5},{"productId":21,"qty":1},{"productId":22,"qty":2},{"productId":23,"qty":3},{"productId":24,"qty":4},{"productId":25,"qty":5},{"productId":26,"qty":1},{"productId":27,"q
… 8,379 bytes total

Expected response

HTTP 200

payload bind.medium

{"fields":674,"bytes":8379,"echo":{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1},{"productId":2,"qty":2},{"productId":3,"qty":3},{"productId":4,"qty":4},{"productId":5,"qty":5},{"productId":6,"qty":1},{"productId":7,"qty":2},{"productId":8,"qty":3},{"productId":9,"qty":4},{"productId":10,"qty":5},{"productId":11,"qty":1},{"productId":12,"qty":2},{"productId":13,"qty":3},{"productId":14,"qty":4},{"productId":15,"qty":5},{"productId":16,"qty":1},{"productId":17,"qty":2},{"productId":18,"qty":3},{"productId":19,"qty":4},{"productId":20,"qty":5},{"productId":21,"qty":1},{"productId":22,"qty":2},{"productId":23,"qty":3},{"productId":24,"qty":4},{"productId":25,"qty":5},{"product
… 8,414 bytes total

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/body/validate-medium.ts
tests/body/validate-medium.tsopen on GitHub →
import { performanceTest } from "#kit";
import { bind, order } from "#payloads";

const path = "/body/validate/medium";

export default performanceTest({
  id: { family: "body", name: "validate_medium" },
  path,
  base: "body.bind_medium",
  varies: "validation",
  heft: 3,
  about:
    "The same body checked against a schema before the handler sees it, and " +
    "answered exactly as the bind row answers it. Read against " +
    "body.bind_medium, the difference is the validator alone rather than the " +
    "validator plus the parse.",

  request: (c) => c.post(path, order.medium.value).okWith(bind.medium),
});

body.validate_small

heft 2

base body.bind_smallbase of body.rejected_all

The same body checked against a schema before the handler sees it, and answered exactly as the bind row answers it. Read against body.bind_small, the difference is the validator alone rather than the validator plus the parse.

Request

POST /body/validate/small
content-typeapplication/json

payload order.small

{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1}]}

Expected response

HTTP 200

payload bind.small

{"fields":4,"bytes":66,"echo":{"customerId":1,"status":"open","lines":[{"productId":1,"qty":1}]}}

Compared as parsed JSON, so key order and how a number is written do not matter.

Test source, tests/body/validate-small.ts
tests/body/validate-small.tsopen on GitHub →
import { performanceTest } from "#kit";
import { bind, order } from "#payloads";

const path = "/body/validate/small";

export default performanceTest({
  id: { family: "body", name: "validate_small" },
  path,
  base: "body.bind_small",
  varies: "validation",
  heft: 2,
  about:
    "The same body checked against a schema before the handler sees it, and " +
    "answered exactly as the bind row answers it. Read against " +
    "body.bind_small, the difference is the validator alone rather than the " +
    "validator plus the parse.",

  request: (c) => c.post(path, order.small.value).okWith(bind.small),
});

body.rejected_all

heft 2

base body.validate_smallbase of body.rejected_first, errors.malformed

Three fields wrong in one body. What a rejection looks like is the framework's own contract, so the status and the field paths are read through its exceptions declaration and this test never sees an error body.

Request

POST /body/validate/small
content-typeapplication/json

payload order.invalid

{"customerId":0,"status":"","lines":[]}

Expected response

HTTP 4XX

The status the framework declares as rejected in its client-exception.

The framework's own error body, read through its client-exception. It has to name customerId, status and lines, or exactly one of them where the framework declares that it reports only the first error.

Test source, tests/body/rejected-all.ts
tests/body/rejected-all.tsopen on GitHub →
import { performanceTest } from "#kit";
import { order } from "#payloads";

const path = "/body/validate/small";

export default performanceTest({
  id: { family: "body", name: "rejected_all" },
  path,
  base: "body.validate_small",
  varies: "outcome",
  heft: 2,
  about:
    "Three fields wrong in one body. What a rejection looks like is the " +
    "framework's own contract, so the status and the field paths are read " +
    "through its exceptions declaration and this test never sees an error " +
    "body.",

  request: (c) => c.post(path, order.invalid.value).rejected("customerId", "status", "lines"),
});

body.rejected_first

heft 2

base body.rejected_all

The same body against a route that stops at the first bad field. Read against body.rejected_all, the difference is the two error contracts: one walks the whole object and one gives up, and the second is doing less work.

Request

POST /body/validate/first-error
content-typeapplication/json

payload order.invalid

{"customerId":0,"status":"","lines":[]}

Expected response

HTTP 4XX

The status the framework declares as rejected in its client-exception.

The framework's own error body, read through its client-exception. It has to name customerId.

Test source, tests/body/rejected-first.ts
tests/body/rejected-first.tsopen on GitHub →
import { performanceTest } from "#kit";
import { order } from "#payloads";

const path = "/body/validate/first-error";

export default performanceTest({
  id: { family: "body", name: "rejected_first" },
  path,
  base: "body.rejected_all",
  varies: "error_contract",
  heft: 2,
  about:
    "The same body against a route that stops at the first bad field. Read " +
    "against body.rejected_all, the difference is the two error contracts: " +
    "one walks the whole object and one gives up, and the second is doing " +
    "less work.",

  request: (c) => c.post(path, order.invalid.value).rejected("customerId"),
});