Tests build their data and check their pages by hand, with one copy of each helper per package #191

Open
opened 2026-10-06 21:25:47 +00:00 by cgalo5758 · 1 comment
Owner

Database tests copy openers from neighbours. About forty test files build catalogs through generated queries and raw INSERTs, and more than forty fixture types re-invent the same steps. Page tests use substring search (over 1,300 calls in internal/server), string offsets for order, and exact class lists. A raw INSERT can build a state the console cannot produce, as the demo seed can (#32); a fixture that ignores an error leaves its test asserting on nothing.

Done when: shared packages beside internal/stripetest provide database helpers, a builder that goes through the console's own functions and fails on any error, a session helper and an HTML query helper selecting by role and aria-*, hx-*, data-*; tests use them; and no test inserts catalog or grant rows with raw SQL.

Database tests copy openers from neighbours. About forty test files build catalogs through generated queries and raw INSERTs, and more than forty fixture types re-invent the same steps. Page tests use substring search (over 1,300 calls in `internal/server`), string offsets for order, and exact class lists. A raw INSERT can build a state the console cannot produce, as the demo seed can (#32); a fixture that ignores an error leaves its test asserting on nothing. Done when: shared packages beside `internal/stripetest` provide database helpers, a builder that goes through the console's own functions and fails on any error, a session helper and an HTML query helper selecting by role and `aria-*`, `hx-*`, `data-*`; tests use them; and no test inserts catalog or grant rows with raw SQL.
cgalo5758 added this to the Public launch milestone 2026-10-06 21:25:47 +00:00
cgalo5758 added the
kind
debt
area/testing
labels 2026-10-06 21:25:47 +00:00
Author
Owner

The test kit landed with the test-kit step of #166:

  • internal/testkit/dbtest opens the shared test databases. Open skips when TEST_DATABASE_URL is unset, never migrates, and refuses a database whose core ledger is behind; Scratch gives a migration's own test a database of its own.
  • internal/testkit/world builds fixtures through the console's own functions where one exists, fails the test on any error, and suffixes names so tests do not collide.
  • internal/testkit/authtest writes a signed-in session, and internal/testkit/htmltest selects elements by role and by aria-*, hx-* and data-* attributes instead of searching the page's text.
  • internal/integrations/fedwiki/fedwikitest builds the FedWiki fixtures, and test/e2e/browsertest holds the browser helpers the walkthroughs and the screens tool share.

Every test that uses a shared test database opens it through dbtest. The shell, FedWiki, migration, walkthrough, screens and plan-management tests are converted.

What keeps this open:

  • Render-test assertions. The member plans and operator reads tests still check rendered pages by substring: about 190 checks in 13 member-plans files (member_upgrade_render_test.go has 36) and about 525 in 15 operator files (operator_enrollment_render_test.go has 130, grant_resumption_operator_test.go 96). They move to htmltest with the code they test, in #188 and #189.
  • Rows inserted by hand. 66 raw INSERTs of catalog or grant rows remain in 27 test files: 22 in 9 files of internal/server (the server fixtures), 23 in 5 of internal/integrations/stripe/workflows, 16 in 9 of internal/entitlements, 2 in 2 of internal/integrations/discourse, 2 in 2 of internal/workflows/entitlements, and 1 in internal/workflows/desiredstate. Each converts with the code it tests. Some of them are tests whose subject is the raw row, such as the enclosure tests that expect a privilege refusal, the conferral-proof refusals and the Stripe mapping uniqueness tests; those belong on an exemption list instead.
  • The merchant sheet's catalog (test/e2e/merchant-disclosure/sheet_test.go). It detaches and re-attaches the demo ladder's tiers while members still hold them, flips is_public in bulk, and writes synced price mappings with made-up Stripe ids. The tier handler refuses a removal without a disposition for default holders and shrinks every holder's provision, so the sheet needs a way to change tiers outside the handlers before it can convert.
  • The delivery-core row helpers. internal/integration's dq builders, newLifecycleFixture, committedLifecycleFixture and regKey, and internal/workflows/desiredstate's fx builders write their rows themselves. They touch no catalog or grant table, but they are the pattern world replaces.
  • A lint rule that holds "no raw catalog or grant rows" once the rest converts, with a list of the tests whose subject is the raw row.
The test kit landed with the test-kit step of #166: - `internal/testkit/dbtest` opens the shared test databases. `Open` skips when `TEST_DATABASE_URL` is unset, never migrates, and refuses a database whose core ledger is behind; `Scratch` gives a migration's own test a database of its own. - `internal/testkit/world` builds fixtures through the console's own functions where one exists, fails the test on any error, and suffixes names so tests do not collide. - `internal/testkit/authtest` writes a signed-in session, and `internal/testkit/htmltest` selects elements by role and by `aria-*`, `hx-*` and `data-*` attributes instead of searching the page's text. - `internal/integrations/fedwiki/fedwikitest` builds the FedWiki fixtures, and `test/e2e/browsertest` holds the browser helpers the walkthroughs and the screens tool share. Every test that uses a shared test database opens it through `dbtest`. The shell, FedWiki, migration, walkthrough, screens and plan-management tests are converted. What keeps this open: - **Render-test assertions.** The member plans and operator reads tests still check rendered pages by substring: about 190 checks in 13 member-plans files (`member_upgrade_render_test.go` has 36) and about 525 in 15 operator files (`operator_enrollment_render_test.go` has 130, `grant_resumption_operator_test.go` 96). They move to `htmltest` with the code they test, in #188 and #189. - **Rows inserted by hand.** 66 raw INSERTs of catalog or grant rows remain in 27 test files: 22 in 9 files of `internal/server` (the server fixtures), 23 in 5 of `internal/integrations/stripe/workflows`, 16 in 9 of `internal/entitlements`, 2 in 2 of `internal/integrations/discourse`, 2 in 2 of `internal/workflows/entitlements`, and 1 in `internal/workflows/desiredstate`. Each converts with the code it tests. Some of them are tests whose subject is the raw row, such as the enclosure tests that expect a privilege refusal, the conferral-proof refusals and the Stripe mapping uniqueness tests; those belong on an exemption list instead. - **The merchant sheet's catalog** (`test/e2e/merchant-disclosure/sheet_test.go`). It detaches and re-attaches the demo ladder's tiers while members still hold them, flips `is_public` in bulk, and writes synced price mappings with made-up Stripe ids. The tier handler refuses a removal without a disposition for default holders and shrinks every holder's provision, so the sheet needs a way to change tiers outside the handlers before it can convert. - **The delivery-core row helpers.** `internal/integration`'s `dq` builders, `newLifecycleFixture`, `committedLifecycleFixture` and `regKey`, and `internal/workflows/desiredstate`'s `fx` builders write their rows themselves. They touch no catalog or grant table, but they are the pattern `world` replaces. - **A lint rule** that holds "no raw catalog or grant rows" once the rest converts, with a list of the tests whose subject is the raw row.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: wiki-cafe/member-console#191