← tests

query

Query string parsing, percent-decoding and coercion, with the values echoed and put to no other use.

Comparable across every framework. Eight parameters on the many row, because eight is what a real search endpoint carries: a page and a size, a sort, a text term and four filters.

A value written {run.name} is drawn once per run and never given to the framework, so it cannot answer from a table.

testheftrequestbasewhat differs from the base
query.one1GET /query/one?page={run.page}json.smallmore query string keys parsed, coerced and echoed
query.many2GET /query/many?page={run.page}&size={run.size}&status={run.status}&category={run.category}&sort={run.sort}&q={run.q}&minPrice={run.minPrice}&maxPrice={run.maxPrice}query.onemore query string keys parsed, coerced and echoed

query.one

heft 1

base json.smallbase of query.many

One query parameter parsed, coerced to an integer and written back. Read against json.small, the difference is the query string being parsed at all.

Request

GET /query/one?page={run.page}

No body.

Expected response

HTTP 200

payload items.small

{"size":"small","count":1,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true}],"echo":{"page":{run.page}}}

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

Test source, tests/query/one.ts
tests/query/one.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/query/one?page={run.page}";

export default performanceTest({
  id: { family: "query", name: "one" },
  path,
  base: "json.small",
  varies: "query_params",
  heft: 1,
  about:
    "One query parameter parsed, coerced to an integer and written back. Read " +
    "against json.small, the difference is the query string being parsed at " +
    "all.",

  request: (c) => c.get("/query/one").query("page", String(c.run.page)).okWith(items.small, { echo: ["page"] }),
});

query.many

heft 2

base query.onebase of forms.urlencoded

Eight parameters, which is what a real search endpoint carries: a page and a size, a sort, a text term and four filters. Read against query.one, the difference is seven more keys parsed, coerced and echoed.

Request

GET /query/many?page={run.page}&size={run.size}&status={run.status}&category={run.category}&sort={run.sort}&q={run.q}&minPrice={run.minPrice}&maxPrice={run.maxPrice}

No body.

Expected response

HTTP 200

payload items.small

{"size":"small","count":1,"items":[{"id":1,"name":"slate-lamp-6647","category":"tools","priceCents":18928,"inStock":true}],"echo":{"page":{run.page},"size":{run.size},"status":"{run.status}","category":"{run.category}","sort":"{run.sort}","q":"{run.q}","minPrice":{run.minPrice},"maxPrice":{run.maxPrice}}}

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

Test source, tests/query/many.ts
tests/query/many.tsopen on GitHub →
import { performanceTest } from "#kit";
import { items } from "#payloads";

const path = "/query/many?page={run.page}&size={run.size}&status={run.status}&category={run.category}&sort={run.sort}&q={run.q}&minPrice={run.minPrice}&maxPrice={run.maxPrice}";

export default performanceTest({
  id: { family: "query", name: "many" },
  path,
  base: "query.one",
  varies: "query_params",
  heft: 2,
  about:
    "Eight parameters, which is what a real search endpoint carries: a page " +
    "and a size, a sort, a text term and four filters. Read against " +
    "query.one, the difference is seven more keys parsed, coerced and echoed.",

  request: (c) =>
    c
      .get("/query/many")
      .query("page", String(c.run.page))
      .query("size", String(c.run.size))
      .query("status", c.run.status)
      .query("category", c.run.category)
      .query("sort", c.run.sort)
      .query("q", c.run.q)
      .query("minPrice", String(c.run.minPrice))
      .query("maxPrice", String(c.run.maxPrice))
      .okWith(items.small, { echo: ["page", "size", "status", "category", "sort", "q", "minPrice", "maxPrice"] }),
});