落地 synastry/star/ask API 与 H5 页面,补齐 cece-frontend-re complete-design 证据文档,并加入 Android 模拟器截图抓取脚本。 Co-authored-by: Cursor <cursoragent@cursor.com>
48 lines
1.2 KiB
Go
48 lines
1.2 KiB
Go
package deepseek
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/config"
|
|
)
|
|
|
|
func TestChat_success(t *testing.T) {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Header.Get("Authorization") != "Bearer test-key" {
|
|
t.Fatalf("auth header: %s", r.Header.Get("Authorization"))
|
|
}
|
|
var req chatRequest
|
|
_ = json.NewDecoder(r.Body).Decode(&req)
|
|
if req.Model != "deepseek-chat" {
|
|
t.Fatalf("model=%s", req.Model)
|
|
}
|
|
_ = json.NewEncoder(w).Encode(chatResponse{
|
|
Choices: []struct {
|
|
Message Message `json:"message"`
|
|
}{{Message: Message{Role: "assistant", Content: "你好,我是成长助手"}}},
|
|
})
|
|
}))
|
|
defer srv.Close()
|
|
|
|
c := New(config.DeepSeekConfig{
|
|
APIKey: "test-key", BaseURL: srv.URL, Model: "deepseek-chat", TimeoutSec: 5,
|
|
})
|
|
out, err := c.Chat(context.Background(), []Message{{Role: "user", Content: "hi"}})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if out != "你好,我是成长助手" {
|
|
t.Fatalf("got %q", out)
|
|
}
|
|
}
|
|
|
|
func TestEnabled(t *testing.T) {
|
|
if New(config.DeepSeekConfig{}).Enabled() {
|
|
t.Fatal("empty key should disable")
|
|
}
|
|
}
|