* feat: support agent attachment send-back * fix: allow default attachment_send in validation
41 lines
1.0 KiB
Go
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())
|
|
}
|
|
}
|