Files
q107580018 db8f5f4c00 feat: support agent attachment send-back (#180)
* feat: support agent attachment send-back

* fix: allow default attachment_send in validation
2026-03-18 07:57:40 +08:00

41 lines
1.0 KiB
Go

package core
import (
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
)
func TestHandleSend_AllowsAttachmentOnly(t *testing.T) {
engine := NewEngine("test", &stubAgent{}, []Platform{&stubMediaPlatform{stubPlatformEngine: stubPlatformEngine{n: "test"}}}, "", LangEnglish)
engine.interactiveStates["session-1"] = &interactiveState{
platform: &stubMediaPlatform{stubPlatformEngine: stubPlatformEngine{n: "test"}},
replyCtx: "reply-ctx",
}
api := &APIServer{engines: map[string]*Engine{"test": engine}}
reqBody := SendRequest{
Project: "test",
SessionKey: "session-1",
Images: []ImageAttachment{{
MimeType: "image/png",
Data: []byte("img"),
FileName: "chart.png",
}},
}
body, err := json.Marshal(reqBody)
if err != nil {
t.Fatalf("marshal request: %v", err)
}
req := httptest.NewRequest(http.MethodPost, "/send", bytes.NewReader(body))
rec := httptest.NewRecorder()
api.handleSend(rec, req)
if rec.Code != http.StatusOK {
t.Fatalf("status = %d, body=%s", rec.Code, rec.Body.String())
}
}