testing/integration_helpers.ts

Integration test helpers — route lookup, response validation, and cookie utilities.

Declarations
#

11 declarations

view source

ADMIN_ONLY_FIELD_BLOCKLIST
#

assert_no_error_info_leakage
#

testing/integration_helpers.ts view source

(body: Record<string, unknown>, context: string): void

Assert that an error response contains no leaky field values.

Checks both field names and string values for patterns indicating stack traces, SQL, or internal paths.

body

parsed error response JSON

type Record<string, unknown>

context

description for error messages

type string

returns

void

assert_no_sensitive_fields_in_json
#

testing/integration_helpers.ts view source

(body: unknown, blocklist: readonly string[], context: string): void

Assert that a parsed JSON body contains no fields from the given blocklist.

body

parsed response JSON

type unknown

blocklist

field names to check for

type readonly string[]

context

description for error messages

type string

returns

void

assert_rate_limit_retry_after_header
#

testing/integration_helpers.ts view source

(response: Response, body: { retry_after: number; }): void

Assert that a 429 response includes a valid Retry-After header matching the JSON body's retry_after field.

response

the 429 response

type Response

body

parsed JSON body with retry_after field

type { retry_after: number; }

returns

void

assert_response_matches_spec
#

testing/integration_helpers.ts view source

(route_specs: RouteSpec[], method: string, path: string, response: Response): Promise<void>

Validate a response body against the route spec's declared schemas.

For 2xx responses, validates against spec.output. For error responses, validates against the merged error schema for that status code. Throws with details on mismatch.

route_specs

route specs for schema lookup

type RouteSpec[]

method

HTTP method of the request

type string

path

path of the request

type string

response

the Response to validate

type Response

returns

Promise<void>

check_error_response_fields
#

testing/integration_helpers.ts view source

(body: Record<string, unknown>): string[]

Assert that an error response body contains no unexpected fields.

Error schemas use z.looseObject (intentional — multiple producers), but test responses should be checked for fields that could leak information. Flags any field not in the known-safe set.

body

parsed error response JSON

type Record<string, unknown>

returns

string[]

array of unexpected field names (empty = clean)

collect_json_keys_recursive
#

testing/integration_helpers.ts view source

(value: unknown): Set<string>

Recursively collect all key names from a parsed JSON value.

Walks objects and arrays to find every property name at any nesting depth.

value

parsed JSON value

type unknown

returns

Set<string>

set of all key names found

create_expired_test_cookie
#

find_auth_route
#

testing/integration_helpers.ts view source

(specs: RouteSpec[], suffix: string, method: RouteMethod): RouteSpec | undefined

Find an auth route by suffix and method.

Useful for discovering login/logout/verify/revoke paths regardless of consumer prefix (/api/account/login, /api/auth/login, etc.).

specs

route specs to search

type RouteSpec[]

suffix

path suffix to match (e.g. '/login')

type string

method

HTTP method

returns

RouteSpec | undefined

matching route spec, or undefined

find_route_spec
#

testing/integration_helpers.ts view source

(specs: RouteSpec[], method: string, path: string): RouteSpec | undefined

Find a route spec matching the given method and path.

Supports both exact matches and parameterized paths (:param segments).

specs

route specs to search

type RouteSpec[]

method

HTTP method

type string

path

request path (exact or with concrete param values)

type string

returns

RouteSpec | undefined

matching route spec, or undefined

SENSITIVE_FIELD_BLOCKLIST
#

Depends on
#

Imported by
#