Render the Brex card through ProviderItem::CardComponent

JA
5d ago
+1232-141

Summary

Provider kit Track B, B4a: Brex's accounts-page card (brex_items/_brex_item) renders through a shared ProviderItem::CardComponent. The card's HTML is unchanged, checked against snapshots of the partial taken before the change.

Part of jaysbeekay/sure#670 (Track B, item 4, first of two slices: B4a card, B4b panel). Stacked on B3b (jaysbeekay/sure#720) in fork stack #687.

Upstream draft PR: https://github.com/we-promise/sure/pull/5232 (same branch, same commit), in native stack we-promise/sure#5268 on refactor/provider-kit.

What changed

  • ProviderItem::CardComponent (new, app/components/provider_item/): the card's template, moved from the Brex partial, with the provider named by its key:
    • messages from the provider's existing <key>_items.<key>_item.* keys (no locale file changes);
    • the provider's logo, paths and dom id from its key and record;
    • the stats and account counts the partial computed (via brex_item_render_locals) are now methods on the component, still taking the per-connection maps the accounts page precomputes.
  • brex_items/_brex_item keeps its brex_item: / visible_accounts: locals and renders the component with Brex's three precomputed maps.
  • BrexItemsHelper#brex_item_render_locals is removed: the partial was its only caller, and no test referenced it.
  • No slots: the card has no Brex-specific parts. The sync-schedule menu item comes from the shared sync_schedule_menu_item helper that 26 cards use, so the component calls it directly.

Screenshots

None: the rendered card is unchanged. The snapshot tests below compare the component's HTML with the partial's, recorded before the change.

Demo data

No demo data needed: no new records.

Migration notes

No migration.

Verification

  • Snapshots: test/components/provider_item/snapshots/ holds seven renders of the original Brex partial, recorded before the change:

    • an admin;
    • an admin with a linked account;
    • a member with the connection's accounts;
    • a member shown one of two accounts (the #3630 case);
    • a member with no visible accounts;
    • a connection scheduled for deletion;
    • a sync error.

    The renders were recorded at a frozen time, with record ids, random element ids and CSRF tokens normalised, and whitespace between tags ignored. ProviderItem::CardComponentTest asserts that both the partial and the component render each snapshot. The seven component tests fail without the change (uninitialized constant ProviderItem::CardComponent).

  • Snapshot provenance (re-checked 2026-11-17): the seven partial snapshot tests were run against the old brex_items/_brex_item partial on up/provider-kit-controller-setup, before this slice: 7 runs, 0 failures. So the snapshots are the old partial's output, not the component's.

  • Whitespace: the normaliser ignores whitespace between and around tags, because the component's template is indented differently. A moved space between inline siblings would therefore pass; no such space differs in these renders.

  • Review fixes (2026-11-17): a test that the card reads the accounts page's precomputed counts, institutions and stats over the model's; the visible_accounts guard now scans the card component; the snapshot normaliser no longer accepts a blank CSRF token.

  • Existing tests unchanged: ProviderItemCardsTest (every card requires and lists only visible_accounts), AccountsControllerTest and the Brex tests pass unedited.

  • Mutations, each caught: counting every account as visible; listing the connection's own accounts instead of the visible ones; showing the admin menu to everyone; dropping the setup prompt; reading another provider's messages; ignoring the precomputed counts.

  • bin/rails test (full, at the B4a commit): 16,290 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).

  • bin/rubocop, erb_lint on the changed templates and bin/brakeman: no offenses or warnings.

  • Diff with copy detection (git diff -C against B3b): non-test +189 / -141.

  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • The accounts page and ProviderItemsController#complete_account_setup render brex_items/brex_item with brex_item: and visible_accounts:; unchanged.
  • ProviderItemCardsTest checks every *_items/_*_item partial requires visible_accounts; the Brex partial still declares it with no default.
  • Siblings: the other providers' cards keep their own partials; they move to the component in their own slices.