// ingestion/internal/api/ingestpath_docmark_test.go package api_test import ( "bytes" "encoding/json" "net/http" "net/http/httptest" "os" "path/filepath" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) func TestIngestPath_DocxUnsupportedWhenDocmarkNotConfigured(t *testing.T) { t.Setenv("DOCMARK_URL", "") _, h := setup(t) dir := t.TempDir() f := filepath.Join(dir, "doc.docx") require.NoError(t, os.WriteFile(f, []byte("fake docx"), 0o644)) body, _ := json.Marshal(map[string]any{"path": f, "source": "test-doc", "dry_run": true}) req := httptest.NewRequest(http.MethodPost, "/ingest-path", bytes.NewReader(body)) rec := httptest.NewRecorder() h.IngestPath(rec, req) assert.Equal(t, http.StatusBadRequest, rec.Code, rec.Body.String()) } func TestIngestPath_DocxSupportedWhenDocmarkConfigured(t *testing.T) { srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") _, _ = w.Write([]byte(`{"jsonrpc":"2.0","id":1,"result":{"content":[{"type":"text","text":"# Converted Doc"}]}}`)) })) defer srv.Close() t.Setenv("DOCMARK_URL", srv.URL+"/mcp") t.Setenv("DOCMARK_BEARER_TOKEN", "tok") _, h := setup(t) dir := t.TempDir() f := filepath.Join(dir, "doc.docx") require.NoError(t, os.WriteFile(f, []byte("fake docx"), 0o644)) body, _ := json.Marshal(map[string]any{"path": f, "source": "test-doc", "dry_run": true}) req := httptest.NewRequest(http.MethodPost, "/ingest-path", bytes.NewReader(body)) rec := httptest.NewRecorder() h.IngestPath(rec, req) require.Equal(t, http.StatusOK, rec.Code, rec.Body.String()) var resp map[string]any require.NoError(t, json.Unmarshal(rec.Body.Bytes(), &resp)) pages, ok := resp["pages"].([]any) require.True(t, ok) assert.NotEmpty(t, pages) }