Broadcast Brex, Questrade and Sharesight sync completion

JA
4d 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.

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:

  • 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.

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.