This commit is contained in:
@@ -53,3 +53,39 @@ func TestValidateContractAcceptsVersionPrefixedOpenAPIPaths(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverAndListKnowledgeBase(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
switch r.URL.Path {
|
||||
case "/api.php/token":
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"access_token": "x", "expires_in": 3600})
|
||||
case "/api.php/doc.json":
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"paths": map[string]any{
|
||||
"/v2.3/Knowledge/KnowbaseItem": map[string]any{"get": map[string]any{}},
|
||||
}})
|
||||
case "/api.php/v2.3/Knowledge/KnowbaseItem":
|
||||
_ = json.NewEncoder(w).Encode([]map[string]any{{
|
||||
"id": 7, "name": "Konto gesperrt", "answer": "<p>Konto entsperren</p>", "date_mod": "2026-07-27 10:00:00",
|
||||
"categories": []any{map[string]any{"id": 4}},
|
||||
}})
|
||||
default:
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}))
|
||||
defer srv.Close()
|
||||
c := New(srv.URL, "v2.3", "cid", "sec", "u", "p", time.Second)
|
||||
path, err := c.DiscoverKnowledgeBasePath(context.Background(), "auto")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if path != "/Knowledge/KnowbaseItem" {
|
||||
t.Fatalf("path=%q", path)
|
||||
}
|
||||
items, err := c.ListKnowledgeBaseItems(context.Background(), path, 50, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(items) != 1 || items[0].ID != 7 || len(items[0].CategoryIDs) != 1 || items[0].CategoryIDs[0] != 4 {
|
||||
t.Fatalf("unexpected items: %+v", items)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user