testing/entities.ts

Shared test entity factories for Account, Actor, RoleGrant, AuditLogEvent, RequestContext, and API tokens.

Override types widen branded Uuid fields to string so tests can pass literal ids without per-call-site casts. The factory brands internally.

Uses create_test_* names to avoid collisions with real create_account_with_actor from auth/account_queries.ts.

view source

Declarations
#

12 declarations

create_test_account
#

create_test_actor
#

create_test_audit_event
#

create_test_context
#

create_test_raw_api_token
#

testing/entities.ts view source

(label?: string): string import {create_test_raw_api_token} from '@fuzdev/fuz_app/testing/entities.js';

Create a well-formed raw API token for tests that need a bearer value to pass the is_api_token_shaped precheck and reach token validation. The body is label padded with A to the generated length, so distinct labels give distinct tokens and a token in a failure message reads back to its test. Not a real credential — it authenticates only where a test mocks the lookup.

label?

base64url characters (A-Z a-z 0-9 - _) that start the token body

type string
optional default 'test'

returns

string

throws

  • Error - when `label` is longer than the body or not base64url

create_test_role_grant
#

create_test_validated_api_token
#

TestAccountOverrides
#

testing/entities.ts view source

TestAccountOverrides

type Partial<Omit<Account, "id" | "created_by" | "updated_by">> & { id?: string | undefined; created_by?: string | null | undefined; updated_by?: string | null | undefined; }

import type {TestAccountOverrides} from '@fuzdev/fuz_app/testing/entities.js';

Override type for create_test_account — id-like fields accept plain string.

created_at?

type string

username?

type string

email?

type string | null

email_verified?

type boolean

updated_at?

type string

deleted_at?

Soft-delete tombstone. Non-null means the account is deleted (delete = soft); auth resolution treats it as absent. A hard purge removes the row entirely. See auth/account_queries.ts.

type string | null

password_hash?

type string

deleted_by?

Actor that performed the soft-delete (initiator: self / admin / keeper). Paired with deleted_at, mirroring role_grant's revoked_at / revoked_by. Plain UUID (no FK, like created_by / updated_by on this table).

type Branded | null

id?

type string

created_by?

type string | null

updated_by?

type string | null

TestActorOverrides
#

testing/entities.ts view source

TestActorOverrides

type Partial<Omit<Actor, "id" | "account_id" | "updated_by">> & { id?: string | undefined; account_id?: string | undefined; updated_by?: string | null | undefined; }

import type {TestActorOverrides} from '@fuzdev/fuz_app/testing/entities.js';

Override type for create_test_actor — id-like fields accept plain string.

created_at?

type string

name?

type string

updated_at?

type string | null

deleted_at?

Soft-delete tombstone — set alongside the owning account's soft-delete.

type string | null

deleted_by?

Actor that performed the soft-delete. Paired with deleted_at.

type Branded | null

id?

type string

account_id?

type string

updated_by?

type string | null

TestAuditEventOverrides
#

testing/entities.ts view source

TestAuditEventOverrides

type Partial<Omit<AuditLogEvent, "id" | "actor_id" | "account_id" | "target_account_id" | "target_actor_id">> & { id?: string | undefined; actor_id?: string | null | undefined; account_id?: string | null | undefined; target_account_id?: string | null | undefined; target_actor_id?: string | null | undefined; }

import type {TestAuditEventOverrides} from '@fuzdev/fuz_app/testing/entities.js';

Override type for create_test_audit_event — id-like fields accept plain string.

created_at?

type string

event_type?

type string

outcome?

type AuditOutcome

seq?

type number

ip?

type string | null

metadata?

type Record<string, unknown> | null

id?

type string

actor_id?

type string | null

account_id?

type string | null

target_account_id?

type string | null

target_actor_id?

type string | null

TestRoleGrantOverrides
#

testing/entities.ts view source

TestRoleGrantOverrides

type Partial<Omit<RoleGrant, "id" | "actor_id" | "scope_kind" | "scope_id" | "revoked_by" | "granted_by" | "source_offer_id">> & { id?: string | undefined; actor_id?: string | undefined; scope_kind?: string | null | undefined; scope_id?: string | null | undefined; revoked_by?: string | null | undefined; granted_by?: string | null | undefined; source_offer_id?: string | null | undefined; }

import type {TestRoleGrantOverrides} from '@fuzdev/fuz_app/testing/entities.js';

Override type for create_test_role_grant — id-like fields accept plain string.

created_at?

type string

expires_at?

type string | null

role?

type string

revoked_at?

type string | null

revoked_reason?

Optional free-form reason attached on revoke (rides on the role_grant_revoked WS notification to the revokee).

type string | null

id?

type string

actor_id?

type string

scope_kind?

type string | null

scope_id?

type string | null

revoked_by?

type string | null

granted_by?

type string | null

source_offer_id?

type string | null

TestValidatedApiTokenOverrides
#

testing/entities.ts view source

TestValidatedApiTokenOverrides

type Partial<Omit<ValidatedApiToken, "account_id">> & { account_id?: string | undefined; }

import type {TestValidatedApiTokenOverrides} from '@fuzdev/fuz_app/testing/entities.js';

Override type for create_test_validated_api_token — account_id accepts plain string.

id?

type string

created_at?

type string

expires_at?

type string | null

name?

type string

scope?

type TokenScope

last_used_at?

type string | null

last_used_ip?

type string | null

token_hash?

type string

expires_in_ms?

Milliseconds until the token expires — expires_at - NOW(), measured on the database clock in the statement that found it live (EXPIRES_IN_MS_SQL); null for an eternal token. The Rust twin's ApiTokenRow.expires_in.

type number | null

account_id?

type string

Depends on
#

Imported by
#