Download desktop/src/api/sessions.test.ts from chenbhao/codev: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/chenbhao/codev/resolve/e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/api/sessions.test.ts
- Command line
-
hf download hf://chenbhao/codev@e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/api/sessions.test.ts
-
curl -L -o sessions.test.ts https://huggingface.co/chenbhao/codev/resolve/e40073cc959cd4729bf4009662bca374c5c4e266/desktop/src/api/sessions.test.ts
1.29 kB
| import { afterEach, describe, expect, it, vi } from 'vitest' | |
| import { setBaseUrl } from './client' | |
| import { sessionsApi } from './sessions' | |
| describe('sessionsApi', () => { | |
| afterEach(() => { | |
| setBaseUrl('http://127.0.0.1:3456') | |
| vi.restoreAllMocks() | |
| }) | |
| it('posts branch requests to the session branch endpoint', async () => { | |
| const fetchMock = vi.spyOn(globalThis, 'fetch') | |
| fetchMock.mockResolvedValueOnce(new Response(JSON.stringify({ | |
| sessionId: 'branch-session', | |
| title: 'Branch', | |
| workDir: '/workspace/repo', | |
| sourceSessionId: 'source-session', | |
| targetMessageId: 'message-1', | |
| }), { | |
| status: 201, | |
| headers: { 'Content-Type': 'application/json' }, | |
| })) | |
| setBaseUrl('http://127.0.0.1:49237') | |
| const result = await sessionsApi.branch('source-session', { | |
| targetMessageId: 'message-1', | |
| title: 'Branch', | |
| }) | |
| expect(result.sessionId).toBe('branch-session') | |
| expect(fetchMock).toHaveBeenCalledOnce() | |
| const [url, init] = fetchMock.mock.calls[0]! | |
| expect(url).toBe('http://127.0.0.1:49237/api/sessions/source-session/branch') | |
| expect(init).toMatchObject({ | |
| method: 'POST', | |
| body: JSON.stringify({ | |
| targetMessageId: 'message-1', | |
| title: 'Branch', | |
| }), | |
| }) | |
| }) | |
| }) | |