Files
memby/server/internal/config/remote_config_test.go
2026-08-22 18:40:50 +12:00

74 lines
2.4 KiB
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package config
import (
"encoding/json"
"testing"
)
func TestRemoteConfigDefaultsAreComplete(t *testing.T) {
document, err := loadRemoteConfig("")
if err != nil {
t.Fatal(err)
}
if document.SchemaVersion != 1 || document.ConfigVersion != 1 {
t.Fatalf("unexpected versions: %+v", document)
}
if document.Copy.Navigation.Favourites != "Favourites" {
t.Fatalf("favourites label = %q", document.Copy.Navigation.Favourites)
}
if !document.ContinueWatching.IncludeNextUp || len(document.Home.Sections) == 0 {
t.Fatalf("central defaults are incomplete: %+v", document)
}
if document.Presentation.FontFamily != "system" {
t.Fatalf("font family = %q, want system", document.Presentation.FontFamily)
}
}
func TestRemoteConfigDefaultsMissingNewSectionsForOlderDocuments(t *testing.T) {
raw := `{"schemaVersion":1,"configVersion":3,"copy":{"navigation":{"home":"Home","forYou":"For You","search":"Search","movies":"Movies","tvShows":"TV Shows","tvCalendar":"TV Calendar","favourites":"Favourites","user":"User","settings":"Settings"},"tagline":"Matts Android TV client"},"features":{"showNavigationVersion":true},"presentation":{"navigationRailExpandedWidthDp":184,"navigationContentShiftDp":112}}`
document, err := loadRemoteConfig(raw)
if err != nil {
t.Fatal(err)
}
if !document.ContinueWatching.Enabled || document.Search.MaxResults != 50 {
t.Fatalf("new fields did not receive defaults: %+v", document)
}
}
func TestRemoteConfigRejectsMalformedAndUnsafeDocuments(t *testing.T) {
document := DefaultRemoteConfig()
document.Presentation.NavigationRailExpandedWidthDp = 500
raw, err := json.Marshal(document)
if err != nil {
t.Fatal(err)
}
if _, err := loadRemoteConfig(string(raw)); err == nil {
t.Fatal("unsafe presentation value was accepted")
}
if _, err := loadRemoteConfig(`{"schemaVersion":1,"unknown":true}`); err == nil {
t.Fatal("unknown fields were accepted")
}
document = DefaultRemoteConfig()
document.Presentation.FontFamily = "comic-sans"
raw, err = json.Marshal(document)
if err != nil {
t.Fatal(err)
}
if _, err := loadRemoteConfig(string(raw)); err == nil {
t.Fatal("unknown font family was accepted")
}
document = DefaultRemoteConfig()
document.MinimumAppVersion = "0.3.0"
document.MaximumAppVersion = "0.2.54"
raw, err = json.Marshal(document)
if err != nil {
t.Fatal(err)
}
if _, err := loadRemoteConfig(string(raw)); err == nil {
t.Fatal("reversed app-version bounds were accepted")
}
}