Serve Brex account setup from ProviderItemsController

JA
5d ago
+199-125

Summary

Provider kit Track B, B3b: Brex's account setup actions move into ProviderItemsController, and the provider_items route concern gains the two setup routes. BrexItems::AccountSetupsController goes, so all of Brex's routes are now served by the shared controller through BrexItemsController. Every route helper and path stays as it is.

Part of jaysbeekay/sure#670 (Track B, item 3, second of two slices: B3a connection and account linking, B3b account setup). Stacked on B3a (jaysbeekay/sure#719) in fork stack #687.

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

What changed

  • ProviderItemsController gains setup_accounts and complete_account_setup, moved from BrexItems::AccountSetupsController:
    • the setup page renders <key>_items/setup_accounts with @<key>_accounts from unlinked_provider_accounts;
    • after setup in a Turbo frame, the provider's card is replaced from <key>_items/_<key>_item;
    • submitted types are limited to the adapter's supported types, and subtypes to those types' subtypes. For Brex that is Depository and CreditCard, the same set as before.
    • both actions keep the admin guard and load the connection like the other member actions.
  • ProviderItem::AccountFlow.adapter_class becomes a class method, so the controller reads the supported types from the same place as the flow.
  • config/routes.rb: the concern's member routes add setup_accounts and complete_account_setup; resources :brex_items no longer needs a block.

Nothing user-visible changes.

Demo data

No demo data needed: no new records or UI.

Migration notes

No migration.

Verification

  • Existing tests unchanged: BrexItemsControllerTest and the other Brex tests pass unedited (212 runs, 0 failures). Two test files change:

    • the controller contract module;
    • ProviderItemCardsTest, the #3630 guard that every card render passes visible_accounts. It scans for card renders by literal partial name. Moving Brex's setup render into the shared controller turns "brex_items/brex_item" into "#{provider_key}_items/#{provider_key}_item", so the scan found 11 sites instead of its floor of 12. The guard now also matches the shared controller's form, as it already matches the generator template's, and is back to 12. Dropping visible_accounts: from the shared render is caught by it.
  • Contract (fail-first): ProviderItemsControllerTests

    • checks the two setup routes' paths and that they recognise as <key>_items#<action>;
    • adds them to the non-admin rejection test.

    Before the change both fail: the routes recognise as brex_items/account_setups, and that controller serves them. It also adds

    • "the setup page lists the connection's accounts that are not linked yet",
    • "completing setup links only this connection's accounts, with supported types and subtypes": in a Turbo frame, one account is linked with the supported type and not the invalid subtype; an account given an unsupported type and another connection's account stay unlinked; the connection's card is replaced.
  • Mutations:

    • Caught: setup not admin-gated; @brex_accounts not set; any subtype allowed; the card not refreshed after setup; the flow built without the connection.
    • Survive as equivalent: passing an unsupported type through, and allowing another connection's account ids. The flow repeats both checks (complete_setup! skips unsupported types and looks up only the connection's own accounts, covered in B2c), so the controller's are defence in depth.
  • bin/rails test (full, at the B3b commit): 16,276 runs, 1 failure, plus the same 8 ReleaseNotesWorkflowTest errors (no node in the test image). The failure was Settings::HostingsControllerTest "can update market data sync settings", a sidekiq-cron test that parallel workers race on through shared Redis. It is unrelated to this change, passed in the run before the guard fix, and passed 3 of 3 when re-run on its own.

  • bin/rubocop on changed files: no offenses. bin/brakeman: no warnings. No ERB or JS changed.

  • Diff with copy detection (git diff -C against B3a): non-test +110 / -122.

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

Blast radius

  • The setup page and the Turbo update read the same view, partial and locals as before (@brex_accounts, brex_item:, visible_accounts:).
  • Route helpers setup_accounts_brex_item_path and complete_account_setup_brex_item_path are unchanged.
  • Siblings: the other providers' controllers keep their own setup actions; they move in their own slices.