fix(update): recover from GitHub rate limits with configurable mirrors
This commit is contained in:
1 parent
68deb48811
commit
20cf7394e5
21 files changed
+1423
-93
No files matched your search
@@ -4,6 +4,30 @@ import { createApiClient } from '../src/lib/api/client';
|
||||
afterEach(() => vi.unstubAllGlobals());
|
||||
|
||||
describe('update API', () => {
|
||||
it('loads, tests and saves mirror selection through authenticated object endpoints', async () => {
|
||||
const config = { mode: 'auto', mirror: '', mirrors: ['https://example.com'] } as const;
|
||||
const payload = { ...config, mirrors: [...config.mirrors] };
|
||||
const fetchMock = vi.fn<typeof fetch>(async () =>
|
||||
Response.json({ config: payload, results: [] }),
|
||||
);
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const api = createApiClient({ tokenStore: { load: () => 'token', save: () => undefined } });
|
||||
await api.update.sources();
|
||||
await api.update.testSources(payload);
|
||||
await api.update.saveSources(payload);
|
||||
expect(fetchMock.mock.calls.map(([url]) => url)).toEqual([
|
||||
'/api/update/sources',
|
||||
'/api/update/sources/test',
|
||||
'/api/update/sources',
|
||||
]);
|
||||
|
||||
for (const [, options] of fetchMock.mock.calls) {
|
||||
expect(new Headers(options?.headers).get('X-SnowLuma-Token')).toBe('token');
|
||||
}
|
||||
|
||||
expect(fetchMock.mock.calls[1]?.[1]?.body).toBe(JSON.stringify(payload));
|
||||
expect(fetchMock.mock.calls[2]?.[1]?.method).toBe('POST');
|
||||
});
|
||||
it('sends authenticated download and restart requests', async () => {
|
||||
const fetchMock = vi.fn<typeof fetch>(async () =>
|
||||
Response.json({ current: '1.0.0', phase: 'ready', version: '2.0.0' }),
|
||||
|
||||
Reference in new issue
Block a user