From 127b501f0a2843183bbdd432a88e02eacbcd4a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Schr=C3=B6ter?= Date: Mon, 13 Jan 2025 15:50:08 +0100 Subject: [PATCH] feat: add mock response for correspondents API and update document correspondent type --- paperless_test.go | 46 ++++++++++++++++++++++++++++------------------ 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/paperless_test.go b/paperless_test.go index e6a215a..30b10a0 100644 --- a/paperless_test.go +++ b/paperless_test.go @@ -55,6 +55,12 @@ func newTestEnv(t *testing.T) *testEnv { env.client = NewPaperlessClient(env.server.URL, "test-token") env.client.HTTPClient = env.server.Client() + // Add mock response for /api/correspondents/ + env.setMockResponse("/api/correspondents/", func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Write([]byte(`{"results": [{"id": 1, "name": "Alpha"}, {"id": 2, "name": "Beta"}]}`)) + }) + return env } @@ -176,7 +182,7 @@ func TestGetDocumentsByTags(t *testing.T) { documentsResponse := GetDocumentsApiResponse{ Results: []struct { ID int `json:"id"` - Correspondent interface{} `json:"correspondent"` + Correspondent int `json:"correspondent"` DocumentType interface{} `json:"document_type"` StoragePath interface{} `json:"storage_path"` Title string `json:"title"` @@ -200,16 +206,18 @@ func TestGetDocumentsByTags(t *testing.T) { } `json:"__search_hit__"` }{ { - ID: 1, - Title: "Document 1", - Content: "Content 1", - Tags: []int{1, 2}, + ID: 1, + Title: "Document 1", + Content: "Content 1", + Tags: []int{1, 2}, + Correspondent: 1, }, { - ID: 2, - Title: "Document 2", - Content: "Content 2", - Tags: []int{2, 3}, + ID: 2, + Title: "Document 2", + Content: "Content 2", + Tags: []int{2, 3}, + Correspondent: 2, }, }, } @@ -245,16 +253,18 @@ func TestGetDocumentsByTags(t *testing.T) { expectedDocuments := []Document{ { - ID: 1, - Title: "Document 1", - Content: "Content 1", - Tags: []string{"tag1", "tag2"}, + ID: 1, + Title: "Document 1", + Content: "Content 1", + Tags: []string{"tag1", "tag2"}, + Correspondent: "Alpha", }, { - ID: 2, - Title: "Document 2", - Content: "Content 2", - Tags: []string{"tag2", "tag3"}, + ID: 2, + Title: "Document 2", + Content: "Content 2", + Tags: []string{"tag2", "tag3"}, + Correspondent: "Beta", }, } @@ -413,7 +423,7 @@ func TestDownloadDocumentAsImages_ManyPages(t *testing.T) { ID: 321, } - // Get sample PDF from tests/pdf/sample.pdf + // Get sample PDF from tests/pdf/many-pages.pdf pdfFile := "tests/pdf/many-pages.pdf" pdfContent, err := os.ReadFile(pdfFile) require.NoError(t, err)