Files
DocsGPT/frontend/src/conversation/quotaError.test.ts
T
Alex 1c9c94eba7 feat(frontend): admin quota management, a usage meter and the quota chat error
The admin dashboard gets a Quotas tab for the instance default, team
allowances and user overrides, with a notice listing models that cost
limits cannot see. A Quota action on the Users tab shows a user's effective
limits, the layer each comes from and their usage, next to the editor for
their override. Each budget is either not set at that layer, a limit, or
unlimited.

Users with a quota see a usage meter with the reset time on the Analytics
settings page, and a refused chat request shows the used amount, the limit
and the reset time in the user's language.
2026-09-21 12:11:12 +01:00

53 lines
1.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { isQuotaError, quotaErrorMessage } from './quotaError';
const t = ((key: string, values: Record<string, string>) =>
`${key}|${values.used}|${values.limit}|${values.resetsAt}`) as any;
describe('isQuotaError', () => {
it('matches only the quota error code', () => {
expect(isQuotaError({ error_code: 'quota-exceeded' })).toBe(true);
expect(isQuotaError({ message: 'Exceeding usage limit' })).toBe(false);
expect(isQuotaError(null)).toBe(false);
expect(isQuotaError('quota-exceeded')).toBe(false);
});
});
describe('quotaErrorMessage', () => {
it('formats token budgets as numbers', () => {
const message = quotaErrorMessage(
{
dimension: 'tokens',
usage: 1200000,
limit: 1000000,
resets_at: '2026-10-01T00:00:00+00:00',
},
t,
'en-US',
);
const [key, used, limit, resetsAt] = message.split('|');
expect(key).toBe('conversation.quotaExceeded.tokens');
expect([used, limit]).toEqual(['1,200,000', '1,000,000']);
expect(resetsAt).not.toBe('');
});
it('formats cost budgets as dollars', () => {
const message = quotaErrorMessage(
{ dimension: 'cost', usage: 5.25, limit: 5 },
t,
'en-US',
);
expect(message).toBe('conversation.quotaExceeded.cost|$5.25|$5.00|');
});
it('tolerates a malformed reset time', () => {
const message = quotaErrorMessage(
{ dimension: 'tokens', usage: 1, limit: 1, resets_at: 'soon' },
t,
'en-US',
);
expect(message.endsWith('|')).toBe(true);
});
});