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.
Part of jaysbeekay/sure#921. Upstream issue: we-promise/sure#5516.
Upstream draft PR: https://github.com/we-promise/sure/pull/5517 (same branch, same commit).
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.
we-promise/sure#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.