diff --git a/neode-ui/src/api/__tests__/filebrowser-client.test.ts b/neode-ui/src/api/__tests__/filebrowser-client.test.ts index c220fa51..f7d6a318 100644 --- a/neode-ui/src/api/__tests__/filebrowser-client.test.ts +++ b/neode-ui/src/api/__tests__/filebrowser-client.test.ts @@ -21,7 +21,9 @@ function jsonResponse(body: unknown, status = 200): Response { json: () => Promise.resolve(body), text: () => Promise.resolve(typeof body === 'string' ? body : JSON.stringify(body)), blob: () => Promise.resolve(new Blob([JSON.stringify(body)])), - headers: new Headers(), + // A real File Browser JSON response carries this; listDirectory now guards + // on it (B4) to detect the SPA-fallback HTML / 502 cases. + headers: new Headers({ 'content-type': 'application/json' }), redirected: false, type: 'basic' as ResponseType, url: '', @@ -119,7 +121,21 @@ describe('FileBrowserClient', () => { mockFetch.mockResolvedValueOnce(jsonResponse(null, 404)) - await expect(fileBrowserClient.listDirectory('/missing')).rejects.toThrow('Failed to list directory: 404') + await expect(fileBrowserClient.listDirectory('/missing')).rejects.toThrow('File Browser is not available (HTTP 404)') + }) + + it('throws a friendly error when File Browser is absent and nginx serves the SPA (B4)', async () => { + setAuthenticated() + + // 200 but text/html (SPA index.html fallback) — res.json() would throw the + // opaque "Unexpected token '<'"; the guard must surface a friendly message. + const htmlResponse = { + ...jsonResponse(''), + headers: new Headers({ 'content-type': 'text/html' }), + } as Response + mockFetch.mockResolvedValueOnce(htmlResponse) + + await expect(fileBrowserClient.listDirectory('/')).rejects.toThrow('File Browser is not available') }) })