Skip to content

feat(analytics): add unit tests for trackClientEvent and assert all S…#162

Merged
lfariabr merged 2 commits intomasterfrom
feat/stripe-analytics-152
Mar 13, 2026
Merged

feat(analytics): add unit tests for trackClientEvent and assert all S…#162
lfariabr merged 2 commits intomasterfrom
feat/stripe-analytics-152

Conversation

@lfariabr
Copy link
Owner

@lfariabr lfariabr commented Mar 13, 2026

…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

Summary by CodeRabbit

  • New Features

    • Added Stripe Payments as a payment integration option.
  • Documentation

    • Updated architecture diagram, tech stack integrations, and changelog (v2.9 knowledge upgrade; v3.1 Stripe Payments); noted Resend as deprecated.
  • Tests

    • Added/expanded tests for analytics tracking and checkout flows (including Stripe selection analytics); adjusted test descriptions for clarity.

…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
@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 04298f5b-29b4-4efa-a9eb-52ad4d21e578

📥 Commits

Reviewing files that changed from the base of the PR and between 676760b and 4722949.

📒 Files selected for processing (1)
  • README.md

Walkthrough

Docs 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

Cohort / File(s) Summary
Documentation
README.md
Added Stripe to integrations, architecture diagram, tech stack; added v3.1 "Stripe Payments" changelog entry and noted Resend deprecation.
Stripe Tests
frontend/src/__tests__/components/Stripe.test.tsx, frontend/src/__tests__/lib/hooks/useStripeCheckout.test.tsx
Added analytics assertion for stripe_item_selected with productKey: "meeting" in Stripe FAB flow; renamed a test description to stripe_checkout_error.
Analytics Tests
frontend/src/__tests__/utils/analytics.test.ts
New unit tests for trackClientEvent: covers window.gtag path, console.log fallback when gtag missing, default empty payload, and swallowing gtag exceptions.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

Tests sharpen knives, Stripe enters the ring,
Analytics checked — no flaky thing.
Console falls back when gtag trips,
Errors swallowed, no limp blips.
Ship payments clean; no weak-code swings.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: adding unit tests for trackClientEvent with analytics assertions, which is the core of this PR.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/stripe-analytics-152
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
frontend/src/__tests__/utils/analytics.test.ts (1)

6-10: Consider a typed window extension to avoid any casts.

Look, I get it — wrestling with window.gtag in TypeScript is like trying to put pants on a cat. But we've got any scattered across these tests like confetti at a bad party. Per coding guidelines, we should avoid any types.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7f86a99 and 676760b.

📒 Files selected for processing (4)
  • README.md
  • frontend/src/__tests__/components/Stripe.test.tsx
  • frontend/src/__tests__/lib/hooks/useStripeCheckout.test.tsx
  • frontend/src/__tests__/utils/analytics.test.ts

@lfariabr lfariabr merged commit f472287 into master Mar 13, 2026
8 checks passed
@lfariabr lfariabr deleted the feat/stripe-analytics-152 branch March 13, 2026 17:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant