package main import ( "strings" "testing" ) // A document counts for an outlet in the years of THAT outlet's entries: The // Guardian's 2013 publication must not put The Intercept's 2014 copy in // The Intercept's 2013 column, and the cell links a page listing exactly the // documents it counts. func TestOutletYearsArePerPublisher(t *testing.T) { root := assemblyCorpus(t, "") writeAssemblyDoc(t, root, "shared", map[string]interface{}{ "title": "Shared", "publication": []map[string]interface{}{ {"publisher": "The Guardian", "date_published": "2013-06-06"}, {"publisher": "The Intercept", "date_published": "2014-02-10"}, {"publisher": "Partner", "date_published": "2012-01-01", "reporting_only": true}, }, }, []string{"page-1.jpg"}, nil) withCorpus(t, root) cells := map[string]outletCell{} table := corpus().outletTables[""] for _, row := range table.Rows { for i, y := range table.Years { cells[row.Name+" "+y] = row.Cells[i] } } for k, want := range map[string]int{ "The Guardian 2013": 1, "The Guardian 2014": 0, "The Intercept 2013": 0, "The Intercept 2014": 1, } { if got := cells[k].Docs; got != want { t.Errorf("%s: %d documents, want %d", k, got, want) } } for _, y := range table.Years { if y == "2012" { t.Errorf("a reporting-only entry made a 2012 column") } } link := cells["The Intercept 2014"].URL if link != "/browse/publisher/The%20Intercept?year=2014&coll=news&coll=sidtoday-archive&coll=foia" { t.Errorf("cell link %q", link) } if got := resultTotal(t, link); got != 1 { t.Errorf("%s lists %d documents, want 1", link, got) } if body := get(t, "/browse/publisher/The%20Intercept?year=2013").Body.String(); !strings.Contains(body, "0 documents") { t.Errorf("The Intercept's 2013 page is not empty") } }