mirror of
https://github.com/icereed/paperless-gpt.git
synced 2025-03-14 05:38:01 -05:00
feat: add mock response for correspondents API and update document correspondent type
This commit is contained in:
parent
91da6eff80
commit
127b501f0a
1 changed files with 28 additions and 18 deletions
|
@ -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"`
|
||||||
|
@ -200,16 +206,18 @@ func TestGetDocumentsByTags(t *testing.T) {
|
||||||
} `json:"__search_hit__"`
|
} `json:"__search_hit__"`
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
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,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -245,16 +253,18 @@ func TestGetDocumentsByTags(t *testing.T) {
|
||||||
|
|
||||||
expectedDocuments := []Document{
|
expectedDocuments := []Document{
|
||||||
{
|
{
|
||||||
ID: 1,
|
ID: 1,
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue