test(filebrowser): align listDirectory tests with B4 content-type guard
The B4 fix made listDirectory require a JSON content-type (to detect the SPA-fallback HTML / 502 cases) and changed the non-OK error string, but its tests still mocked headerless responses + the old message, so they failed — which also polluted the run and tripped AppIconGrid's teardown. Give the JSON mock a content-type, update the non-OK expectation, and add a test for the guard's friendly-error path. Full suite now 667/667 green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
1278caa249
commit
b08e4c4268
@ -21,7 +21,9 @@ function jsonResponse(body: unknown, status = 200): Response {
|
|||||||
json: () => Promise.resolve(body),
|
json: () => Promise.resolve(body),
|
||||||
text: () => Promise.resolve(typeof body === 'string' ? body : JSON.stringify(body)),
|
text: () => Promise.resolve(typeof body === 'string' ? body : JSON.stringify(body)),
|
||||||
blob: () => Promise.resolve(new Blob([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,
|
redirected: false,
|
||||||
type: 'basic' as ResponseType,
|
type: 'basic' as ResponseType,
|
||||||
url: '',
|
url: '',
|
||||||
@ -119,7 +121,21 @@ describe('FileBrowserClient', () => {
|
|||||||
|
|
||||||
mockFetch.mockResolvedValueOnce(jsonResponse(null, 404))
|
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('<!doctype html><html></html>'),
|
||||||
|
headers: new Headers({ 'content-type': 'text/html' }),
|
||||||
|
} as Response
|
||||||
|
mockFetch.mockResolvedValueOnce(htmlResponse)
|
||||||
|
|
||||||
|
await expect(fileBrowserClient.listDirectory('/')).rejects.toThrow('File Browser is not available')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user