Files
lzt404 100f5df737 Revert "feat(quota): unify OAuth and API balance lookup (#279)"
This reverts commit d473c8b8f186e82eb63e15d7a3bc54f05810b087.
2026-09-20 18:09:32 +08:00

39 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'bun:test';
import {
captureQuotaCacheGeneration,
commitQuotaCacheIfCurrent,
getQuotaCacheSnapshot,
pruneQuotaCache,
updateQuotaCache,
} from '../src/services/quotaCache';
describe('额度跨页面缓存', () => {
it('保留仍存在的认证文件额度并清理失效项', () => {
updateQuotaCache({
first: { status: 'success', rows: [], fetchedAt: 1 },
removed: { status: 'error', rows: [], error: 'old' },
});
pruneQuotaCache(new Set(['first']));
expect(getQuotaCacheSnapshot()).toEqual({
first: { status: 'success', rows: [], fetchedAt: 1 },
});
});
it('认证文件集合变化后拒绝过期请求写回', () => {
updateQuotaCache({
stale: { status: 'loading', rows: [] },
retained: { status: 'loading', rows: [] },
});
const generation = captureQuotaCacheGeneration();
pruneQuotaCache(new Set(['retained']));
let committed = false;
expect(commitQuotaCacheIfCurrent(generation, () => {
committed = true;
})).toBe(false);
expect(committed).toBe(false);
expect(getQuotaCacheSnapshot().retained).toEqual({ status: 'idle', rows: [] });
});
});