first commit

This commit is contained in:
libroot 2026-11-19 04:40:59 +02:00
commit 8c4dcae475
Signed by: libroot
GPG key ID: 2AC68C029EBE9ACE
89 changed files with 24623 additions and 0 deletions

View file

@ -0,0 +1,49 @@
package main
import (
"encoding/json"
"fmt"
"strings"
"testing"
)
// A reporting-only partner keeps its entry, but is not a source of the file:
// publisher: must not match it and the source category must not list it.
func TestReportingOnlyIsNotASource(t *testing.T) {
var d Document
if err := json.Unmarshal([]byte(`{"publication": [
{"publisher": "The Intercept", "title": "Norway Used NSA Technology",
"date_published": "2018-03-01", "reporters": ["Gallagher, Ryan"]},
{"publisher": "NRK", "title": "Antennene som samler inn data",
"date_published": "2018-03-01", "reporters": ["Hopland, Standahl"],
"reporting_only": true}
]}`), &d); err != nil {
t.Fatal(err)
}
if got := fmt.Sprint(facetValues(&d, "PU")); got != "[The Intercept]" {
t.Errorf("publisher values %s, want only [The Intercept]", got)
}
// The /browse/publisher/{outlet} index is built from the same values, so
// the page and the facet agree: the publisher is a source, the partner
// that only reported the story is not. The index is package state, so
// put the corpus back for whatever runs next.
prev := corpus().archive.Docs
t.Cleanup(func() { corpus().archive.Docs = prev; corpus().buildCategoryDocs() })
corpus().archive.Docs = []Document{d}
corpus().buildCategoryDocs()
if got := len(corpus().categoryMatches("publisher", "The Intercept")); got != 1 {
t.Errorf("the publishing outlet's page lists %d documents, want 1", got)
}
if got := len(corpus().categoryMatches("publisher", "NRK")); got != 0 {
t.Errorf("the reporting-only partner's page lists %d documents, want 0", got)
}
// The entry itself, its byline and its article survive.
if len(d.Publication) != 2 || d.Publication[1].Publisher != "NRK" ||
len(d.Publication[1].Journalists) != 1 {
t.Errorf("the reporting-only entry lost data: %+v", d.Publication)
}
if !strings.Contains(fmt.Sprint(d.JournalistsDeduped()), "Hopland") {
t.Error("a partner's reporters should still be credited")
}
}