testing/db_entities.ts

DB-backed entity factories for tests that need real account + actor rows in the database.

Companion to testing/entities.ts — that file ships in-memory factories (create_test_account, create_test_actor) for tests that mock the DB; this file ships factories that hit a real Db so query-level tests don't reimplement the same query_create_account_with_actor wrapper in every file.

For full-fledged test accounts that also need an API token + signed session cookie + role_grants, use bootstrap_test_keeper (keeper) or create_test_account_with_credentials (additional accounts) from testing/app_server.ts instead.

view source

Declarations
#

5 declarations

create_test_account_with_actor
#

testing/db_entities.ts view source

(db: Db, options: { username: string; password_hash?: string | undefined; }): Promise<TestAccountWithActor> import {create_test_account_with_actor} from '@fuzdev/fuz_app/testing/db_entities.js';

Create an account + actor row pair in the database for tests.

Wraps query_create_account_with_actor with a default password_hash so suites that don't exercise password verification can stay terse. Replaces the per-file create_user / create_test_actor / create_test_account helpers that had accumulated across the auth test suite. The username is stored lowercased, as every production creation path stores it and the account_username_lowercase CHECK requires.

db

type Db

options

type { username: string; password_hash?: string | undefined; }

returns

Promise<TestAccountWithActor>

create_test_extra_actor
#

testing/db_entities.ts view source

(db: Db, account_id: string, name: string): Promise<Actor> import {create_test_extra_actor} from '@fuzdev/fuz_app/testing/db_entities.js';

Add a second actor to an existing test account — the multi-actor edge.

Its created_at is read from the wall clock (clock_timestamp()) rather than the transaction-fixed NOW() default the production query_create_actor relies on. Actors listed for an account sort by created_at ASC, id ASC, so an extra actor seeded in the transaction that created the account's first one would share its created_at and order by random id, and the multi-actor actor_required available list would come out in a random order. Seeded through here, the first actor sorts first and the extras in insert order. The bootstrap-cradle seeding of extra_actors uses it — the _testing_reset action and the in-process setup — as the Rust reset seeds them with query_create_actor_with_clock_timestamp.

db

the database, or the transaction the account was seeded in

type Db

account_id

the account the actor joins

type string

name

the actor's name

type string

returns

Promise<Actor>

the created actor

mutates

  • actor table — inserts the new row

create_test_role_grant_direct
#

testing/db_entities.ts view source

(db: Db, input: CreateRoleGrantInput): Promise<RoleGrant> import {create_test_role_grant_direct} from '@fuzdev/fuz_app/testing/db_entities.js';

Materialize a role_grant directly via query_create_role_grant, bypassing the production offer/accept consent flow.

In-process only. This helper takes a raw Db handle and seeds rows without firing audit fan-out, WebSocket broadcasts, or the _supersede notification chain a real grant emits. Cross-process suites must instead drive role_grant_offer_create_action_spec + role_grant_offer_accept_action_spec via testing/role_grant_helpers.ts's role_grant_offer_and_accept so the fixture observes the full post-commit fan-out the way production does — otherwise tests would mask real divergence between the TS and Rust spines.

Use this helper for query-level (*.db.test.ts) tests that exercise revoke or isolation semantics — not the consent path itself. The schema's source_offer_id = null shape is an intentional admin-direct escape; this helper exposes it so suites don't reimplement the same direct-seed wrapper.

db

type Db

input

returns

Promise<RoleGrant>

soft_delete_test_actor
#

testing/db_entities.ts view source

(db: Db, actor_id: string): Promise<boolean> import {soft_delete_test_actor} from '@fuzdev/fuz_app/testing/db_entities.js';

Soft-delete (tombstone) one actor via the production query_actor_soft_delete — returns true when an active row flipped. The TS twin of the Rust query_actor_soft_delete the guard tests use, for seeding the latent multi-actor tombstone state directly (no per-actor-delete RPC ships yet).

db

type Db

actor_id

type string

returns

Promise<boolean>

TestAccountWithActor
#

Depends on
#

Imported by
#