CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (pull_request) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (pull_request) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (pull_request) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Canceled after 0s
CI / Web (dms-browser) (push) Canceled after 0s
CI / Web (pdf-viewer) (push) Canceled after 0s
CI / Web (shl) (push) Canceled after 0s
Supply-Chain-Scan (Go) / govulncheck (push) Canceled after 0s
Supply-Chain-Scan (npm) / npm-audit (push) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (pull_request) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (pull_request) Canceled after 0s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (pull_request) Canceled after 0s
CI / Web (dms-browser) (pull_request) Canceled after 0s
CI / Web (pdf-viewer) (pull_request) Canceled after 0s
CI / Web (shl) (pull_request) Canceled after 0s
Core-Schnittstellen-Vertragstests / contract-tests (pull_request) Canceled after 0s
Supply-Chain-Scan (npm) / npm-audit (pull_request) Canceled after 0s
Core-Pflichttest-Gate / pflichttest-gate (pull_request) Canceled after 0s
RBAC-Rollenhierarchie-Pflichtgate / rbac-policy-invariant (pull_request) Canceled after 0s
Import-Assistent fuer paperless-ngx-Exporte (dieses Projekts primaeres Referenzsystem): Parser, Feld-Mapping-Vorschlag ueber ENG-04s fieldmapping.Store, Umwandlung in DMS2-01-Bundles, Import-Lauf mit Erfolgs-/Fehleranzahl. Mapping-Vorschau-Oberflaeche (Next.js/shl). Echte Funde dabei behoben: fieldmapping.FieldDef hatte keine JSON-Tags (serialisierte als NexarchField/Required statt nexarch_field/required, API-Antwort damit fuer das Frontend unbrauchbar); die neuen BFF-Routen lieferten ohne cache:no-store eine veraltete Antwort aus Next.js' Fetch-Cache aus. 4/4 Akzeptanzkriterien erfuellt, alle 4 Prüfungen real durchgefuehrt inkl. echtem Chrome/Puppeteer-Ende-zu-Ende-Test (Mapping im Browser geaendert, Import mit geaenderter Zuordnung erfolgreich ausgefuehrt). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
130 lines
3.8 KiB
Go
130 lines
3.8 KiB
Go
package dms2import
|
|
|
|
import (
|
|
"archive/zip"
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
// buildFixtureZip renders a minimal but structurally real paperless-ngx
|
|
// exporter archive: manifest.json with correspondent/type/tag/document
|
|
// records plus one original file, exactly the shape ParsePaperlessExport
|
|
// expects.
|
|
func buildFixtureZip(t *testing.T, manifest string, originalName string, originalContent []byte) []byte {
|
|
t.Helper()
|
|
var buf bytes.Buffer
|
|
zw := zip.NewWriter(&buf)
|
|
|
|
mw, err := zw.Create("manifest.json")
|
|
if err != nil {
|
|
t.Fatalf("create manifest.json: %v", err)
|
|
}
|
|
if _, err := mw.Write([]byte(manifest)); err != nil {
|
|
t.Fatalf("write manifest.json: %v", err)
|
|
}
|
|
|
|
if originalName != "" {
|
|
ow, err := zw.Create("documents/originals/" + originalName)
|
|
if err != nil {
|
|
t.Fatalf("create original: %v", err)
|
|
}
|
|
if _, err := ow.Write(originalContent); err != nil {
|
|
t.Fatalf("write original: %v", err)
|
|
}
|
|
}
|
|
|
|
if err := zw.Close(); err != nil {
|
|
t.Fatalf("close zip: %v", err)
|
|
}
|
|
return buf.Bytes()
|
|
}
|
|
|
|
const sampleManifest = `[
|
|
{"model": "documents.correspondent", "pk": 1, "fields": {"name": "Stadtwerke Musterstadt"}},
|
|
{"model": "documents.documenttype", "pk": 2, "fields": {"name": "Rechnung"}},
|
|
{"model": "documents.tag", "pk": 3, "fields": {"name": "wichtig"}},
|
|
{"model": "documents.document", "pk": 42, "fields": {
|
|
"title": "Stromrechnung September",
|
|
"correspondent": 1,
|
|
"document_type": 2,
|
|
"tags": [3],
|
|
"created": "2026-09-01T10:00:00Z",
|
|
"content": "Betrag: 84,20 EUR"
|
|
}}
|
|
]`
|
|
|
|
// AC1: a real third-party export can be read.
|
|
func TestParsePaperlessExport_ValidFixture(t *testing.T) {
|
|
z := buildFixtureZip(t, sampleManifest, "42_stromrechnung.pdf", []byte("%PDF-1.4 fake"))
|
|
docs, err := ParsePaperlessExport(z)
|
|
if err != nil {
|
|
t.Fatalf("ParsePaperlessExport: %v", err)
|
|
}
|
|
if len(docs) != 1 {
|
|
t.Fatalf("expected 1 document, got %d", len(docs))
|
|
}
|
|
d := docs[0]
|
|
if d.PK != "42" {
|
|
t.Errorf("PK = %q, want 42", d.PK)
|
|
}
|
|
if d.Title != "Stromrechnung September" {
|
|
t.Errorf("Title = %q", d.Title)
|
|
}
|
|
if d.RawFields["correspondent"] != "Stadtwerke Musterstadt" {
|
|
t.Errorf("correspondent resolved = %q", d.RawFields["correspondent"])
|
|
}
|
|
if d.RawFields["document_type"] != "Rechnung" {
|
|
t.Errorf("document_type resolved = %q", d.RawFields["document_type"])
|
|
}
|
|
if d.RawFields["tags"] != "wichtig" {
|
|
t.Errorf("tags resolved = %q", d.RawFields["tags"])
|
|
}
|
|
if string(d.Content) != "%PDF-1.4 fake" {
|
|
t.Errorf("content bytes not read correctly")
|
|
}
|
|
if d.ContentType != "application/pdf" {
|
|
t.Errorf("content type = %q, want application/pdf", d.ContentType)
|
|
}
|
|
}
|
|
|
|
func TestParsePaperlessExport_MissingManifest(t *testing.T) {
|
|
var buf bytes.Buffer
|
|
zw := zip.NewWriter(&buf)
|
|
_ = zw.Close()
|
|
if _, err := ParsePaperlessExport(buf.Bytes()); err == nil {
|
|
t.Fatal("expected error for archive without manifest.json")
|
|
}
|
|
}
|
|
|
|
func TestParsePaperlessExport_NotAZip(t *testing.T) {
|
|
if _, err := ParsePaperlessExport([]byte("not a zip")); err == nil {
|
|
t.Fatal("expected error for non-zip input")
|
|
}
|
|
}
|
|
|
|
func TestParsePaperlessExport_MissingOriginalFile(t *testing.T) {
|
|
z := buildFixtureZip(t, sampleManifest, "", nil)
|
|
if _, err := ParsePaperlessExport(z); err == nil {
|
|
t.Fatal("expected error when the original document file is missing")
|
|
}
|
|
}
|
|
|
|
func TestDetectFields_UnionAcrossDocuments(t *testing.T) {
|
|
z := buildFixtureZip(t, sampleManifest, "42_stromrechnung.pdf", []byte("x"))
|
|
docs, err := ParsePaperlessExport(z)
|
|
if err != nil {
|
|
t.Fatalf("ParsePaperlessExport: %v", err)
|
|
}
|
|
fields := DetectFields(docs)
|
|
want := map[string]bool{"title": true, "created": true, "content": true, "correspondent": true, "document_type": true, "tags": true}
|
|
got := map[string]bool{}
|
|
for _, f := range fields {
|
|
got[f] = true
|
|
}
|
|
for f := range want {
|
|
if !got[f] {
|
|
t.Errorf("DetectFields missing %q, got %v", f, fields)
|
|
}
|
|
}
|
|
}
|