fix(kimi): reorder usage summary in buildKimiQuotaRows function

This commit is contained in:
Supra4E8C
2026-07-25 00:52:21 +08:00
parent 3738c0b7ff
commit 3447a0bd58
2 changed files with 40 additions and 10 deletions
+10 -10
View File
@@ -223,16 +223,6 @@ function toKimiUsageRow(
export function buildKimiQuotaRows(payload: KimiUsagePayload): KimiQuotaRow[] {
const rows: KimiQuotaRow[] = [];
const usage = payload.usage;
if (usage && typeof usage === 'object') {
const summary = toKimiUsageRow(usage as Record<string, unknown>, {
labelKey: 'kimi_quota.weekly_limit',
});
if (summary) {
rows.push({ id: 'summary', ...summary });
}
}
const limits = payload.limits;
if (Array.isArray(limits)) {
limits.forEach((item, idx) => {
@@ -250,6 +240,16 @@ export function buildKimiQuotaRows(payload: KimiUsagePayload): KimiQuotaRow[] {
});
}
const usage = payload.usage;
if (usage && typeof usage === 'object') {
const summary = toKimiUsageRow(usage as Record<string, unknown>, {
labelKey: 'kimi_quota.weekly_limit',
});
if (summary) {
rows.push({ id: 'summary', ...summary });
}
}
return rows;
}
+30
View File
@@ -0,0 +1,30 @@
import { describe, expect, test } from 'bun:test';
import { buildKimiQuotaRows } from '@/utils/quota';
describe('Kimi quota ordering', () => {
test('shows the 5-hour limit before the weekly limit', () => {
const rows = buildKimiQuotaRows({
usage: {
used: 200,
limit: 1000,
},
limits: [
{
detail: {
used: 20,
limit: 100,
},
window: {
duration: 300,
timeUnit: 'MINUTES',
},
},
],
});
expect(rows.map(({ id }) => id)).toEqual(['limit-0', 'summary']);
expect(rows[0]?.labelKey).toBe('kimi_quota.limit_window');
expect(rows[0]?.labelParams).toEqual({ duration: '5h' });
expect(rows[1]?.labelKey).toBe('kimi_quota.weekly_limit');
});
});