mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-24 16:05:44 +08:00
feat(account): 支持测试连接 Chat Completions 路径
This commit is contained in:
@@ -513,6 +513,12 @@ const handleEvent = (event: {
|
||||
}
|
||||
break
|
||||
|
||||
case 'status':
|
||||
if (event.text) {
|
||||
addLine(event.text, 'text-cyan-300')
|
||||
}
|
||||
break
|
||||
|
||||
case 'image':
|
||||
if (event.image_url) {
|
||||
generatedImages.value.push({
|
||||
|
||||
@@ -147,4 +147,46 @@ describe('AccountTestModal', () => {
|
||||
mode: 'compact'
|
||||
})
|
||||
})
|
||||
|
||||
it('renders Chat Completions path status from test SSE', async () => {
|
||||
const encoder = new TextEncoder()
|
||||
const chunks = [
|
||||
encoder.encode('data: {"type":"status","text":"已通过 /v1/chat/completions 验证"}\n\n'),
|
||||
encoder.encode('data: {"type":"test_complete","success":true}\n\n')
|
||||
]
|
||||
global.fetch = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
body: {
|
||||
getReader: () => ({
|
||||
read: vi.fn().mockImplementation(() => Promise.resolve(
|
||||
chunks.length > 0
|
||||
? { done: false, value: chunks.shift() }
|
||||
: { done: true, value: undefined }
|
||||
))
|
||||
})
|
||||
}
|
||||
} as any)
|
||||
|
||||
const wrapper = mount(AccountTestModal, {
|
||||
props: {
|
||||
show: true,
|
||||
account: buildAccount()
|
||||
},
|
||||
global: {
|
||||
stubs: {
|
||||
BaseDialog: BaseDialogStub,
|
||||
Select: SelectStub,
|
||||
TextArea: TextAreaStub,
|
||||
Icon: true
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
await flushPromises()
|
||||
;(wrapper.vm as any).selectedModelId = 'gpt-5.4'
|
||||
await (wrapper.vm as any).startTest()
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.text()).toContain('已通过 /v1/chat/completions 验证')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user