Files
hermes-web-ui/tests/client/conversations-api.test.ts
Zhicheng Han 3f88553765 feat(web-ui): add pinned sessions and live monitor in Chat (#118)
* feat: add single-page live session monitor and chat pinning

* fix: restore full test green after main merge

* fix: use Array.from instead of Set spread for ts-node compatibility

[...new Set()] requires downlevelIteration which isn't enabled in
ts-node dev mode, causing sonic-boom crash on startup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: ekko <fqsy1416@gmail.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-22 08:09:58 +08:00

40 lines
1.5 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
const mockRequest = vi.hoisted(() => vi.fn())
vi.mock('@/api/client', () => ({
request: mockRequest,
}))
import { fetchConversationDetail, fetchConversationSummaries } from '@/api/hermes/conversations'
describe('conversations api', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('builds summaries URLs with optional params', async () => {
mockRequest.mockResolvedValue({ sessions: [] })
await fetchConversationSummaries()
await fetchConversationSummaries({ humanOnly: false, source: 'cli', limit: 25 })
expect(mockRequest).toHaveBeenNthCalledWith(1, '/api/hermes/sessions/conversations')
expect(mockRequest).toHaveBeenNthCalledWith(2, '/api/hermes/sessions/conversations?humanOnly=false&source=cli&limit=25')
})
it('encodes detail URLs and forwards optional params', async () => {
mockRequest.mockResolvedValue({ session_id: 'conv', messages: [], visible_count: 0, thread_session_count: 1 })
await fetchConversationDetail('folder/with spaces', { humanOnly: false, source: 'discord' })
expect(mockRequest).toHaveBeenCalledWith('/api/hermes/sessions/conversations/folder%2Fwith%20spaces/messages?humanOnly=false&source=discord')
})
it('propagates conversation detail errors so the monitor can render an error state', async () => {
mockRequest.mockRejectedValue(new Error('boom'))
await expect(fetchConversationDetail('conv-1', { humanOnly: true })).rejects.toThrow('boom')
})
})