fix: align claude-console test auth with relay logic

This commit is contained in:
Jiahao Luo
2026-03-01 23:28:10 +08:00
parent f77a76ce1d
commit b8c38adf70
3 changed files with 49 additions and 7 deletions

View File

@@ -32,7 +32,7 @@ describe('claudeConsoleRelayService.testAccountConnection', () => {
jest.clearAllMocks()
})
it('passes selected model stream payload to sendStreamTestRequest', async () => {
it('passes selected model stream payload and bearer auth for non sk-ant key', async () => {
claudeConsoleAccountService.getAccount.mockResolvedValue({
name: 'Console A1',
apiUrl: 'https://console.example.com',
@@ -55,8 +55,42 @@ describe('claudeConsoleRelayService.testAccountConnection', () => {
expect(createClaudeTestPayload).toHaveBeenCalledWith('claude-sonnet-4-6', { stream: true })
expect(sendStreamTestRequest).toHaveBeenCalledWith(
expect.objectContaining({
payload
payload,
authorization: 'Bearer test-key'
})
)
})
it('passes selected model stream payload and x-api-key for sk-ant key', async () => {
claudeConsoleAccountService.getAccount.mockResolvedValue({
name: 'Console A1',
apiUrl: 'https://console.example.com',
apiKey: 'sk-ant-test-key',
proxy: null,
userAgent: null
})
claudeConsoleAccountService._createProxyAgent.mockReturnValue(undefined)
const payload = {
model: 'claude-sonnet-4-6',
stream: true
}
createClaudeTestPayload.mockReturnValue(payload)
sendStreamTestRequest.mockResolvedValue(undefined)
const res = {}
await claudeConsoleRelayService.testAccountConnection('a1', res, 'claude-sonnet-4-6')
expect(createClaudeTestPayload).toHaveBeenCalledWith('claude-sonnet-4-6', { stream: true })
const requestOptions = sendStreamTestRequest.mock.calls[0][0]
expect(requestOptions).toEqual(
expect.objectContaining({
payload,
extraHeaders: expect.objectContaining({
'x-api-key': 'sk-ant-test-key'
})
})
)
expect(requestOptions).not.toHaveProperty('authorization')
})
})