feat: initialize external DobotAI agent gateway
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"gitea.zheromiku.top/Weknora/dobotai-platform/internal/core"
|
||||
)
|
||||
|
||||
type fakeQA struct{}
|
||||
|
||||
func (fakeQA) Ask(context.Context, core.QARequest) (core.QAResult, error) {
|
||||
return core.QAResult{TurnID: "turn-1", Answer: "answer"}, nil
|
||||
}
|
||||
|
||||
func TestQAEndpointRequiresTokenAndReturnsResult(t *testing.T) {
|
||||
server, err := New(fakeQA{}, "ingress-secret")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
body := `{"tenant_key":"tenant","channel":"dingtalk","conversation_type":"direct","external_user_id":"user","external_message_id":"message","query":"hello"}`
|
||||
unauthorized := httptest.NewRequest(http.MethodPost, "/v1/qa", strings.NewReader(body))
|
||||
unauthorizedResult := httptest.NewRecorder()
|
||||
server.Handler().ServeHTTP(unauthorizedResult, unauthorized)
|
||||
if unauthorizedResult.Code != http.StatusUnauthorized {
|
||||
t.Fatalf("unauthorized status=%d", unauthorizedResult.Code)
|
||||
}
|
||||
authorized := httptest.NewRequest(http.MethodPost, "/v1/qa", strings.NewReader(body))
|
||||
authorized.Header.Set("Authorization", "Bearer ingress-secret")
|
||||
result := httptest.NewRecorder()
|
||||
server.Handler().ServeHTTP(result, authorized)
|
||||
if result.Code != http.StatusOK || !strings.Contains(result.Body.String(), `"turn_id":"turn-1"`) {
|
||||
t.Fatalf("status=%d body=%s", result.Code, result.Body.String())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user