Adjust for unlimited plan option
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user