summaryrefslogtreecommitdiff
path: root/mobile
diff options
context:
space:
mode:
authorLukasz Kasprzak <lukas@labunix.xyz>2026-08-03 23:56:14 +0200
committerLukasz Kasprzak <lukas@labunix.xyz>2026-08-03 23:56:14 +0200
commit13d5e99ab90ab872c8cc072a0246348f0d24fa9a (patch)
treec70a355d0ad4c6fd4dc5007c42b223b854544d69 /mobile
parente3d551ebb8f6ac2bf1a7027991a4222e83309a39 (diff)
downloadlectio-13d5e99ab90ab872c8cc072a0246348f0d24fa9a.tar.gz
lectio-13d5e99ab90ab872c8cc072a0246348f0d24fa9a.zip
mobile: return the day's rank and its localised label
Diffstat (limited to 'mobile')
-rw-r--r--mobile/mobile.go23
-rw-r--r--mobile/mobile_test.go42
2 files changed, 56 insertions, 9 deletions
diff --git a/mobile/mobile.go b/mobile/mobile.go
index c2c6347..6312ee0 100644
--- a/mobile/mobile.go
+++ b/mobile/mobile.go
@@ -16,6 +16,7 @@ import (
"strings"
"github.com/lukaszkasprzak/lectio/internal/config"
+ "github.com/lukaszkasprzak/lectio/internal/i18n"
"github.com/lukaszkasprzak/lectio/internal/readings"
"github.com/lukaszkasprzak/lectio/internal/render"
)
@@ -31,15 +32,17 @@ type reading struct {
// dayDoc is the JSON returned by Day.
type dayDoc struct {
- Date string `json:"date"`
- Form string `json:"form"`
- Lang string `json:"lang"`
- Version string `json:"version"`
- Name string `json:"name"`
- Season string `json:"season"`
- Colour string `json:"colour"`
- Readings []reading `json:"readings"`
- Error string `json:"error,omitempty"`
+ Date string `json:"date"`
+ Form string `json:"form"`
+ Lang string `json:"lang"`
+ Version string `json:"version"`
+ Name string `json:"name"`
+ Season string `json:"season"`
+ Colour string `json:"colour"`
+ Rank string `json:"rank"`
+ RankLabel string `json:"rank_label"`
+ Readings []reading `json:"readings"`
+ Error string `json:"error,omitempty"`
}
// lectByForm maps the app's form code to lectio's lectionary value.
@@ -69,6 +72,8 @@ func Day(date, form, version, lang string) string {
out.Name = info.Name
out.Season = info.Season
out.Colour = info.Colour
+ out.Rank = info.Rank
+ out.RankLabel = i18n.Get(lang).Rank[info.Rank]
} else {
out.Error = err.Error()
}
diff --git a/mobile/mobile_test.go b/mobile/mobile_test.go
new file mode 100644
index 0000000..c7df63c
--- /dev/null
+++ b/mobile/mobile_test.go
@@ -0,0 +1,42 @@
+package mobile
+
+import (
+ "encoding/json"
+ "testing"
+)
+
+func decodeDay(t *testing.T, s string) map[string]any {
+ t.Helper()
+ var m map[string]any
+ if err := json.Unmarshal([]byte(s), &m); err != nil {
+ t.Fatalf("Day returned invalid JSON: %v\n%s", err, s)
+ }
+ return m
+}
+
+func TestDayCarriesLocalisedRank(t *testing.T) {
+ pl := decodeDay(t, Day("2026-08-01", "of", "vul", "pl"))
+ if pl["rank"] != "memorial" {
+ t.Errorf("pl rank = %v, want memorial", pl["rank"])
+ }
+ if pl["rank_label"] != "wspomnienie obowiązkowe" {
+ t.Errorf("pl rank_label = %v", pl["rank_label"])
+ }
+ en := decodeDay(t, Day("2026-08-01", "of", "vul", "en"))
+ if en["rank_label"] != "memorial" {
+ t.Errorf("en rank_label = %v", en["rank_label"])
+ }
+}
+
+// The app shows the colour as a swatch and never as a word, so the raw key must
+// be present and no localised label may be. This test exists so the app cannot
+// quietly start depending on a colour word.
+func TestDayHasColourKeyButNoColourLabel(t *testing.T) {
+ m := decodeDay(t, Day("2026-08-01", "of", "vul", "pl"))
+ if m["colour"] != "white" {
+ t.Errorf("colour = %v, want white", m["colour"])
+ }
+ if _, present := m["colour_label"]; present {
+ t.Error("colour_label must not be returned: the app draws a swatch")
+ }
+}