Broadcast Brex, Questrade and Sharesight sync completion

JA
6d ago
+101-2

Summary

Brex, Questrade and Sharesight syncs raised NameError in post-sync because none of them defines a SyncCompleteEvent. Each now has one.

Closes #5516.

Fork pre-flight: jaysbeekay/sure#944 (same branch, same commit). Fork issue: jaysbeekay/sure#921.

What changed

Syncable#sync_broadcaster builds self.class::SyncCompleteEvent. BrexItem, QuestradeItem and SharesightItem define none. All three are synced, by Family::Syncer and by their controllers' sync_later, so every sync that reached post-sync raised NameError. Sync#perform_post_sync rescued it and reported it to Sentry, and the linked accounts and the family were never broadcast.

Each provider now has a SyncCompleteEvent in the existing per-provider shape (Plaid, SimpleFIN, Lunch Flow): it broadcasts each linked account, then the family. SharesightItem#accounts is a method over its portfolios rather than an association, and returns the same linked accounts.

Left out:

  • FinancekitItem has no SyncCompleteEvent either but never reaches post-sync. Its syncable scope is none, it has no Syncer, nothing calls sync_later on it, and Financekit::Processor creates its Sync rows already completed.
  • The per-provider shape sends the family toast more than once per sync, because Account::SyncCompleteEvent sends it too. These classes match their siblings; that is a separate question.

Verification

All in test/models/provider_item_sync_complete_events_test.rb:

  • One parameterised end-to-end case for Brex, Questrade and Sharesight. It links two accounts and runs a completed Sync#perform, then asserts that nothing reaches Sentry, the family stream gets the sync toast and not the card, each linked account gets its own refresh, and another account gets nothing. Each failed before the fix with Expected: [] Actual: ["NameError"].
  • brex_item and questrade_item join PROVIDERS. sharesight_item has no fixtures, so it joins the providers the test builds. Each failed with NameError: uninitialized constant <Item>::SyncCompleteEvent.
  • Mutations, each caught, on each of the three classes:
    • the body loops over family.accounts;
    • no family broadcast;
    • no account broadcast;
    • only the first account broadcast (accounts.first(1).each).
  • bin/rails test (full, at cd8242250): 18144 runs, 0 failures (8 ReleaseNotesWorkflowTest environment errors). rubocop clean.

#4188 also edits this test file. There is no text conflict, but if it merges first, the new case needs its perform_enqueued_jobs(only: FamilySyncToastJob) wrapping.

Migration notes

No migration.


Summary by cubic

Fixes Brex, Questrade, and Sharesight syncs raising NameError in post-sync, so linked accounts and families are now broadcast when these syncs complete.

  • Adds a SyncCompleteEvent per provider in the existing per-provider shape: broadcast each linked account, then the family.
  • Adds a test per provider that links two accounts, runs a completed sync, and verifies no Sentry report, each linked account gets its own refresh, family toast (not the card), and nothing broadcast to unrelated accounts. All three raised NameError before.
  • Leaves out FinancekitItem: it never reaches post-sync because its Sync rows are created already completed.
  • Keeps the existing double family toast per sync (the account-level event also sends it), matching sibling providers.

Summary by CodeRabbit

  • New Features
    • Sync completion updates are now available for Brex, Questrade, and Sharesight connections.
    • When syncing finishes, linked accounts are refreshed and the associated family receives a completion notification.
    • Accounts not linked to the provider connection do not receive these updates.