aboutsummaryrefslogtreecommitdiff
path: root/internal/readings/readings_test.go
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:28:38 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-07-23 13:28:38 +0200
commit0351f4f188207d0204e1e0124d32127e820e33d5 (patch)
tree526ae229dd7a56987cf6f262afbf2d5f0ad53293 /internal/readings/readings_test.go
parentf8772261f0c4feca68eee0300b5d726fd168a534 (diff)
downloadlectio-0351f4f188207d0204e1e0124d32127e820e33d5.tar.gz
lectio-0351f4f188207d0204e1e0124d32127e820e33d5.zip
readings: lectionary router + part filtering
Diffstat (limited to 'internal/readings/readings_test.go')
-rw-r--r--internal/readings/readings_test.go97
1 files changed, 97 insertions, 0 deletions
diff --git a/internal/readings/readings_test.go b/internal/readings/readings_test.go
new file mode 100644
index 0000000..fd355ff
--- /dev/null
+++ b/internal/readings/readings_test.go
@@ -0,0 +1,97 @@
+package readings
+
+import (
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "strings"
+ "testing"
+
+ "github.com/lukaszkasprzak/lectio/internal/config"
+ "github.com/lukaszkasprzak/lectio/internal/liturgy"
+)
+
+func sectionsForFilterTests() []liturgy.Section {
+ return []liturgy.Section{
+ {PartID: "pierwsze_czytanie", Heading: "1. czytanie"},
+ {PartID: "psalm", Heading: "Psalm"},
+ {PartID: "ewangelia", Heading: "Ewangelia"},
+ }
+}
+
+func TestFilterPartsGospelOnly(t *testing.T) {
+ secs := sectionsForFilterTests()
+ got := filterParts(secs, config.Config{}, false)
+
+ if len(got) != 1 {
+ t.Fatalf("got %d sections, want 1: %+v", len(got), got)
+ }
+ if got[0].PartID != "ewangelia" {
+ t.Errorf("got PartID %q, want ewangelia", got[0].PartID)
+ }
+}
+
+func TestFilterPartsAll(t *testing.T) {
+ secs := sectionsForFilterTests()
+ cfg := config.Config{
+ Lectionary: "new",
+ Parts: map[string]map[string]bool{
+ "new": {"psalm": false},
+ },
+ }
+ got := filterParts(secs, cfg, true)
+
+ if len(got) != 2 {
+ t.Fatalf("got %d sections, want 2: %+v", len(got), got)
+ }
+ for _, s := range got {
+ if s.PartID == "psalm" {
+ t.Errorf("psalm should have been filtered out: %+v", got)
+ }
+ }
+ ids := map[string]bool{got[0].PartID: true, got[1].PartID: true}
+ if !ids["pierwsze_czytanie"] || !ids["ewangelia"] {
+ t.Errorf("got %+v, want pierwsze_czytanie and ewangelia", got)
+ }
+}
+
+func TestLoadModernRoutes(t *testing.T) {
+ html, err := os.ReadFile("../liturgy/testdata/2026-07-22.html")
+ if err != nil {
+ t.Fatal(err)
+ }
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Write(html)
+ }))
+ defer srv.Close()
+ liturgy.SetBaseURL(srv.URL + "/liturgia/%s/Ewangelia")
+ t.Setenv("XDG_CACHE_HOME", t.TempDir())
+
+ cfg := config.Config{Lectionary: "new"}
+ secs, err := Load(cfg, Options{Date: "2026-07-22", All: true})
+ if err != nil {
+ t.Fatalf("Load: %v", err)
+ }
+
+ found := false
+ for _, s := range secs {
+ if s.PartID == "ewangelia" {
+ found = true
+ }
+ }
+ if !found {
+ t.Errorf("no gospel section (PartID=ewangelia) found in %+v", secs)
+ }
+}
+
+func TestLoadTraditionalOfflineErrors(t *testing.T) {
+ cfg := config.Config{Lectionary: "traditional", TraditionalLang: "pl"}
+ _, err := Load(cfg, Options{Date: "2026-07-22", Offline: true})
+ if err == nil {
+ t.Fatal("expected error, got nil")
+ }
+ msg := strings.ToLower(err.Error())
+ if !strings.Contains(msg, "offline") || !strings.Contains(msg, "traditional") {
+ t.Errorf("error %q should mention offline and traditional", err.Error())
+ }
+}