Build image / build-and-push (push) Successful in 6s
Co-authored-by: Steve Dudenhoeffer <[email protected]>
34 lines
1.3 KiB
Go
34 lines
1.3 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
// TestAgentRoutesAbsentWithoutAKey — an instance with no API key must start,
|
|
// serve the app, and simply not offer the assistant. The routes aren't
|
|
// registered at all, so this is a 404 rather than a handler that apologizes:
|
|
// the same shape as OIDC when unconfigured.
|
|
func TestAgentRoutesAbsentWithoutAKey(t *testing.T) {
|
|
r := authEngine(t, localCfg()) // localCfg has no agent configuration
|
|
cookie := registerAndCookie(t, r, "[email protected]")
|
|
gid := createGardenAPI(t, r, cookie, "G")
|
|
|
|
w := doJSON(t, r, http.MethodPost, "/api/v1/agent/chat",
|
|
map[string]any{"gardenId": gid, "message": "plant garlic"}, cookie)
|
|
if w.Code != http.StatusNotFound {
|
|
t.Errorf("chat without a key: status %d, want 404", w.Code)
|
|
}
|
|
|
|
path := "/api/v1/gardens/" + strconv.FormatInt(gid, 10) + "/agent/history"
|
|
if w := doJSON(t, r, http.MethodGet, path, nil, cookie); w.Code != http.StatusNotFound {
|
|
t.Errorf("history without a key: status %d, want 404", w.Code)
|
|
}
|
|
|
|
// And the rest of the app is entirely unaffected.
|
|
if w := doJSON(t, r, http.MethodGet, fullPath(gid), nil, cookie); w.Code != http.StatusOK {
|
|
t.Errorf("editor load: status %d, want 200 — an unconfigured agent must not break the app", w.Code)
|
|
}
|
|
}
|