Adjust for unlimited plan option

This commit is contained in:
Jakub Syty
2026-08-26 13:58:31 +02:00
parent 0c847e25bd
commit 1459b4b360
5 changed files with 143 additions and 20 deletions
@@ -19,10 +19,10 @@ const payload = {
},
};
const mockResponse = () => ({
const mockResponse = (body = payload) => ({
ok: true,
status: 200,
json: async () => payload,
json: async () => body,
});
describe('GitHub Copilot quota provider', () => {
@@ -39,4 +39,40 @@ describe('GitHub Copilot quota provider', () => {
expect(result.usage.windows.premium_interactions.usedPercent).toBe(25);
expect(result.usage.windows.premium_interactions.valueLabel).toBe('225 / 300 left');
});
it.each([
['primary provider', fetchQuota],
['add-on provider', fetchQuotaAddon],
])('reports unlimited plans without a percent for the %s', async (_name, fetchProviderQuota) => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
quota_reset_date: '2026-09-01T00:00:00Z',
quota_snapshots: {
premium_interactions: { unlimited: true, entitlement: -1, remaining: -1 },
},
})));
const result = await fetchProviderQuota();
expect(result.ok).toBe(true);
expect(result.usage.windows.premium_interactions.usedPercent).toBeNull();
expect(result.usage.windows.premium_interactions.valueLabel).toBe('Unlimited');
});
it.each([
['primary provider', fetchQuota],
['add-on provider', fetchQuotaAddon],
])('falls back to percent_remaining when entitlement is unusable for the %s', async (_name, fetchProviderQuota) => {
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(mockResponse({
quota_reset_date: '2026-09-01T00:00:00Z',
quota_snapshots: {
premium_interactions: { entitlement: 0, remaining: 0, percent_remaining: 75.5 },
},
})));
const result = await fetchProviderQuota();
expect(result.ok).toBe(true);
expect(result.usage.windows.premium_interactions.usedPercent).toBeCloseTo(24.5);
expect(result.usage.windows.premium_interactions.valueLabel ?? null).toBeNull();
});
});