Skip to content

[PM-16456] Enhance PreviewOrganizationTaxCommand to support Teams Starter 2023#8000

Open
JaredScar wants to merge 1 commit into
mainfrom
ac/pm-16456-add-occupied-seat-count-chek-when-restoring-user
Open

[PM-16456] Enhance PreviewOrganizationTaxCommand to support Teams Starter 2023#8000
JaredScar wants to merge 1 commit into
mainfrom
ac/pm-16456-add-occupied-seat-count-chek-when-restoring-user

Conversation

@JaredScar

Copy link
Copy Markdown
Contributor

🎟️ Tracking

📔 Objective

Fixes issue where showing the upgrade plan modal to a Teams Starter 2023 plan errors out...

📸 Screenshots

BEFORE
image

NOW
image

…ogging for subscription discrepancies. Added a logger for better traceability and refined quantity determination logic for password manager plans.
@JaredScar JaredScar requested a review from a team as a code owner July 16, 2026 20:53
@JaredScar JaredScar requested a review from connerbw July 16, 2026 20:53
@JaredScar JaredScar added ai-review Request a Claude code review t:bugfix Change Type - Bugfix labels Jul 16, 2026
@github-actions

github-actions Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

🤖 Bitwarden Claude Code Review

Overall Assessment: APPROVE

Reviewed the change to PreviewOrganizationTaxCommand that fixes the crash when previewing an upgrade from a flat-rate plan (Teams Starter 2023) to a seat-based plan. The fix correctly restructures the quantity resolution so the subscription line-item lookup only runs when it is actually needed, and replaces an unguarded dictionary indexer (which threw KeyNotFoundException) with a TryGetValue guard that returns a clean BadRequest and logs a non-sensitive diagnostic. The added private _logger field is appropriate since BaseBillingCommand does not expose its logger to subclasses. Logic and branching are correct.

Code Review Details
  • ❓ : Bugfix and new BadRequest path lack unit test coverage; no existing plan-change test uses a non-seat-based current plan
    • src/Core/Billing/Organizations/Commands/PreviewOrganizationTaxCommand.cs:238

Comment on lines +238 to +263
if (currentPlan.HasNonSeatBasedPasswordManagerPlan() && !newPlan.HasNonSeatBasedPasswordManagerPlan())
{
// The current plan doesn't have a per-seat subscription item to read a quantity from
// (e.g. upgrading from a flat-rate plan like Teams Starter), so fall back to the
// organization's occupied seat count instead of looking it up on the subscription.
quantity = (long)organization.Seats!;
}
else
{
var passwordManagerPriceId = currentPlan.HasNonSeatBasedPasswordManagerPlan()
? currentPlan.PasswordManager.StripePlanId
: currentPlan.PasswordManager.StripeSeatPlanId];
: currentPlan.PasswordManager.StripeSeatPlanId;

var quantity = currentPlan.HasNonSeatBasedPasswordManagerPlan() &&
!newPlan.HasNonSeatBasedPasswordManagerPlan()
? (long)organization.Seats!
: passwordManagerSeats.Quantity;
if (!subscriptionItemsByPriceId.TryGetValue(passwordManagerPriceId, out var passwordManagerSeats))
{
_logger.LogError(
"Organization {OrganizationId}'s subscription {SubscriptionId} does not contain a " +
"Password Manager line item matching its current plan's price {PriceId}",
organization.Id, organization.GatewaySubscriptionId, passwordManagerPriceId);

return new BadRequest(
"Your organization's subscription does not match its current plan. Please contact support for assistance.");
}

quantity = passwordManagerSeats.Quantity;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

QUESTION: This bugfix (and the new BadRequest path) has no accompanying unit test.

Details

The existing Subscription Plan Change tests in PreviewOrganizationTaxCommandTests.cs only exercise current plans of Free, Families, Teams, and Enterprise — none of which are non-seat-based (HasNonSeatBasedPasswordManagerPlan()). The Teams Starter 2023 → seat-based upgrade path introduced here, and the new missing-line-item BadRequest return, are both untested.

Per the repo convention (.claude/CLAUDE.md: "ALWAYS add unit tests"), consider adding:

  1. A regression test upgrading from a non-seat-based plan (e.g. PlanType.TeamsStarter2023) that asserts quantity == organization.Seats.
  2. A test where the current plan's price is absent from subscription.Items, asserting the BadRequest result.

This locks in the fix and prevents regression of the original crash.

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 74.07407% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 62.23%. Comparing base (3e79593) to head (e40406e).

Files with missing lines Patch % Lines
...izations/Commands/PreviewOrganizationTaxCommand.cs 74.07% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8000      +/-   ##
==========================================
- Coverage   62.23%   62.23%   -0.01%     
==========================================
  Files        2287     2287              
  Lines       99663    99683      +20     
  Branches     9004     9004              
==========================================
+ Hits        62023    62035      +12     
- Misses      35469    35477       +8     
  Partials     2171     2171              

☔ View full report in Codecov by Harness.
📢 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request a Claude code review t:bugfix Change Type - Bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant