lint
This commit is contained in:
977 files changed
+198426
-158324
No files matched your search
@@ -2,49 +2,56 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { createApiClient } from '../src/lib/api/client';
|
||||
|
||||
const tokenStore = {
|
||||
load: () => 'trace-token',
|
||||
save: () => undefined,
|
||||
load: () => 'trace-token',
|
||||
save: () => undefined,
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
vi.unstubAllGlobals();
|
||||
});
|
||||
|
||||
describe('API client full TRACE export', () => {
|
||||
it('downloads the exact authenticated server text and filename', async () => {
|
||||
const body = 'header\nTRACE recvHex=000102aabbcc\n';
|
||||
const fetchMock = vi.fn().mockResolvedValue(new Response(body, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
'Content-Disposition': 'attachment; filename="server-trace.log"',
|
||||
},
|
||||
}));
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const client = createApiClient({ tokenStore });
|
||||
it('downloads the exact authenticated server text and filename', async () => {
|
||||
const body = 'header\nTRACE recvHex=000102aabbcc\n';
|
||||
const fetchMock = vi.fn().mockResolvedValue(
|
||||
new Response(body, {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'text/plain; charset=utf-8',
|
||||
'Content-Disposition': 'attachment; filename="server-trace.log"',
|
||||
},
|
||||
}),
|
||||
);
|
||||
vi.stubGlobal('fetch', fetchMock);
|
||||
const client = createApiClient({ tokenStore });
|
||||
|
||||
await expect(client.logs.exportTrace()).resolves.toEqual({
|
||||
text: body,
|
||||
filename: 'server-trace.log',
|
||||
await expect(client.logs.exportTrace()).resolves.toEqual({
|
||||
text: body,
|
||||
filename: 'server-trace.log',
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledExactlyOnceWith(
|
||||
'/api/logs/export/trace',
|
||||
expect.objectContaining({
|
||||
headers: { Authorization: 'Bearer trace-token' },
|
||||
}),
|
||||
);
|
||||
});
|
||||
expect(fetchMock).toHaveBeenCalledExactlyOnceWith(
|
||||
'/api/logs/export/trace',
|
||||
expect.objectContaining({
|
||||
headers: { Authorization: 'Bearer trace-token' },
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('rejects a failed export instead of downloading an error body', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn().mockResolvedValue(new Response(
|
||||
JSON.stringify({ message: 'export unavailable' }),
|
||||
{ status: 500, statusText: 'Internal Server Error' },
|
||||
)));
|
||||
const client = createApiClient({ tokenStore });
|
||||
it('rejects a failed export instead of downloading an error body', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn().mockResolvedValue(
|
||||
new Response(JSON.stringify({ message: 'export unavailable' }), {
|
||||
status: 500,
|
||||
statusText: 'Internal Server Error',
|
||||
}),
|
||||
),
|
||||
);
|
||||
const client = createApiClient({ tokenStore });
|
||||
|
||||
await expect(client.logs.exportTrace()).rejects.toMatchObject({
|
||||
status: 500,
|
||||
message: 'export unavailable',
|
||||
await expect(client.logs.exportTrace()).rejects.toMatchObject({
|
||||
status: 500,
|
||||
message: 'export unavailable',
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user