Skip to content

test(billing): decouple subscriptions component test from tenant plan IDs#4191

Merged
PierreBrisorgueil merged 1 commit into
masterfrom
fix/billing-subs-test-decouple
May 21, 2026
Merged

test(billing): decouple subscriptions component test from tenant plan IDs#4191
PierreBrisorgueil merged 1 commit into
masterfrom
fix/billing-subs-test-decouple

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Collaborator

@PierreBrisorgueil PierreBrisorgueil commented May 21, 2026

Summary

Closes #4189

  • Add vi.mock('../lib/billing.resolveStaticContent.js', ...) returning generic plan IDs (p1, p2, p3) to decouple the subscriptions component test from tenant-specific plan IDs (e.g. starter)
  • Update one test fixture to use the generic p2 plan instead of the hardcoded starter plan ID

Why

The billing subscriptions component test was relying on tenant-specific plan IDs that live in resolved static content. When the plan IDs change (e.g. new pricing tiers, GTM plan rename), tests break for non-structural reasons. This mock makes the test fixture-agnostic and aligned with the billing module's own test isolation pattern.

Test plan

  • All 82/82 billing component tests pass locally (npm run test:unit)
  • No coverage thresholds changed
  • No production code touched — test file only

Summary by CodeRabbit

  • Tests
    • Improved test reliability for subscription functionality by updating test fixtures to ensure consistent behavior across different scenarios.

Review Change Stack

… IDs

Closes #4189. Mock resolveStaticContent with generic p1/p2/p3 plan IDs so the
'Change Plan' upgrade CTA assertion no longer depends on tenant content
('starter' on devkit master, 'free/growth/pro' on Trawl downstream).

Unblocks dropping the trawl_vue local override (PR #922 patch).
Copilot AI review requested due to automatic review settings May 21, 2026 17:19
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 21, 2026

Walkthrough

This PR mocks the billing.resolveStaticContent module to return generic plan IDs (p1, p2, p3) in the subscriptions test suite and updates the paid plan upgrade CTA test to use p2 instead of the tenant-specific starter plan ID, decoupling the test from downstream-specific plan configurations.

Changes

Subscription test tenant decoupling

Layer / File(s) Summary
Mock resolveStaticContent and align test plan references
src/modules/billing/tests/billing.subscriptions.component.unit.tests.js
Vitest mock added for billing.resolveStaticContent.js to return deterministic generic plans (p1, p2, p3), and the "paid plan upgrade CTA as Change Plan" test updated to use plan: 'p2' instead of 'starter' so the test aligns with the mocked content and remains tenant-agnostic.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • pierreb-devkit/Vue#4166: This PR makes billing subscriptions consume the new resolveStaticContent()-provided static content, which this test update directly corresponds to by mocking that same module.
  • pierreb-devkit/Vue#4127: Both PRs modify billing.subscriptions.component.unit.tests.js to align plan ID and assertion expectations in the subscriptions component's CTA and plan card rendering behavior.

Suggested labels

billing

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: decoupling a test from tenant-specific plan IDs through mocking.
Description check ✅ Passed The description covers all essential sections: Summary with specific changes and issue link, Why (addressing test brittleness), and Test plan with verification results.
Linked Issues check ✅ Passed The PR fully implements all coding requirements from issue #4189: mocks resolveStaticContent with generic plan IDs (p1/p2/p3), updates the upgrade CTA test to use p2, and eliminates tenant-specific plan ID coupling.
Out of Scope Changes check ✅ Passed All changes are scoped to decoupling the test file from tenant plan IDs as required; no production code modified and no unrelated changes present.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/billing-subs-test-decouple

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
Copy Markdown

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/modules/billing/tests/billing.subscriptions.component.unit.tests.js (1)

397-410: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use mocked highest plan ID in the “highest plan” CTA test.

This suite now mocks plans as p1/p2/p3, but the highest-plan test still uses plan: 'pro'. That can make the assertion pass via an unknown-plan path instead of true highest-plan behavior.

Suggested fix
-  it('hides the paid plan upgrade CTA on the highest plan', async () => {
-    store.subscription = { status: 'active', plan: 'pro', currentPeriodEnd: new Date().toISOString() };
+  it('hides the paid plan upgrade CTA on the highest plan', async () => {
+    store.subscription = { status: 'active', plan: 'p3', currentPeriodEnd: new Date().toISOString() };
     wrapper = mountSubscriptions({ serverConfig: { billing: { meterMode: false } } });
     await flushPromises();
     expect(wrapper.text()).not.toContain('Change Plan');
   });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/modules/billing/tests/billing.subscriptions.component.unit.tests.js`
around lines 397 - 410, The "hides the paid plan upgrade CTA on the highest
plan" test uses a hardcoded plan 'pro' which doesn't match the mocked plans
(p1/p2/p3); update the test to set store.subscription.plan to the mocked highest
plan (e.g., 'p3') so the code path for the actual highest plan is exercised,
leaving the rest of the test (mountSubscriptions call and assertions) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/modules/billing/tests/billing.subscriptions.component.unit.tests.js`:
- Around line 397-410: The "hides the paid plan upgrade CTA on the highest plan"
test uses a hardcoded plan 'pro' which doesn't match the mocked plans
(p1/p2/p3); update the test to set store.subscription.plan to the mocked highest
plan (e.g., 'p3') so the code path for the actual highest plan is exercised,
leaving the rest of the test (mountSubscriptions call and assertions) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 09857790-7907-4dc5-89d9-17c1a91d3217

📥 Commits

Reviewing files that changed from the base of the PR and between 45bf131 and b53790e.

📒 Files selected for processing (1)
  • src/modules/billing/tests/billing.subscriptions.component.unit.tests.js

@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.56%. Comparing base (45bf131) to head (b53790e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4191   +/-   ##
=======================================
  Coverage   99.56%   99.56%           
=======================================
  Files          31       31           
  Lines        1140     1140           
  Branches      329      329           
=======================================
  Hits         1135     1135           
  Misses          5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PierreBrisorgueil PierreBrisorgueil merged commit 6477873 into master May 21, 2026
7 of 8 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the billing subscriptions component unit tests to avoid coupling assertions to tenant-specific billing plan IDs by mocking resolveStaticContent() with generic plan identifiers.

Changes:

  • Added a vi.mock('../lib/billing.resolveStaticContent.js', ...) in the subscriptions component test to provide stable, generic plan IDs (p1, p2, p3).
  • Updated the “Change Plan” CTA test fixture to use a generic plan ID (p2) instead of a tenant-specific one (starter).


vi.mock('../lib/billing.resolveStaticContent.js', () => ({
resolveStaticContent: () => ({
plans: [{ id: 'p1' }, { id: 'p2' }, { id: 'p3' }],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

billing.subscriptions test: decouple from tenant plan IDs (resolveStaticContent mock)

2 participants