feat(analytics): add unit tests for trackClientEvent and assert all S…#162
feat(analytics): add unit tests for trackClientEvent and assert all S…#162
Conversation
…tripe events (#152) - Add analytics.test.ts: covers gtag present, console fallback, error swallowing - Assert stripe_item_selected for meeting product in Stripe.test.tsx - Rename test: 'tracks checkout_error' → 'tracks stripe_checkout_error event on failure' - Update README: add v3.1 Stripe Payments to features table, Stripe to integrations
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughDocs and tests updated to add Stripe payments: README includes Stripe in integrations, architecture, and changelog; frontend tests add analytics assertions for Stripe checkout and new unit tests for trackClientEvent fallback and error-safety. (48 words) Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
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)
frontend/src/__tests__/utils/analytics.test.ts (1)
6-10: Consider a typed window extension to avoidanycasts.Look, I get it — wrestling with
window.gtagin TypeScript is like trying to put pants on a cat. But we've gotanyscattered across these tests like confetti at a bad party. Per coding guidelines, we should avoidanytypes.You could define a typed interface once and reuse it:
🔧 Optional: Type-safe window extension
import { trackClientEvent } from '@/utils/analytics'; +interface WindowWithGtag extends Window { + gtag?: (...args: unknown[]) => void; +} + describe('trackClientEvent', () => { let consoleSpy: jest.SpyInstance; beforeEach(() => { consoleSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); // Start each test with no gtag - delete (window as any).gtag; + delete (window as unknown as WindowWithGtag).gtag; });Then use
(window as unknown as WindowWithGtag).gtag = gtag;in subsequent assignments.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@frontend/src/__tests__/utils/analytics.test.ts` around lines 6 - 10, Add a small test-only typed window extension to avoid any casts: define an interface (e.g. WindowWithGtag { gtag?: typeof gtag }) in the test file or a shared test-utils file, then replace all uses of (window as any).gtag with casts to that interface like (window as unknown as WindowWithGtag).gtag (including in the beforeEach delete line and any assignments) and update related tests to use the new WindowWithGtag type instead of any.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@frontend/src/__tests__/utils/analytics.test.ts`:
- Around line 6-10: Add a small test-only typed window extension to avoid any
casts: define an interface (e.g. WindowWithGtag { gtag?: typeof gtag }) in the
test file or a shared test-utils file, then replace all uses of (window as
any).gtag with casts to that interface like (window as unknown as
WindowWithGtag).gtag (including in the beforeEach delete line and any
assignments) and update related tests to use the new WindowWithGtag type instead
of any.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f865cb90-1669-47f1-8359-48a1154f6360
📒 Files selected for processing (4)
README.mdfrontend/src/__tests__/components/Stripe.test.tsxfrontend/src/__tests__/lib/hooks/useStripeCheckout.test.tsxfrontend/src/__tests__/utils/analytics.test.ts
…tripe events (#152)
Summary by CodeRabbit
New Features
Documentation
Tests