package tools_test import ( "context" "encoding/json" "io" "net/http" "net/http/httptest" "testing" "gitea.d-ma.be/mathias/gitea-mcp/internal/allowlist" "gitea.d-ma.be/mathias/gitea-mcp/internal/gitea" "gitea.d-ma.be/mathias/gitea-mcp/internal/tools" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestIssueReopenTool(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { assert.Equal(t, http.MethodPatch, r.Method) assert.Equal(t, "/api/v1/repos/mathias/infra/issues/26", r.URL.Path) b, _ := io.ReadAll(r.Body) assert.JSONEq(t, `{"state":"open"}`, string(b)) w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(`{"number":26,"title":"feat: ntfy via NPM","state":"open","html_url":"http://gitea.example.com/mathias/infra/issues/26"}`)) })) defer srv.Close() tool := tools.NewIssueReopen(gitea.NewClient(srv.URL, "tok"), allowlist.New([]string{"mathias"})) out, err := tool.Call(context.Background(), json.RawMessage(`{"owner":"mathias","name":"infra","number":26}`)) require.NoError(t, err) assert.Contains(t, string(out), `"number":26`) assert.Contains(t, string(out), `"state":"open"`) } func TestIssueReopenAllowlistRejects(t *testing.T) { tool := tools.NewIssueReopen(gitea.NewClient("http://unused", ""), allowlist.New([]string{"mathias"})) _, err := tool.Call(context.Background(), json.RawMessage(`{"owner":"evil","name":"x","number":1}`)) require.Error(t, err) }