feat: add mock response for correspondents API and update document correspondent type

This commit is contained in:
Dominik Schröter 2025-01-13 15:50:08 +01:00
parent 91da6eff80
commit 127b501f0a

View file

@ -55,6 +55,12 @@ func newTestEnv(t *testing.T) *testEnv {
env.client = NewPaperlessClient(env.server.URL, "test-token") env.client = NewPaperlessClient(env.server.URL, "test-token")
env.client.HTTPClient = env.server.Client() 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 return env
} }
@ -176,7 +182,7 @@ func TestGetDocumentsByTags(t *testing.T) {
documentsResponse := GetDocumentsApiResponse{ documentsResponse := GetDocumentsApiResponse{
Results: []struct { Results: []struct {
ID int `json:"id"` ID int `json:"id"`
Correspondent interface{} `json:"correspondent"` Correspondent int `json:"correspondent"`
DocumentType interface{} `json:"document_type"` DocumentType interface{} `json:"document_type"`
StoragePath interface{} `json:"storage_path"` StoragePath interface{} `json:"storage_path"`
Title string `json:"title"` Title string `json:"title"`
@ -204,12 +210,14 @@ func TestGetDocumentsByTags(t *testing.T) {
Title: "Document 1", Title: "Document 1",
Content: "Content 1", Content: "Content 1",
Tags: []int{1, 2}, Tags: []int{1, 2},
Correspondent: 1,
}, },
{ {
ID: 2, ID: 2,
Title: "Document 2", Title: "Document 2",
Content: "Content 2", Content: "Content 2",
Tags: []int{2, 3}, Tags: []int{2, 3},
Correspondent: 2,
}, },
}, },
} }
@ -249,12 +257,14 @@ func TestGetDocumentsByTags(t *testing.T) {
Title: "Document 1", Title: "Document 1",
Content: "Content 1", Content: "Content 1",
Tags: []string{"tag1", "tag2"}, Tags: []string{"tag1", "tag2"},
Correspondent: "Alpha",
}, },
{ {
ID: 2, ID: 2,
Title: "Document 2", Title: "Document 2",
Content: "Content 2", Content: "Content 2",
Tags: []string{"tag2", "tag3"}, Tags: []string{"tag2", "tag3"},
Correspondent: "Beta",
}, },
} }
@ -413,7 +423,7 @@ func TestDownloadDocumentAsImages_ManyPages(t *testing.T) {
ID: 321, 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" pdfFile := "tests/pdf/many-pages.pdf"
pdfContent, err := os.ReadFile(pdfFile) pdfContent, err := os.ReadFile(pdfFile)
require.NoError(t, err) require.NoError(t, err)