Invalidation of queries#718
Conversation
📝 WalkthroughWalkthroughAdds an exported utility to optimistically update a user's full-account React Query cache and updates two permission-management components to use that utility on success; also adds unit tests for the new cache-update behavior. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/web/src/specs/api/update-account-keys-cache.spec.ts (1)
6-11: Use the realgetAccountFullQueryOptionswith partial mocking to avoid queryKey drift.The mock hardcodes
queryKey: ["accounts", "full", username], but the SDK'sQueryKeys.accounts.full(username)actually returns["get-account-full", username]. ImportgetAccountFullQueryOptionsfrom@ecency/sdkand usevi.spyOn()to mock only thequeryFn, ensuring the queryKey matches the real SDK and adheres to usingQueryKeysas the single source of truth.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/web/src/specs/api/update-account-keys-cache.spec.ts` around lines 6 - 11, The current mock replaces getAccountFullQueryOptions entirely and hardcodes a queryKey that drifts from the SDK; instead import getAccountFullQueryOptions from "@ecency/sdk" and use vi.spyOn(getAccountFullQueryOptionsModule, "getAccountFullQueryOptions") or vi.spyOn(`@ecency/sdk`, "getAccountFullQueryOptions") to call through and only replace the returned queryFn (e.g., spyOn(...).mockImplementationOnce(opts => ({ ...opts, queryFn: vi.fn() }))) so the real queryKey (produced by QueryKeys.accounts.full(username) / getAccountFullQueryOptions) is preserved and tests remain aligned with the SDK.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/web/src/specs/api/update-account-keys-cache.spec.ts`:
- Around line 6-11: The current mock replaces getAccountFullQueryOptions
entirely and hardcodes a queryKey that drifts from the SDK; instead import
getAccountFullQueryOptions from "@ecency/sdk" and use
vi.spyOn(getAccountFullQueryOptionsModule, "getAccountFullQueryOptions") or
vi.spyOn(`@ecency/sdk`, "getAccountFullQueryOptions") to call through and only
replace the returned queryFn (e.g., spyOn(...).mockImplementationOnce(opts => ({
...opts, queryFn: vi.fn() }))) so the real queryKey (produced by
QueryKeys.accounts.full(username) / getAccountFullQueryOptions) is preserved and
tests remain aligned with the SDK.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 9f389f38-1975-44ba-b646-506b1f9442e7
📒 Files selected for processing (4)
apps/web/src/api/mutations/update-account-keys-cache.tsapps/web/src/app/(dynamicPages)/profile/[username]/permissions/_components/add-keys-steps/step-4-confirm.tsxapps/web/src/app/(dynamicPages)/profile/[username]/permissions/_components/manage-keys-dialog.tsxapps/web/src/specs/api/update-account-keys-cache.spec.ts
Summary by CodeRabbit