feat(sync): add Octokit retry/throttle and rate-limited status
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
|
||||
import { isRateLimitError } from '../../convex/githubClient';
|
||||
|
||||
describe('isRateLimitError', () => {
|
||||
test('detects a 403 primary rate limit via ratelimit-remaining header', () => {
|
||||
expect(
|
||||
isRateLimitError({
|
||||
status: 403,
|
||||
response: { headers: { 'x-ratelimit-remaining': '0' } },
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('detects a 429 status', () => {
|
||||
expect(isRateLimitError({ status: 429 })).toBe(true);
|
||||
});
|
||||
|
||||
test('detects a secondary rate limit via message', () => {
|
||||
expect(
|
||||
isRateLimitError({ status: 403, message: 'secondary rate limit' }),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
test('returns false for a 404', () => {
|
||||
expect(isRateLimitError({ status: 404 })).toBe(false);
|
||||
});
|
||||
|
||||
test('returns false for a 500', () => {
|
||||
expect(isRateLimitError({ status: 500 })).toBe(false);
|
||||
});
|
||||
|
||||
test('returns false for a generic Error', () => {
|
||||
expect(isRateLimitError(new Error('boom'))).toBe(false);
|
||||
});
|
||||
|
||||
test('returns false for non-object values', () => {
|
||||
expect(isRateLimitError(null)).toBe(false);
|
||||
expect(isRateLimitError(undefined)).toBe(false);
|
||||
expect(isRateLimitError('rate limit')).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user