Broadcast Brex, Questrade and Sharesight sync completion
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:
FinancekitItemhas noSyncCompleteEventeither but never reaches post-sync. Itssyncablescope isnone, it has noSyncer, nothing callssync_lateron it, andFinancekit::Processorcreates itsSyncrows already completed.- The per-provider shape sends the family toast more than once per sync, because
Account::SyncCompleteEventsends 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 ownrefresh, and another account gets nothing. Each failed before the fix withExpected: [] Actual: ["NameError"]. brex_itemandquestrade_itemjoinPROVIDERS.sharesight_itemhas no fixtures, so it joins the providers the test builds. Each failed withNameError: 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).
- the body loops over
bin/rails test(full, at cd8242250): 18144 runs, 0 failures (8ReleaseNotesWorkflowTestenvironment 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
SyncCompleteEventper 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
NameErrorbefore. - Leaves out
FinancekitItem: it never reaches post-sync because itsSyncrows 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.