fix(webapp): billing alert preview uses current limit instead of stale saved amount
After a customer raised their billing limit, the alert-threshold percentage preview kept calculating dollar amounts against the previous limit until they re-saved their alerts. This happened because the preview reused the alert record's snapshotted amount whenever saved percentage levels existed. The preview now returns the snapshot only when it still matches the current effective/plan limit, and otherwise falls back to the current effective limit, so the preview reflects the saved billing limit immediately. Adds a regression test covering the raised-limit scenario. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01TywtuVBcXSNVTV6nJbgLk8
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
area: webapp
|
||||
type: fix
|
||||
---
|
||||
|
||||
Raising your billing limit now updates the alert threshold preview amounts right away, instead of showing figures based on the previous limit until you save your alerts again.
|
||||
@@ -315,9 +315,6 @@ export function getAlertPreviewLimitCents(
|
||||
planLimitCents: number
|
||||
): number {
|
||||
const amountCents = getSavedAlertAmountCents(alerts);
|
||||
if (amountCents > 0 && percentageAlertLevelsToUiThresholds(alerts.alertLevels).length > 0) {
|
||||
return amountCents;
|
||||
}
|
||||
if (percentageAlertAmountMatches(amountCents, effectiveLimitCents, planLimitCents)) {
|
||||
return amountCents;
|
||||
}
|
||||
|
||||
@@ -90,6 +90,18 @@ describe("billingAlertsFormat", () => {
|
||||
).toBe(10_000);
|
||||
});
|
||||
|
||||
it("previews percentage alerts against the current limit after it is raised", () => {
|
||||
// Alerts were saved against an old $30 limit; the customer has since raised
|
||||
// it to $300. The preview should follow the current limit, not the snapshot.
|
||||
expect(
|
||||
getAlertPreviewLimitCents(
|
||||
{ amount: 30, emails: [], alertLevels: [0.75, 0.9] },
|
||||
30_000,
|
||||
10_000
|
||||
)
|
||||
).toBe(30_000);
|
||||
});
|
||||
|
||||
it("normalizes legacy API alerts with dollar amount field and whole percents", () => {
|
||||
expect(
|
||||
normalizeBillingAlertsFromApi(
|
||||
|
||||
Reference in New Issue
Block a user