Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

1.0 KB
Raw Blame
import type { BillingAlertConfig } from 'lib/logic/billing/billingLogic'

import { TodayRailSeverity, severityFromBillingAlert, worstSeverity } from './todayRailSeverity'

describe('todayRailSeverity', () => {
    test.each<[string, BillingAlertConfig | null, TodayRailSeverity]>([
        ['no alert', null, 'none'],
        ['usage limit reached', { kind: 'usage_limit', status: 'error', title: '' }, 'critical'],
        ['usage limit approaching', { kind: 'usage_limit', status: 'info', title: '' }, 'warning'],
        ['trial ending', { kind: 'trial', status: 'info', title: '' }, 'none'],
    ])('rates a billing alert for %s', (_name, alert, expected) => {
        expect(severityFromBillingAlert(alert)).toEqual(expected)
    })

    test.each<[TodayRailSeverity[], TodayRailSeverity]>([
        [['ok', 'warning'], 'warning'],
        [['critical', 'notice'], 'critical'],
        [['none', 'notice'], 'notice'],
    ])('picks the worst of %j', (severities, expected) => {
        expect(worstSeverity(...severities)).toEqual(expected)
    })
})