fix(design): bound requests and prevent mutation replay
This commit is contained in:
@@ -35,6 +35,36 @@ describe('proxyAwareFetch', () => {
|
||||
expect(net.fetch).toHaveBeenCalledWith('https://example.test', undefined);
|
||||
});
|
||||
|
||||
it('does not replay a mutation through global fetch after Electron net.fetch fails', async () => {
|
||||
setElectronVersion('43.4.0');
|
||||
const transportError = new Error('response transport failed');
|
||||
const fetchMock = vi.fn();
|
||||
vi.mocked(net.fetch).mockRejectedValue(transportError);
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await expect(proxyAwareFetch('https://example.test/quote', {
|
||||
method: 'PATCH',
|
||||
body: JSON.stringify({ aspect_ratio: '16:9' }),
|
||||
})).rejects.toBe(transportError);
|
||||
|
||||
expect(net.fetch).toHaveBeenCalledOnce();
|
||||
expect(fetchMock).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('retains the global fallback for safe reads after Electron net.fetch fails', async () => {
|
||||
setElectronVersion('43.4.0');
|
||||
const response = new Response('node fallback');
|
||||
const fetchMock = vi.fn().mockResolvedValue(response);
|
||||
vi.mocked(net.fetch).mockRejectedValue(new Error('electron transport failed'));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
|
||||
await expect(proxyAwareFetch('https://example.test/read', {
|
||||
method: 'GET',
|
||||
})).resolves.toBe(response);
|
||||
|
||||
expect(fetchMock).toHaveBeenCalledWith('https://example.test/read', { method: 'GET' });
|
||||
});
|
||||
|
||||
it('uses the global fetch outside Electron', async () => {
|
||||
setElectronVersion(undefined);
|
||||
const response = new Response('node');
|
||||
|
||||
Reference in New Issue
Block a user