* Map a Pro (or legacy) plan to a Team tier, choosing the smallest Team tier * whose credit allowance is at least the current plan's so an upgrade never * silently drops credits. Returns `null` when no eligible Team tier exists * (e.g. a Max owner when the Team Max price is unconfigured) so the c
(plan: string)
| 238 | * surface `upgrade-required` instead of downgrading. |
| 239 | */ |
| 240 | function mapToTeamPlanName(plan: string): string | null { |
| 241 | if (isTeam(plan)) return plan |
| 242 | |
| 243 | const credits = getPlanTierCredits(plan) |
| 244 | const eligibleTiers = [...CREDIT_TIERS] |
| 245 | .filter((tier) => tier.credits >= credits) |
| 246 | .sort((a, b) => a.credits - b.credits) |
| 247 | |
| 248 | for (const tier of eligibleTiers) { |
| 249 | const candidate = buildPlanName('team', tier.credits) |
| 250 | if (getPlanByName(candidate)) { |
| 251 | return candidate |
| 252 | } |
| 253 | } |
| 254 | return null |
| 255 | } |
no test coverage detected