Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions internal/repository/readings/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ func TestLeyningCachesEveryDayInTheSpan(t *testing.T) {
}
}

// The "ah"/"sh" transliteration spellings are not @hebcal/locales names --
// readings-svc 400s on them -- so Learning sends their base locale ("a"/"s")
// instead; every other lg passes through unchanged.
func TestLearningMapsTransliterationLocales(t *testing.T) {
tests := []struct{ lg, want string }{
{"ah", "a"},
{"sh", "s"},
{"he", "he"},
{"", ""},
}
for _, tt := range tests {
var got string
c := readingstest.Serve(t, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
got = r.URL.Query().Get("lg")
json.NewEncoder(w).Encode(map[string]any{"items": []any{}})
}))
day := time.Date(2026, 9, 1, 0, 0, 0, 0, time.UTC)
if _, err := c.Learning(t.Context(), []string{"dsm"}, tt.lg, day, day); err != nil {
t.Fatalf("lg=%q: %v", tt.lg, err)
}
if got != tt.want {
t.Errorf("lg=%q sent lg=%q to sidecar, want %q", tt.lg, got, tt.want)
}
}
}

// A hung sidecar must not hang the /shabbat response. Leyning bounds every
// request at 3 seconds of its own, and honours an earlier caller deadline,
// which is what this checks.
Expand Down
18 changes: 17 additions & 1 deletion internal/repository/readings/learning.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,27 @@ func (c *Client) Learning(ctx context.Context, codes []string, lg string, start,
q := url.Values{}
q.Set("start", start.Format("2006-01-02"))
q.Set("end", end.Format("2006-01-02"))
if lg != "" {
if lg := learningLocale(lg); lg != "" {
q.Set("lg", lg)
}
for _, code := range codes {
q.Set(code, "on")
}
return c.get(ctx, "/learning", q)
}

// learningLocale maps a download URL's lg to one @hebcal/locales knows, since
// readings-svc 400s on any it cannot import. The "ah"/"sh" transliteration
// variants are hebcal-web's own "show the Hebrew name too" spellings, not real
// locale names -- their base locales are "a" and "s" -- and the appended Hebrew
// is drawn here in the renderer, not by the sidecar. Every other lg is passed
// through: readings-svc rejecting an unknown one is preferable to hiding it.
func learningLocale(lg string) string {
switch lg {
case "ah":
return "a"
case "sh":
return "s"
}
return lg
}
Loading