Skip to content

Commit 2120e08

Browse files
committed
test(mobile): pin the API bypass at a root mount, where /api/ is inside the scope
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jQhk3S1XeTLgXSkEMt
1 parent 163cfd1 commit 2120e08

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

‎ui/packages/mobile/src/__tests__/serviceWorkerSource.test.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { describe, it, expect, vi } from 'vitest';
1616
import { getServiceWorkerSource, SERVICE_WORKER_CACHE_URLS_MESSAGE } from '../serviceWorkerSource';
1717

1818
const ORIGIN = 'https://app.test';
19-
const SCOPE = `${ORIGIN}/_console/`;
19+
const CONSOLE_SCOPE = `${ORIGIN}/_console/`;
20+
let SCOPE = CONSOLE_SCOPE;
2021

2122
type Listener = (event: any) => void;
2223
type NetworkAnswer = (url: string) => Response | Promise<Response>;
@@ -239,6 +240,20 @@ describe("'app-shell' worker — the API bypass rule", () => {
239240
expect(sw.store.size).toBe(0);
240241
});
241242

243+
it('bypasses the API prefix on its own, at a root mount where /api/ is inside the scope', async () => {
244+
SCOPE = `${ORIGIN}/`;
245+
try {
246+
const sw = bootWorker(appShell('b1'));
247+
for (const mode of ['cors', 'navigate']) {
248+
expect((await sw.fetch(`${ORIGIN}/api/v1/data/account`, { mode })).answered, `mode ${mode}`).toBe(false);
249+
}
250+
// The control: a file under the same root mount is answered.
251+
expect((await sw.fetch(`${ORIGIN}/favicon.svg`)).answered).toBe(true);
252+
} finally {
253+
SCOPE = CONSOLE_SCOPE;
254+
}
255+
});
256+
242257
it('honours a custom API prefix', async () => {
243258
const sw = bootWorker(appShell('b1', { apiPrefix: '/_console/rpc/' }));
244259
expect((await sw.fetch(`${SCOPE}rpc/call`)).answered).toBe(false);

0 commit comments

Comments
 (0)