feat(api): align provider creation with presets/custom/google sdk

This commit is contained in:
zenfun
2025-12-17 22:19:17 +08:00
parent 174735f152
commit 2b0ed3d3d5
5 changed files with 214 additions and 10 deletions

View File

@@ -39,8 +39,8 @@ func TestCreateProviderPreset_OpenAI_SetsBaseURL(t *testing.T) {
if got.Type != "openai" {
t.Fatalf("expected type openai, got %q", got.Type)
}
if got.BaseURL != "https://api.openai.com" {
t.Fatalf("expected base_url=https://api.openai.com, got %q", got.BaseURL)
if got.BaseURL != "https://api.openai.com/v1" {
t.Fatalf("expected base_url=https://api.openai.com/v1, got %q", got.BaseURL)
}
if got.Name == "" {
t.Fatalf("expected generated name")
@@ -68,3 +68,25 @@ func TestCreateProviderCustom_RequiresBaseURL(t *testing.T) {
t.Fatalf("expected 400, got %d body=%s", rr.Code, rr.Body.String())
}
}
func TestCreateProviderGoogle_GeminiRequiresAPIKey(t *testing.T) {
h, _ := newTestHandler(t)
r := gin.New()
r.POST("/admin/providers/google", h.CreateProviderGoogle)
reqBody := map[string]any{
"type": "gemini",
"models": []string{"gemini-2.0-flash"},
}
b, _ := json.Marshal(reqBody)
req := httptest.NewRequest(http.MethodPost, "/admin/providers/google", bytes.NewReader(b))
req.Header.Set("Content-Type", "application/json")
rr := httptest.NewRecorder()
r.ServeHTTP(rr, req)
if rr.Code != http.StatusBadRequest {
t.Fatalf("expected 400, got %d body=%s", rr.Code, rr.Body.String())
}
}