mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
fix(billing): usage warning states the actual share used, floored (DS-34 review)
This commit is contained in:
@@ -61,6 +61,19 @@ describe('sandbox hours copy', () => {
|
||||
expect(usageWarningLine(team({ usageWarningPercent: 100 }), t)).toBeNull()
|
||||
})
|
||||
|
||||
it('states the actual share used, floored, not the level that triggered it', () => {
|
||||
expect(usageWarningLine(team({ usedSeconds: 119 * HOUR, usageWarningPercent: 90 }), t)).toBe(
|
||||
'Your team has used 99% of this month’s sandbox hours.'
|
||||
)
|
||||
expect(usageWarningLine(team({ usedSeconds: 92 * HOUR, usageWarningPercent: 75 }), t)).toBe(
|
||||
'Your team has used 76% of this month’s sandbox hours.'
|
||||
)
|
||||
// Never "100%" while billing still reports hours left.
|
||||
expect(usageWarningLine(team({ usedSeconds: 119.9 * HOUR, usageWarningPercent: 90 }), t)).toBe(
|
||||
'Your team has used 99% of this month’s sandbox hours.'
|
||||
)
|
||||
})
|
||||
|
||||
it('turns the hours bar to the warning tone at 90%', () => {
|
||||
expect(includedUsageTone(team({ usedSeconds: 107 * HOUR }))).toBe('default')
|
||||
expect(includedUsageTone(team({ usedSeconds: 108 * HOUR }))).toBe('warning')
|
||||
|
||||
@@ -56,18 +56,32 @@ export function sandboxHoursOverLine(
|
||||
}
|
||||
|
||||
/**
|
||||
* The early warning at whichever level billing reports (75%, 90%) until the hours run out; at 100%
|
||||
* the bar, the hours-left line and the out-of-hours states say it instead.
|
||||
* The share of included hours actually used, floored, for the warning sentence: never below the
|
||||
* level billing reported (its count may be fresher) and never 100 while hours remain.
|
||||
*/
|
||||
export function usedPercentForWarning(entitlement: OrcaBillingEntitlement): number {
|
||||
const level = entitlement.usageWarningPercent ?? 0
|
||||
const used =
|
||||
entitlement.includedSeconds > 0
|
||||
? Math.floor((entitlement.usedSeconds / entitlement.includedSeconds) * 100)
|
||||
: level
|
||||
return Math.min(99, Math.max(level, used))
|
||||
}
|
||||
|
||||
/**
|
||||
* Shown once billing reports a warning level (75%, 90%) until the hours run out; the sentence states
|
||||
* the actual share used, not the level. At 100% the bar, the hours-left line and the out-of-hours
|
||||
* states say it instead.
|
||||
*/
|
||||
export function usageWarningLine(entitlement: OrcaBillingEntitlement, t: Translate): string | null {
|
||||
const percent = entitlement.usageWarningPercent
|
||||
if (percent === null || percent >= 100) {
|
||||
const level = entitlement.usageWarningPercent
|
||||
if (level === null || level >= 100) {
|
||||
return null
|
||||
}
|
||||
return t(
|
||||
'auto.components.billing.teamUsedPercent',
|
||||
'Your team has used {{percent}}% of this month’s sandbox hours.',
|
||||
{ percent: String(percent) }
|
||||
{ percent: String(usedPercentForWarning(entitlement)) }
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user